Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[bug] handle syscall errno in windows permissions #7059

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

pkoutsovasilis
Copy link
Contributor

@pkoutsovasilis pkoutsovasilis commented Feb 27, 2025

What does this PR do?

This PR attempts to fix an issue in Windows permission handling where FixPermissions could return an "Error" message stating "The operation completed successfully." The root cause most probably is the lack of explicit handling for syscall.Errno(0), which indicates success but was mistakenly treated as an error. Also it fixes another issue where we weren't taking ownership of the files when we run into the syscall.Errno(0) from the acl.Apply

Why is it important?

Properly handling syscall.Errno(0) prevents unnecessary error propagation and aligns the implementation with Windows system call behavior.

Checklist

  • I have read and understood the pull request guidelines of this project.
  • My code follows the style guidelines of this project.
  • I have commented my code, particularly in hard-to-understand areas.
  • I have made corresponding changes to the documentation.
  • I have made corresponding changes to the default configuration files.
  • I have added tests that prove my fix is effective or that my feature works.
  • I have added an entry in ./changelog/fragments using the changelog tool.
  • I have added an integration test or an E2E test.

Disruptive User Impact

This fix is not expected to cause any disruptions.

How to test this PR locally

N/A

Related issues

@pkoutsovasilis pkoutsovasilis added Team:Elastic-Agent-Control-Plane Label for the Agent Control Plane team backport-active-all Automated backport with mergify to all the active branches labels Feb 27, 2025
@pkoutsovasilis pkoutsovasilis self-assigned this Feb 27, 2025
// Check for Errno = 0 which indicates success
// https://pkg.go.dev/golang.org/x/sys/windows#Errno
if errors.Is(err, syscall.Errno(0)) {
return nil
Copy link
Contributor Author

@pkoutsovasilis pkoutsovasilis Feb 27, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

see here, previously if this was syscall.Errno(0), we were returning which IMO shouldn't be the case, and we should continue below trying to take onwership

@pkoutsovasilis
Copy link
Contributor Author

buildkite test this

@pkoutsovasilis pkoutsovasilis added the bug Something isn't working label Feb 27, 2025
@pkoutsovasilis pkoutsovasilis force-pushed the fix/windows_permissions branch from 55990e1 to 44ac8e9 Compare February 27, 2025 21:33
@pkoutsovasilis pkoutsovasilis marked this pull request as ready for review February 27, 2025 23:00
@pkoutsovasilis pkoutsovasilis requested a review from a team as a code owner February 27, 2025 23:00
@elasticmachine
Copy link
Contributor

Pinging @elastic/elastic-agent-control-plane (Team:Elastic-Agent-Control-Plane)

Copy link
Contributor

@blakerouse blakerouse left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Other than the naming suggestion this looks good.

@@ -21,6 +21,15 @@ import (
"github.com/elastic/elastic-agent/pkg/utils"
)

func errHandler(err error) error {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A clearer name would be better here. Being names errHandler doesn't really provide context to what it is doing, when reading the code where it is called from. Something like filterSuccessErr would be more appropriate.

Suggested change
func errHandler(err error) error {
func filterSuccessErr(err error) error {

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we put this on every windows sycall we make? What is special about acl.Apply here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe that this error code (ERROR_SUCCESS) handling should happen for all functions that call directly the Win32 low level API. Now acl.Apply is actually calling this API here but doesn't check for it. Thus I don't believe we should add this check in every windows syscall 🙂

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thank you @blakerouse I was clearly lacking inspiration when naming this function but I do like your proposal! I just committed it 🙂

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@blakerouse @cmacknz should I consider this conversation as resolved? 🙂

@elasticmachine
Copy link
Contributor

💚 Build Succeeded

History

cc @pkoutsovasilis

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backport-active-all Automated backport with mergify to all the active branches bug Something isn't working Team:Elastic-Agent-Control-Plane Label for the Agent Control Plane team
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[enroll] Windows can return err, even when operation is successful
4 participants