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