Skip to content

Commit fd8f853

Browse files
authored
change Docker image to run as nonroot for k8s clusters restricting to runAsNonRoot (#515)
* change Docker image to run as nonroot for k8s clusters restricting to runAsNonRoot Refs: elastic/elastic-otel-node#1398 * also chown the copied files
1 parent 5c0b40f commit fd8f853

2 files changed

Lines changed: 9 additions & 3 deletions

File tree

operator/Dockerfile

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,11 @@ RUN pip install --no-cache-dir --target workspace /opt/distro/*.whl -r requireme
3838

3939
FROM ${IMAGE}:${IMAGE_VERSION}
4040

41-
COPY --from=build /operator-build/workspace /autoinstrumentation
42-
COPY --from=build-musl /operator-build/workspace /autoinstrumentation-musl
41+
COPY --chown=65532:65532 --from=build /operator-build/workspace /autoinstrumentation
42+
COPY --chown=65532:65532 --from=build-musl /operator-build/workspace /autoinstrumentation-musl
43+
44+
# Use wolfi's "nonroot" user/group to satisfy k8s runAsNonRoot security policies.
45+
USER 65532:65532
4346

4447
RUN chmod -R go+r /autoinstrumentation
4548
RUN chmod -R go+r /autoinstrumentation-musl

operator/Dockerfile.alpine

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@ RUN pip install --target workspace /opt/distro/*.whl -r requirements.txt
1515

1616
FROM python:3.12-alpine3.22@sha256:f6973b8f9395204414a7f25d99a50ba1c7306064771d11a8c2a848e9af3697a6
1717

18-
COPY --from=build /operator-build/workspace /autoinstrumentation
18+
COPY --chown=65534:65534 --from=build /operator-build/workspace /autoinstrumentation
19+
20+
# Use "nobody" user, to mimic the non-root "nonroot" user/group used in Dockerfile.
21+
USER 65534:65534
1922

2023
RUN chmod -R go+r /autoinstrumentation

0 commit comments

Comments
 (0)