Skip to content

Commit

Permalink
Stop running agent container as root by default (#21213)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
jsoriano authored Sep 24, 2020
1 parent 6bd7090 commit a9db1b1
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 3 deletions.
2 changes: 1 addition & 1 deletion dev-tools/packaging/packages.yml
Original file line number Diff line number Diff line change
Expand Up @@ -340,7 +340,7 @@ shared:
buildFrom: 'centos:7'
dockerfile: 'Dockerfile.elastic-agent.tmpl'
docker_entrypoint: 'docker-entrypoint.elastic-agent.tmpl'
user: 'root'
user: '{{ .BeatName }}'
linux_capabilities: ''
files:
'elastic-agent.yml':
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ RUN mkdir -p {{ $beatHome }}/data {{ $beatHome }}/data/elastic-agent-{{ commit_s
chown -R root:root {{ $beatHome }} && \
find {{ $beatHome }} -type d -exec chmod 0750 {} \; && \
find {{ $beatHome }} -type f -exec chmod 0640 {} \; && \
find {{ $beatHome }}/data -type d -exec chmod 0770 {} \; && \
find {{ $beatHome }}/data -type f -exec chmod 0660 {} \; && \
rm {{ $beatBinary }} && \
ln -s {{ $beatHome }}/data/elastic-agent-{{ commit_short }}/elastic-agent {{ $beatBinary }} && \
chmod 0750 {{ $beatHome }}/data/elastic-agent-*/elastic-agent && \
Expand All @@ -21,7 +23,7 @@ RUN mkdir -p {{ $beatHome }}/data {{ $beatHome }}/data/elastic-agent-{{ commit_s
{{- range $i, $modulesd := .ModulesDirs }}
chmod 0770 {{ $beatHome}}/{{ $modulesd }} && \
{{- end }}
chmod 0770 {{ $beatHome }}/data {{ $beatHome }}/data/elastic-agent-{{ commit_short }}/logs
true

FROM {{ .from }}

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

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

# Elastic Agent needs group permissions in the home itself to be able to
# create fleet.yml when running as non-root.
RUN chmod 0770 {{ $beatHome }}

RUN mkdir /licenses
COPY --from=home {{ $beatHome }}/LICENSE.txt /licenses
COPY --from=home {{ $beatHome }}/NOTICE.txt /licenses
Expand Down
2 changes: 2 additions & 0 deletions x-pack/elastic-agent/CHANGELOG.next.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@

==== Breaking changes

- Docker container is not run as root by default. {pull}21213[21213]

==== Bugfixes

==== New features
Expand Down
2 changes: 1 addition & 1 deletion x-pack/elastic-agent/magefile.go
Original file line number Diff line number Diff line change
Expand Up @@ -336,7 +336,7 @@ func requiredPackagesPresent(basePath, beat, version string, requiredPackages []

// TestPackages tests the generated packages (i.e. file modes, owners, groups).
func TestPackages() error {
return devtools.TestPackages(devtools.WithRootUserContainer())
return devtools.TestPackages()
}

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

0 comments on commit a9db1b1

Please sign in to comment.