Skip to content

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

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

Merged
merged 5 commits into from
Apr 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions internal/packages/packages.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,12 @@ type Owner struct {
Type string `config:"type" json:"type" yaml:"type"`
}

type Agent struct {
Privileges struct {
Root bool `config:"root" json:"root" yaml:"root"`
} `config:"privileges" json:"privileges" yaml:"privileges"`
}

// PackageManifest represents the basic structure of a package's manifest
type PackageManifest struct {
SpecVersion string `config:"format_version" json:"format_version" yaml:"format_version"`
Expand All @@ -130,6 +136,7 @@ type PackageManifest struct {
Description string `config:"description" json:"description" yaml:"description"`
License string `config:"license" json:"license" yaml:"license"`
Categories []string `config:"categories" json:"categories" yaml:"categories"`
Agent Agent `config:"agent" json:"agent" yaml:"agent"`
}

type Elasticsearch struct {
Expand Down
14 changes: 10 additions & 4 deletions internal/testrunner/runners/system/runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -313,7 +313,7 @@ func (r *runner) createServiceOptions(variantName string) servicedeployer.Factor
}
}

func (r *runner) createAgentInfo(policy *kibana.Policy, config *testConfig) (agentdeployer.AgentInfo, error) {
func (r *runner) createAgentInfo(policy *kibana.Policy, config *testConfig, agentManifest packages.Agent) (agentdeployer.AgentInfo, error) {
var info agentdeployer.AgentInfo

info.Name = r.options.TestFolder.Package
Expand All @@ -339,6 +339,12 @@ func (r *runner) createAgentInfo(policy *kibana.Policy, config *testConfig) (age
info.Agent.Runtime = config.Agent.Runtime
info.Agent.PidMode = config.Agent.PidMode

// If user is defined in the configuration file, it has preference
// and it should not be overwritten by the value in the manifest
if info.Agent.User == "" && agentManifest.Privileges.Root {
info.Agent.User = "root"
}

return info, nil
}

Expand Down Expand Up @@ -819,7 +825,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.Agent)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -1127,12 +1133,12 @@ func (r *runner) setupService(ctx context.Context, config *testConfig, serviceOp
return service, service.Info(), nil
}

func (r *runner) setupAgent(ctx context.Context, config *testConfig, state ServiceState, policy *kibana.Policy) (agentdeployer.DeployedAgent, agentdeployer.AgentInfo, error) {
func (r *runner) setupAgent(ctx context.Context, config *testConfig, state ServiceState, policy *kibana.Policy, agentManifest packages.Agent) (agentdeployer.DeployedAgent, agentdeployer.AgentInfo, error) {
if !r.options.RunIndependentElasticAgent {
return nil, agentdeployer.AgentInfo{}, nil
}
logger.Warn("setting up agent (technical preview)...")
agentInfo, err := r.createAgentInfo(policy, config)
agentInfo, err := r.createAgentInfo(policy, config, agentManifest)
if err != nil {
return nil, agentdeployer.AgentInfo{}, err
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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).

pid_mode: "host"
linux_capabilities:
- AUDIT_CONTROL
Expand Down
Original file line number Diff line number Diff line change
@@ -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

name: auditd_manager_independent_agent
title: "Auditd Manager"
version: 999.999.999
license: basic
description: "The Auditd Manager Integration receives audit events from the Linux Audit Framework that is a part of the Linux kernel."
type: integration
categories:
- os_system
- security
conditions:
kibana.version: "^8.2.0"
elastic:
subscription: basic
kibana:
version: "^8.2.0"
screenshots:
- src: /img/sample-screenshot.png
title: Sample screenshot
Expand All @@ -30,3 +32,6 @@ policy_templates:
description: Collecting auditd events
owner:
github: elastic/security-external-integrations
agent:
privileges:
root: true