-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
Run all knative-sample images as non root #5758
Run all knative-sample images as non root #5758
Conversation
Signed-off-by: karthikmurali60 <[email protected]>
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: karthikmurali60 The full list of commands accepted by this bot can be found here.
Needs approval from an approver in each of these files:
Approvers can indicate their approval by writing |
✅ Deploy Preview for knative ready!Built without sensitive environment variables
To edit notification comments on pull requests, go to your Netlify site configuration. |
Welcome @karthikmurali60! It looks like this is your first PR to knative/docs 🎉 |
Hello @karthikmurali60, I'm thinking we should remove the Thoughts @dprotaso? |
+1 on the |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See comments above
Sorry for the intrusion; I was working on this issue before that @karthikmurali60 answered me (see comment). I have a draft PR (prushh#1) on my repository if you are interested. I would like to expose some points:
Thanks for your time. |
Ah, I did not get that. These are all very good points 👍 is it possible that you coordinate to combine your work? |
It seems both |
My bad, I started working on it since he hadn't responded for a while.
No problem here! I would like to know if you have any preferences on the Dockerfile structure in order to standardise them a bit:
|
I don't have a strong preference here, but as these are "just" code-samples, I'd vote to keep it as simple as possible.
Sure.
👍
Yeah, but keep in mind that those images are also used in more restrictive environments than vanilla K8s like OpenShift, which will overwrite the
Debian, see https://github.com/GoogleContainerTools/distroless |
I pushed the cloudevents-go sample using the following image definition. Show Dockerfile# Use the official Golang image to create a build artifact.
# This is based on Debian and sets the GOPATH to /go.
# https://hub.docker.com/_/golang
FROM golang:1.13 as builder
ARG TARGETOS
ARG TARGETARCH
# Create and change to the app directory.
WORKDIR /app
# Copy local code to the container image.
COPY . ./
# Ensure Go modules are on and create the go.mod and go.sum files.
# Also builds the binary
ENV GO111MODULE=on
RUN go mod init cloudevents.go \
&& CGO_ENABLED=0 GOOS=linux GOOS=${TARGETOS} GOARCH=${TARGETARCH} go build -v -o server
# Allows the container builds to reuse downloaded dependencies.
RUN go mod download
# Use the official Alpine image for a lean production container.
# https://hub.docker.com/_/alpine
# https://docs.docker.com/develop/develop-images/multistage-build/#use-multi-stage-builds
FROM alpine:3
ARG USER=appuser
ARG USER_UID=1000
ARG USER_GID=$USER_UID
# Add a user so the server will run as a non-root user.
RUN addgroup -g $USER_GID $USER && \
adduser -u ${USER_UID} -G $USER -D $USER && \
apk add --no-cache ca-certificates
# Create and change to the app directory.
WORKDIR "/home/${USER}/app"
# Copy the binary to the production image from the builder stage.
COPY --from=builder /app/server ./server
# Set the non-root user as current.
USER $USER
# Run the web service on container startup.
CMD ["./server"] You can find it at https://hub.docker.com/r/prushh/cloudevents-go |
@prushh tested on OpenShift, works fine with a random runtime user:
|
@karthikmurali60 Could you please give me access to your Otherwise, I could create a new PR with both our commits. |
@ReToCode How can I proceed? He hasn't answered in a while... |
Feel free to open a new PR on your fork, referencing this PR here. I'll close this one. |
Fixes knative/serving#14566
Proposed Changes