Skip to content

Handle PRIVILEGE_LEVEL_CHANGE action#10231

Merged
michalpristas merged 38 commits intoelastic:mainfrom
michalpristas:feat/switch-action
Nov 5, 2025
Merged

Handle PRIVILEGE_LEVEL_CHANGE action#10231
michalpristas merged 38 commits intoelastic:mainfrom
michalpristas:feat/switch-action

Conversation

@michalpristas
Copy link
Copy Markdown
Contributor

@michalpristas michalpristas commented Oct 1, 2025

to test this you need a 9.2 kibana with FF config:

xpack.fleet.enableExperimental: ["enableAgentPrivilegeLevelChange"]

This PR adds a handler for PRIVILEGE_LEVEL_CHANGE action.
Once action comes and permissions are fixed we call the code identical to privilege or unprivilege CLI commands.

Service manager handles user changes differently Windows being least problematic.
Systemd could do daemon-reload but for consistency MacOS and Linux are handled in a same way:

  • change to service file is made
  • agent is rebooted
  • desired user is detecting by reading a service definition file
  • permissions are fixed if needed
  • if it is non-root, setgid,setuid calls are made to drop privileges
  • we continue running.
    This is not performed if we are running using proper user

Test steps:

  • run kibana instance local or cloud >=9.2-SNAPSHOT
  • set config value xpack.fleet.enableExperimental: ["enableAgentPrivilegeLevelChange"]
  • enroll agent to fleet, make sure you don't have system integration enabled (system requires root)
  • dev tools: POST kbn:api/fleet/agents/{agent_id}/privilege_level_change
  • check file system permissions are correct
  • check process is using proper user/group
  • check service file is updated
  • restart machine recheck everything

Fixes: #4973

@michalpristas michalpristas self-assigned this Oct 1, 2025
@michalpristas michalpristas requested a review from a team as a code owner October 1, 2025 11:37
@michalpristas michalpristas added enhancement New feature or request Team:Elastic-Agent-Control-Plane Label for the Agent Control Plane team backport-skip labels Oct 1, 2025
@elasticmachine
Copy link
Copy Markdown
Contributor

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

Comment thread internal/pkg/agent/cmd/run.go Outdated
Comment thread internal/pkg/agent/cmd/run_darwin.go Outdated
Comment thread internal/pkg/agent/cmd/run_darwin.go Outdated
Comment thread internal/pkg/agent/cmd/run_darwin.go
Comment thread internal/pkg/agent/install/componentvalidation/validation.go
Comment thread internal/pkg/agent/install/svc.go
Comment thread internal/pkg/agent/install/switch.go
michalpristas and others added 3 commits October 2, 2025 10:51
…privilege_level_change.go

Co-authored-by: Paolo Chilà <paolo.chila@elastic.co>
Co-authored-by: Paolo Chilà <paolo.chila@elastic.co>
Copy link
Copy Markdown
Contributor

@ycombinator ycombinator left a comment

Choose a reason for hiding this comment

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

@michalpristas Would it be possible to add some integration/E2E tests in this PR? Failing that, could you add some manual testing steps to the PR description? Thanks.

@michalpristas
Copy link
Copy Markdown
Contributor Author

added testing steps to description

Comment thread internal/pkg/agent/cmd/run.go
michalpristas and others added 11 commits October 6, 2025 09:49
Co-authored-by: Shaunak Kashyap <ycombinator@gmail.com>
Co-authored-by: Shaunak Kashyap <ycombinator@gmail.com>
…nge.yaml

Co-authored-by: Shaunak Kashyap <ycombinator@gmail.com>
…privilege_level_change.go

Co-authored-by: Shaunak Kashyap <ycombinator@gmail.com>
…privilege_level_change.go

Co-authored-by: Shaunak Kashyap <ycombinator@gmail.com>
Comment thread internal/pkg/agent/cmd/run.go
Comment thread internal/pkg/agent/cmd/run.go Outdated
Comment thread internal/pkg/agent/cmd/run.go
Comment thread internal/pkg/agent/cmd/run_darwin.go
Comment thread internal/pkg/agent/cmd/run_linux.go Outdated
Comment thread internal/pkg/agent/cmd/run_windows.go Outdated
@mergify
Copy link
Copy Markdown
Contributor

mergify bot commented Oct 7, 2025

This pull request is now in conflicts. Could you fix it? 🙏
To fixup this pull request, you can check out it locally. See documentation: https://help.github.com/articles/checking-out-pull-requests-locally/

git fetch upstream
git checkout -b feat/switch-action upstream/feat/switch-action
git merge upstream/main
git push upstream feat/switch-action

@mergify
Copy link
Copy Markdown
Contributor

mergify bot commented Oct 24, 2025

This pull request is now in conflicts. Could you fix it? 🙏
To fixup this pull request, you can check out it locally. See documentation: https://help.github.com/articles/checking-out-pull-requests-locally/

git fetch upstream
git checkout -b feat/switch-action upstream/feat/switch-action
git merge upstream/main
git push upstream feat/switch-action

@mergify
Copy link
Copy Markdown
Contributor

mergify bot commented Oct 30, 2025

This pull request is now in conflicts. Could you fix it? 🙏
To fixup this pull request, you can check out it locally. See documentation: https://help.github.com/articles/checking-out-pull-requests-locally/

git fetch upstream
git checkout -b feat/switch-action upstream/feat/switch-action
git merge upstream/main
git push upstream feat/switch-action

@elasticmachine
Copy link
Copy Markdown
Contributor

💛 Build succeeded, but was flaky

Failed CI Steps

History

cc @michalpristas

Copy link
Copy Markdown
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.

This looks good, thanks for working on it and iterating to get it into a good state.

@michalpristas michalpristas merged commit ac2e9f8 into elastic:main Nov 5, 2025
21 checks passed
hayotbisonai pushed a commit to hayotbisonai/elastic-agent that referenced this pull request Nov 23, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backport-skip enhancement New feature or request 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.

Handle new action for switching Agent from privileged to unprivileged mode

5 participants