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

Set user depending on agent.privileges.root field from manifest #1789

Merged
merged 5 commits into from
Apr 22, 2024

Conversation

mrodm
Copy link
Contributor

@mrodm mrodm commented Apr 18, 2024

Relates #787
Relates #1586

When using independent agents, if the package defines in its manifest that it requries root as:

agent:
  privileges:
    root: true

elastic-package will automatically set the user root in the docker-compose scenario for the agent.

Added this setting into the test package auditid_manager_independent_agent. It can be checked that these settings are set for that agent container along with the capabilities:

 $ docker inspect elastic-package-agent-auditd_manager_independent_agent-auditd-elastic-agent-1 | jq -r '.[] | .HostConfig.PidMode'
host

 $ docker inspect elastic-package-agent-auditd_manager_independent_agent-auditd-elastic-agent-1 | jq -r '.[] | .HostConfig.CapAdd'
[
  "AUDIT_CONTROL",
  "AUDIT_READ"
]

 $ docker inspect elastic-package-agent-auditd_manager_independent_agent-auditd-elastic-agent-1 | jq -r '.[] | .Config.User'
root

@mrodm mrodm self-assigned this Apr 18, 2024
@mrodm mrodm changed the title Honor agent properties root Honor agent privileges root from manifest Apr 18, 2024
@elasticmachine
Copy link
Collaborator

💚 Build Succeeded

History

cc @mrodm

@mrodm mrodm changed the title Honor agent privileges root from manifest Set user depending on agent.privileges.root field from manifest Apr 18, 2024
Comment on lines 342 to 345
// If user is defined in configuration file has preference ?
if info.Agent.User == "" && packageManifest.Agent.Privileges.Root {
info.Agent.User = "root"
}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

As it is, if one configuration defines another user, that user will have preference over what the package manifest sets.

Should it be set always according to what the package manifest sets ignoring the setting from the configuration file?

Copy link
Member

Choose a reason for hiding this comment

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

Yes, configuration file should have preference. There may be a test that tries with a non-root user with additional capabilities.

@@ -1,15 +1,17 @@
format_version: 1.0.0
format_version: 2.12.0
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Minimum version to define agent.privileges.root in the manifest

@mrodm mrodm marked this pull request as ready for review April 18, 2024 16:35
@mrodm mrodm requested a review from a team April 18, 2024 16:42
Copy link
Member

@jsoriano jsoriano left a comment

Choose a reason for hiding this comment

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

Not tested. Code LGTM.

Comment on lines 342 to 345
// If user is defined in configuration file has preference ?
if info.Agent.User == "" && packageManifest.Agent.Privileges.Root {
info.Agent.User = "root"
}
Copy link
Member

Choose a reason for hiding this comment

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

Yes, configuration file should have preference. There may be a test that tries with a non-root user with additional capabilities.

@@ -819,7 +824,7 @@ func (r *runner) prepareScenario(ctx context.Context, config *testConfig, svcInf
return nil
}

agentDeployed, agentInfo, err := r.setupAgent(ctx, config, serviceStateData, policy)
agentDeployed, agentInfo, err := r.setupAgent(ctx, config, serviceStateData, policy, scenario.pkgManifest)
Copy link
Member

Choose a reason for hiding this comment

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

Nit. Maybe we can reduce the new dependecy here by passing only the agent options.

Suggested change
agentDeployed, agentInfo, err := r.setupAgent(ctx, config, serviceStateData, policy, scenario.pkgManifest)
agentDeployed, agentInfo, err := r.setupAgent(ctx, config, serviceStateData, policy, scenario.pkgManifest.Agent)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sure, done this change in 1d65244

@@ -5,7 +5,6 @@ data_stream:
preserve_original_event: true
agent:
runtime: docker
user: "root"
Copy link
Member

Choose a reason for hiding this comment

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

It would work the same if we keep the user here, right?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, that's right. I've tested it again locally keeping the user in the configuration file and it keeps the same behavior (sets root user).

@mrodm mrodm merged commit c2ff98b into elastic:main Apr 22, 2024
3 checks passed
@mrodm mrodm deleted the honor_agent_properties_root branch April 22, 2024 10:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants