Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[aoc-collector non-root user]: Create and use a new user for the container image #2301

Merged
merged 2 commits into from
Oct 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 28 additions & 7 deletions cmd/awscollector/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,30 @@
ARG BUILDMODE=build

################################
# Certificate Stage #
# #
# Base Stage #
# #
################################
FROM alpine:latest AS certs
FROM alpine:latest AS base

ARG USERNAME=aoc
ARG USER_UID=4317

RUN addgroup \
-g $USER_UID \
$USERNAME && \
adduser \
-D \
-g $USERNAME \
-h "/home/${USERNAME}"\
-G $USERNAME \
-u $USER_UID \
$USERNAME

RUN apk --update add ca-certificates

################################
# Build Stage #
# #
# Build Stage #
# #
################################
FROM golang:1.20 AS prep-build

Expand Down Expand Up @@ -68,14 +82,21 @@ COPY config/ /workspace/config/
################################
FROM scratch

COPY --from=certs /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/ca-certificates.crt
ARG USERNAME=aoc

COPY --from=base /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/ca-certificates.crt
COPY --from=base /etc/passwd /etc/passwd
COPY --from=base /etc/group /etc/group
COPY --from=base /home/$USERNAME/ /home/$USERNAME
COPY --from=package /workspace/awscollector /awscollector
COPY --from=package /workspace/config/ /etc/
COPY --from=package /workspace/healthcheck /healthcheck

ENV RUN_IN_CONTAINER="True"

USER $USERNAME
# aws-sdk-go needs $HOME to look up shared credentials
ENV HOME=/root
ENV HOME=/home/$USERNAME
ENTRYPOINT ["/awscollector"]
CMD ["--config=/etc/otel-config.yaml"]
EXPOSE 4317 55681 2000
3 changes: 3 additions & 0 deletions deployment-template/eks/otel-container-insights-infra.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,9 @@ spec:
containers:
- name: aws-otel-collector
image: public.ecr.aws/aws-observability/aws-otel-collector:latest
securityContext:
runAsUser: 0
runAsGroup: 0
env:
- name: K8S_NODE_NAME
valueFrom:
Expand Down