Skip to content
This repository has been archived by the owner on Jul 7, 2023. It is now read-only.

Commit

Permalink
Merge pull request #32 from jchauncey/run-as-nonroot
Browse files Browse the repository at this point in the history
feat(Dockerfile): Run as nonroot user
  • Loading branch information
k8s-ci-robot committed Jun 4, 2020
2 parents 33ef516 + fc984f0 commit 5bfe3a1
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -30,20 +30,21 @@ RUN echo "Building for $GOARCH" \
&& ln -sf `pwd` ${GOPATH}/src/github.com/kubernetes-sigs/dashboard-metrics-scraper \
&& GOARCH=${GOARCH} hack/build.sh

# Create a nonroot user for final image
RUN useradd -u 10001 nonroot

# Final stage: the running container.
FROM scratch AS final

# Import the Certificate-Authority certificates for enabling HTTPS.
COPY --from=builder /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/

# Import the compiled executable from the second stage.
COPY --from=builder /metrics-sidecar /metrics-sidecar

# We need a tmp folder too
COPY --from=builder /tmp /tmp
# Copy nonroot user
COPY --from=builder /etc/passwd /etc/passwd

# Declare the port on which the webserver will be exposed.
EXPOSE 8080
USER nonroot

# Run the compiled binary.
ENTRYPOINT ["/metrics-sidecar"]

0 comments on commit 5bfe3a1

Please sign in to comment.