Skip to content

Commit a9db1b1

Browse files
authored
Stop running agent container as root by default (#21213)
Stop running Elastic Agent as root by default on docker image. When root user or other privileges are required, they will need to be explicitly configured at run time. This already happens now, except for the root user. Provided Kubernetes manifests already use security context to run as user 0.
1 parent 6bd7090 commit a9db1b1

4 files changed

Lines changed: 11 additions & 3 deletions

File tree

dev-tools/packaging/packages.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -340,7 +340,7 @@ shared:
340340
buildFrom: 'centos:7'
341341
dockerfile: 'Dockerfile.elastic-agent.tmpl'
342342
docker_entrypoint: 'docker-entrypoint.elastic-agent.tmpl'
343-
user: 'root'
343+
user: '{{ .BeatName }}'
344344
linux_capabilities: ''
345345
files:
346346
'elastic-agent.yml':

dev-tools/packaging/templates/docker/Dockerfile.elastic-agent.tmpl

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ RUN mkdir -p {{ $beatHome }}/data {{ $beatHome }}/data/elastic-agent-{{ commit_s
1212
chown -R root:root {{ $beatHome }} && \
1313
find {{ $beatHome }} -type d -exec chmod 0750 {} \; && \
1414
find {{ $beatHome }} -type f -exec chmod 0640 {} \; && \
15+
find {{ $beatHome }}/data -type d -exec chmod 0770 {} \; && \
16+
find {{ $beatHome }}/data -type f -exec chmod 0660 {} \; && \
1517
rm {{ $beatBinary }} && \
1618
ln -s {{ $beatHome }}/data/elastic-agent-{{ commit_short }}/elastic-agent {{ $beatBinary }} && \
1719
chmod 0750 {{ $beatHome }}/data/elastic-agent-*/elastic-agent && \
@@ -21,7 +23,7 @@ RUN mkdir -p {{ $beatHome }}/data {{ $beatHome }}/data/elastic-agent-{{ commit_s
2123
{{- range $i, $modulesd := .ModulesDirs }}
2224
chmod 0770 {{ $beatHome}}/{{ $modulesd }} && \
2325
{{- end }}
24-
chmod 0770 {{ $beatHome }}/data {{ $beatHome }}/data/elastic-agent-{{ commit_short }}/logs
26+
true
2527

2628
FROM {{ .from }}
2729

@@ -69,6 +71,10 @@ RUN chmod 755 /usr/local/bin/docker-entrypoint
6971

7072
COPY --from=home {{ $beatHome }} {{ $beatHome }}
7173

74+
# Elastic Agent needs group permissions in the home itself to be able to
75+
# create fleet.yml when running as non-root.
76+
RUN chmod 0770 {{ $beatHome }}
77+
7278
RUN mkdir /licenses
7379
COPY --from=home {{ $beatHome }}/LICENSE.txt /licenses
7480
COPY --from=home {{ $beatHome }}/NOTICE.txt /licenses

x-pack/elastic-agent/CHANGELOG.next.asciidoc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77

88
==== Breaking changes
99

10+
- Docker container is not run as root by default. {pull}21213[21213]
11+
1012
==== Bugfixes
1113

1214
==== New features

x-pack/elastic-agent/magefile.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -336,7 +336,7 @@ func requiredPackagesPresent(basePath, beat, version string, requiredPackages []
336336

337337
// TestPackages tests the generated packages (i.e. file modes, owners, groups).
338338
func TestPackages() error {
339-
return devtools.TestPackages(devtools.WithRootUserContainer())
339+
return devtools.TestPackages()
340340
}
341341

342342
// RunGo runs go command and output the feedback to the stdout and the stderr.

0 commit comments

Comments
 (0)