Skip to content

Commit c2ff98b

Browse files
authored
Set user depending on agent.privileges.root field from manifest (elastic#1789)
Set user root if specified in agent.privileges.root (package manifest). If user is also specified in the configuration file (system tests), that value from the configuration file has preference.
1 parent 0615df4 commit c2ff98b

File tree

4 files changed

+25
-8
lines changed

4 files changed

+25
-8
lines changed

internal/packages/packages.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,12 @@ type Owner struct {
115115
Type string `config:"type" json:"type" yaml:"type"`
116116
}
117117

118+
type Agent struct {
119+
Privileges struct {
120+
Root bool `config:"root" json:"root" yaml:"root"`
121+
} `config:"privileges" json:"privileges" yaml:"privileges"`
122+
}
123+
118124
// PackageManifest represents the basic structure of a package's manifest
119125
type PackageManifest struct {
120126
SpecVersion string `config:"format_version" json:"format_version" yaml:"format_version"`
@@ -130,6 +136,7 @@ type PackageManifest struct {
130136
Description string `config:"description" json:"description" yaml:"description"`
131137
License string `config:"license" json:"license" yaml:"license"`
132138
Categories []string `config:"categories" json:"categories" yaml:"categories"`
139+
Agent Agent `config:"agent" json:"agent" yaml:"agent"`
133140
}
134141

135142
type Elasticsearch struct {

internal/testrunner/runners/system/runner.go

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -313,7 +313,7 @@ func (r *runner) createServiceOptions(variantName string) servicedeployer.Factor
313313
}
314314
}
315315

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

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

342+
// If user is defined in the configuration file, it has preference
343+
// and it should not be overwritten by the value in the manifest
344+
if info.Agent.User == "" && agentManifest.Privileges.Root {
345+
info.Agent.User = "root"
346+
}
347+
342348
return info, nil
343349
}
344350

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

822-
agentDeployed, agentInfo, err := r.setupAgent(ctx, config, serviceStateData, policy)
828+
agentDeployed, agentInfo, err := r.setupAgent(ctx, config, serviceStateData, policy, scenario.pkgManifest.Agent)
823829
if err != nil {
824830
return nil, err
825831
}
@@ -1127,12 +1133,12 @@ func (r *runner) setupService(ctx context.Context, config *testConfig, serviceOp
11271133
return service, service.Info(), nil
11281134
}
11291135

1130-
func (r *runner) setupAgent(ctx context.Context, config *testConfig, state ServiceState, policy *kibana.Policy) (agentdeployer.DeployedAgent, agentdeployer.AgentInfo, error) {
1136+
func (r *runner) setupAgent(ctx context.Context, config *testConfig, state ServiceState, policy *kibana.Policy, agentManifest packages.Agent) (agentdeployer.DeployedAgent, agentdeployer.AgentInfo, error) {
11311137
if !r.options.RunIndependentElasticAgent {
11321138
return nil, agentdeployer.AgentInfo{}, nil
11331139
}
11341140
logger.Warn("setting up agent (technical preview)...")
1135-
agentInfo, err := r.createAgentInfo(policy, config)
1141+
agentInfo, err := r.createAgentInfo(policy, config, agentManifest)
11361142
if err != nil {
11371143
return nil, agentdeployer.AgentInfo{}, err
11381144
}

test/packages/with-custom-agent/auditd_manager_independent_agent/data_stream/auditd/_dev/test/system/test-default-config.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ data_stream:
55
preserve_original_event: true
66
agent:
77
runtime: docker
8-
user: "root"
98
pid_mode: "host"
109
linux_capabilities:
1110
- AUDIT_CONTROL

test/packages/with-custom-agent/auditd_manager_independent_agent/manifest.yml

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,17 @@
1-
format_version: 1.0.0
1+
format_version: 2.12.0
22
name: auditd_manager_independent_agent
33
title: "Auditd Manager"
44
version: 999.999.999
5-
license: basic
65
description: "The Auditd Manager Integration receives audit events from the Linux Audit Framework that is a part of the Linux kernel."
76
type: integration
87
categories:
98
- os_system
109
- security
1110
conditions:
12-
kibana.version: "^8.2.0"
11+
elastic:
12+
subscription: basic
13+
kibana:
14+
version: "^8.2.0"
1315
screenshots:
1416
- src: /img/sample-screenshot.png
1517
title: Sample screenshot
@@ -30,3 +32,6 @@ policy_templates:
3032
description: Collecting auditd events
3133
owner:
3234
github: elastic/security-external-integrations
35+
agent:
36+
privileges:
37+
root: true

0 commit comments

Comments
 (0)