Skip to content

[8.18] (backport #9604) Fix/8544 mac linux unprivileged reenroll#9767

Merged
kaanyalti merged 4 commits into
8.18from
mergify/bp/8.18/pr-9604
Sep 10, 2025
Merged

[8.18] (backport #9604) Fix/8544 mac linux unprivileged reenroll#9767
kaanyalti merged 4 commits into
8.18from
mergify/bp/8.18/pr-9604

Conversation

@mergify
Copy link
Copy Markdown
Contributor

@mergify mergify Bot commented Sep 5, 2025

  • Bug

What does this PR do?

Updates the enroll command so that the file permissions are fixed when a privileged user executes enroll. Implemented only for mac/linux. Permission fix is executed every time root executes enroll and enroll is not triggered by install. Windows implementation will be in a follow up pr. Split the PRs as windows implementation may end up being more involved.

Why is it important?

Currently a root user needs to run sudo -u elastic-agent-user elastic-agent enroll ... in order to re-enroll an unprivileged agent.

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 change 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

None

How to test this PR locally

  • Build the agent
  • Install and enroll with --unprivileged flag
  • Execute enroll as root
  • Verify that agent is still healthy

Related issues


This is an automatic backport of pull request #9604 done by [Mergify](https://mergify.com).

* fix(8544): remove unused files

* fix(8544): remove file ownership check in enroll command

* fix(8544): added getOwnerFromPath for mac and linux and added relevant tests

fix(8544): added empty owner check in enroll unix tests

* fix(8544): added fileownership and permission fix in enroll command

fix(8544): refactored fix permission computation, and added tests

* fix(8544): added noop getOwnerFromPath for windows

* fix(8544): updated re-enroll test

* fix(8544): added changelog fragment

* fix(8544): ran mage check

fix(8544): ran mage check

* fix(8544): refactored computeFixPermissions and updated relevant test cases

* fix(8544): refactor computeFixPermissions if block

(cherry picked from commit 08444d4)

# Conflicts:
#	internal/pkg/agent/cmd/enroll.go
@mergify mergify Bot added backport conflicts There is a conflict in the backported pull request labels Sep 5, 2025
@mergify mergify Bot requested a review from a team as a code owner September 5, 2025 12:09
@mergify mergify Bot requested review from blakerouse and pkoutsovasilis and removed request for a team September 5, 2025 12:09
@mergify
Copy link
Copy Markdown
Contributor Author

mergify Bot commented Sep 5, 2025

Cherry-pick of 08444d4 has failed:

On branch mergify/bp/8.18/pr-9604
Your branch is up to date with 'origin/8.18'.

You are currently cherry-picking commit 08444d400.
  (fix conflicts and run "git cherry-pick --continue")
  (use "git cherry-pick --skip" to skip this patch)
  (use "git cherry-pick --abort" to cancel the cherry-pick operation)

Changes to be committed:
	new file:   changelog/fragments/1756313785-enable-root-user-to-re-enroll-unprivileged-agent-for-mac-and-linux.yaml
	deleted:    internal/pkg/agent/cmd/enroll_match_fileowner_unix.go
	deleted:    internal/pkg/agent/cmd/enroll_match_fileowner_unix_test.go
	deleted:    internal/pkg/agent/cmd/enroll_match_fileowner_windows.go
	deleted:    internal/pkg/agent/cmd/enroll_match_fileowner_windows_test.go
	new file:   internal/pkg/agent/cmd/enroll_test.go
	modified:   internal/pkg/agent/cmd/enroll_unix.go
	new file:   internal/pkg/agent/cmd/enroll_unix_test.go
	modified:   internal/pkg/agent/cmd/enroll_windows.go
	modified:   testing/integration/ess/re-enroll_test.go

Unmerged paths:
  (use "git add <file>..." to mark resolution)
	both modified:   internal/pkg/agent/cmd/enroll.go

To fix up this pull request, you can check it out locally. See documentation: https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/reviewing-changes-in-pull-requests/checking-out-pull-requests-locally

@mergify mergify Bot mentioned this pull request Sep 5, 2025
6 tasks
@github-actions github-actions Bot added the Team:Elastic-Agent-Control-Plane Label for the Agent Control Plane team label Sep 5, 2025
@elasticmachine
Copy link
Copy Markdown
Contributor

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

@kaanyalti kaanyalti removed the conflicts There is a conflict in the backported pull request label Sep 5, 2025
@mergify
Copy link
Copy Markdown
Contributor Author

mergify Bot commented Sep 8, 2025

This pull request has not been merged yet. Could you please review and merge it @kaanyalti? 🙏

kaanyalti
kaanyalti previously approved these changes Sep 8, 2025
@kaanyalti kaanyalti dismissed their stale review September 8, 2025 19:24

ci is not green

@elastic-sonarqube
Copy link
Copy Markdown

@elasticmachine
Copy link
Copy Markdown
Contributor

💚 Build Succeeded

History

cc @kaanyalti

@kaanyalti kaanyalti merged commit 53dab29 into 8.18 Sep 10, 2025
18 checks passed
@kaanyalti kaanyalti deleted the mergify/bp/8.18/pr-9604 branch September 10, 2025 15:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backport 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.

3 participants