@@ -9,7 +9,6 @@ FROM {{ .buildFrom }} AS home
9
9
COPY beat {{ $beatHome }}
10
10
11
11
RUN mkdir -p {{ $beatHome }}/data {{ $beatHome }}/data/elastic-agent-{{ commit_short }}/logs && \
12
- chown -R root:root {{ $beatHome }} && \
13
12
find {{ $beatHome }} -type d -exec chmod 0755 {} \; && \
14
13
find {{ $beatHome }} -type f -exec chmod 0644 {} \; && \
15
14
find {{ $beatHome }}/data -type d -exec chmod 0770 {} \; && \
@@ -127,25 +126,16 @@ COPY --from=home {{ $beatHome }}/NOTICE.txt /licenses
127
126
COPY --from=home /opt /opt
128
127
{{- end }}
129
128
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
-
141
129
{{- if eq .user "root" }}
142
130
{{- if contains .image_name "-cloud" }}
143
131
# Generate folder for a stub command that will be overwritten at runtime
144
132
RUN mkdir /app
145
133
{{- end }}
146
134
{{- 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
149
139
150
140
{{- if contains .image_name "-cloud" }}
151
141
# Generate folder for a stub command that will be overwritten at runtime
@@ -154,6 +144,17 @@ RUN chown {{ .user }} /app
154
144
{{- end }}
155
145
{{- end }}
156
146
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
+
157
158
{{- if (and (contains .image_name "-complete") (not (contains .from "ubi-minimal"))) }}
158
159
USER root
159
160
ENV NODE_PATH={{ $beatHome }}/.node
0 commit comments