Skip to content

Fix/8544 mac linux unprivileged reenroll#9604

Merged
kaanyalti merged 10 commits into
elastic:mainfrom
kaanyalti:fix/8544_mac_linux_unprivileged_reenroll
Sep 5, 2025
Merged

Fix/8544 mac linux unprivileged reenroll#9604
kaanyalti merged 10 commits into
elastic:mainfrom
kaanyalti:fix/8544_mac_linux_unprivileged_reenroll

Conversation

@kaanyalti
Copy link
Copy Markdown

@kaanyalti kaanyalti commented Aug 27, 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

@mergify
Copy link
Copy Markdown
Contributor

mergify Bot commented Aug 27, 2025

This pull request does not have a backport label. Could you fix it @kaanyalti? 🙏
To fixup this pull request, you need to add the backport labels for the needed
branches, such as:

  • backport-./d./d is the label that automatically backports to the 8./d branch. /d is the digit
  • backport-active-all is the label that automatically backports to all active branches.
  • backport-active-8 is the label that automatically backports to all active minor branches for the 8 major.
  • backport-active-9 is the label that automatically backports to all active minor branches for the 9 major.

@mergify mergify Bot mentioned this pull request Aug 27, 2025
6 tasks
@kaanyalti kaanyalti 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 Aug 27, 2025
Comment thread internal/pkg/agent/cmd/enroll.go Outdated
@kaanyalti kaanyalti force-pushed the fix/8544_mac_linux_unprivileged_reenroll branch 3 times, most recently from cfe42f7 to f612dc5 Compare August 28, 2025 08:44
…t tests

fix(8544): added empty owner check in enroll unix tests
@kaanyalti kaanyalti force-pushed the fix/8544_mac_linux_unprivileged_reenroll branch 3 times, most recently from 127f60e to e27504c Compare August 28, 2025 10:17
Comment thread internal/pkg/agent/cmd/enroll.go Outdated
@kaanyalti kaanyalti force-pushed the fix/8544_mac_linux_unprivileged_reenroll branch 2 times, most recently from 8cc7a4d to e15b90e Compare August 28, 2025 20:09
@kaanyalti kaanyalti force-pushed the fix/8544_mac_linux_unprivileged_reenroll branch from e15b90e to 84d2dd7 Compare August 28, 2025 20:56
@kaanyalti kaanyalti marked this pull request as ready for review August 29, 2025 02:08
@kaanyalti kaanyalti requested a review from a team as a code owner August 29, 2025 02:08
@elasticmachine
Copy link
Copy Markdown
Contributor

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

@ebeahan
Copy link
Copy Markdown
Member

ebeahan commented Sep 3, 2025

Buildkite test this

@elastic-sonarqube
Copy link
Copy Markdown

@elasticmachine
Copy link
Copy Markdown
Contributor

💛 Build succeeded, but was flaky

Failed CI Steps

History

cc @kaanyalti

@blakerouse
Copy link
Copy Markdown
Contributor

Code looks good. I am building it now, and will run it before +1.

@michalpristas
Copy link
Copy Markdown
Contributor

as blake seems to be testing it as well please wait for him to get back to you

@blakerouse
Copy link
Copy Markdown
Contributor

I was able to test this on Linux arm64 and it is working as expected. After re-enrollment as root on an unprivileged installation all files written to disk have the correct permissions and the service is running successfully.

@kaanyalti kaanyalti merged commit 08444d4 into elastic:main Sep 5, 2025
19 checks passed
@kaanyalti kaanyalti deleted the fix/8544_mac_linux_unprivileged_reenroll branch September 5, 2025 12:08
@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Sep 5, 2025

@Mergifyio backport 8.18 8.19 9.0 9.1

@mergify
Copy link
Copy Markdown
Contributor

mergify Bot commented Sep 5, 2025

backport 8.18 8.19 9.0 9.1

✅ Backports have been created

Details

mergify Bot pushed a commit that referenced this pull request Sep 5, 2025
* 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 Bot pushed a commit that referenced this pull request Sep 5, 2025
* 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 Bot pushed a commit that referenced this pull request Sep 5, 2025
* 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 Bot pushed a commit that referenced this pull request Sep 5, 2025
* 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 Bot pushed a commit that referenced this pull request Sep 5, 2025
* 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
kaanyalti pushed a commit that referenced this pull request Sep 8, 2025
* Fix/8544 mac linux unprivileged reenroll (#9604)

* 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

* fix(8544): resolve merge conflicts

---------

Co-authored-by: Kaan Yalti <kaan.yalti@elastic.co>
kaanyalti pushed a commit that referenced this pull request Sep 8, 2025
* Fix/8544 mac linux unprivileged reenroll (#9604)

* 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

* fix(8544): resolve merge conflicts

---------

Co-authored-by: Kaan Yalti <kaan.yalti@elastic.co>
kaanyalti pushed a commit that referenced this pull request Sep 8, 2025
* Fix/8544 mac linux unprivileged reenroll (#9604)

* 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

* fix(8544): resolve merge conflicts

---------

Co-authored-by: Kaan Yalti <kaan.yalti@elastic.co>
kaanyalti pushed a commit that referenced this pull request Sep 10, 2025
* Fix/8544 mac linux unprivileged reenroll (#9604)

* 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

* fix(8544): resolve merge conflicts

---------

Co-authored-by: Kaan Yalti <kaan.yalti@elastic.co>
Co-authored-by: Panos Koutsovasilis <panos.koutsovasilis@elastic.co>
intxgo pushed a commit to intxgo/elastic-agent that referenced this pull request Sep 24, 2025
* 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
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 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.

5 participants