Skip to content

Commit fa357a8

Browse files
[Fix] Agent incapable of running on Azure Container Instances (#3576)
What this change is introducing on top of bringing back work introduced in #3084 is change of ordrer for some operations. Changing owner of a file, discards capabilities set. This becomes a problem with heartbeat as it needs setuid and netraw capabilities to perform properly. So setting capabilities was moved after chown.
1 parent 9adbac2 commit fa357a8

File tree

2 files changed

+46
-14
lines changed

2 files changed

+46
-14
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
# Kind can be one of:
2+
# - breaking-change: a change to previously-documented behavior
3+
# - deprecation: functionality that is being removed in a later release
4+
# - bug-fix: fixes a problem in a previous version
5+
# - enhancement: extends functionality but does not break or fix existing behavior
6+
# - feature: new functionality
7+
# - known-issue: problems that we are aware of in a given version
8+
# - security: impacts on the security of a product or a user’s deployment.
9+
# - upgrade: important information for someone upgrading from a prior version
10+
# - other: does not fit into any of the other categories
11+
kind: bug
12+
13+
# Change summary; a 80ish characters long description of the change.
14+
summary: Elastic-Agent container runs on Azure Container Instances
15+
16+
# Long description; in case the summary is not enough to describe the change
17+
# this field accommodate a description without length limits.
18+
#description:
19+
20+
# Affected component; a word indicating the component this changeset affects.
21+
component: elastic-agent
22+
23+
# PR number; optional; the PR number that added the changeset.
24+
# If not present is automatically filled by the tooling finding the PR where this changelog fragment has been added.
25+
# NOTE: the tooling supports backports, so it's able to fill the original PR number instead of the backport PR number.
26+
# Please provide it if you are adding a fragment for a different PR.
27+
pr: 3576
28+
29+
# Issue number; optional; the GitHub issue related to this changeset (either closes or is part of).
30+
# If not present is automatically filled by the tooling with the issue linked to the PR number.
31+
issue: 82

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

+15-14
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ FROM {{ .buildFrom }} AS home
99
COPY beat {{ $beatHome }}
1010

1111
RUN mkdir -p {{ $beatHome }}/data {{ $beatHome }}/data/elastic-agent-{{ commit_short }}/logs && \
12-
chown -R root:root {{ $beatHome }} && \
1312
find {{ $beatHome }} -type d -exec chmod 0755 {} \; && \
1413
find {{ $beatHome }} -type f -exec chmod 0644 {} \; && \
1514
find {{ $beatHome }}/data -type d -exec chmod 0770 {} \; && \
@@ -127,25 +126,16 @@ COPY --from=home {{ $beatHome }}/NOTICE.txt /licenses
127126
COPY --from=home /opt /opt
128127
{{- end }}
129128

130-
131-
RUN setcap cap_net_raw,cap_setuid+p {{ $beatHome }}/data/elastic-agent-{{ commit_short }}/components/heartbeat && \
132-
{{- if .linux_capabilities }}
133-
# Since the beat is stored at the other end of a symlink we must follow the symlink first
134-
# For security reasons setcap does not support symlinks. This is smart in the general case
135-
# but in our specific case since we're building a trusted image from trusted binaries this is
136-
# fine. Thus, we use readlink to follow the link and setcap on the actual binary
137-
readlink -f {{ $beatBinary }} | xargs setcap {{ .linux_capabilities }} && \
138-
{{- end }}
139-
true
140-
141129
{{- if eq .user "root" }}
142130
{{- if contains .image_name "-cloud" }}
143131
# Generate folder for a stub command that will be overwritten at runtime
144132
RUN mkdir /app
145133
{{- end }}
146134
{{- else }}
147-
RUN groupadd --gid 1000 {{ .BeatName }}
148-
RUN useradd -M --uid 1000 --gid 1000 --groups 0 --home {{ $beatHome }} {{ .user }}
135+
RUN groupadd --gid 1000 {{ .BeatName }} && \
136+
useradd -M --uid 1000 --gid 1000 --groups 0 --home {{ $beatHome }} {{ .user }} && \
137+
chown -R {{ .user }}:{{ .user }} {{ $beatHome }} && \
138+
true
149139

150140
{{- if contains .image_name "-cloud" }}
151141
# Generate folder for a stub command that will be overwritten at runtime
@@ -154,6 +144,17 @@ RUN chown {{ .user }} /app
154144
{{- end }}
155145
{{- end }}
156146

147+
# Keep this after any chown command, chown resets any applied capabilities
148+
RUN setcap cap_net_raw,cap_setuid+p {{ $beatHome }}/data/elastic-agent-{{ commit_short }}/components/heartbeat && \
149+
{{- if .linux_capabilities }}
150+
# Since the beat is stored at the other end of a symlink we must follow the symlink first
151+
# For security reasons setcap does not support symlinks. This is smart in the general case
152+
# but in our specific case since we're building a trusted image from trusted binaries this is
153+
# fine. Thus, we use readlink to follow the link and setcap on the actual binary
154+
setcap {{ .linux_capabilities }} $(readlink -f {{ $beatBinary }}) && \
155+
{{- end }}
156+
true
157+
157158
{{- if (and (contains .image_name "-complete") (not (contains .from "ubi-minimal"))) }}
158159
USER root
159160
ENV NODE_PATH={{ $beatHome }}/.node

0 commit comments

Comments
 (0)