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

Do not use non-numeric UID in Dockerfile #484

Open
jiridanek opened this issue Oct 28, 2022 · 2 comments
Open

Do not use non-numeric UID in Dockerfile #484

jiridanek opened this issue Oct 28, 2022 · 2 comments

Comments

@jiridanek
Copy link
Member

https://docs.openshift.com/container-platform/4.6/openshift_images/create-images.html says

Support arbitrary user ids

By default, OpenShift Container Platform runs containers using an arbitrarily assigned user ID. This provides additional security against processes escaping the container due to a container engine vulnerability and thereby achieving escalated permissions on the host node.

For an image to support running as an arbitrary user, directories and files that are written to by processes in the image must be owned by the root group and be read/writable by that group. Files to be executed must also have group execute permissions.

Adding the following to your Dockerfile sets the directory and file permissions to allow users in the root group to access them in the built image:

RUN chgrp -R 0 /some/directory &&
chmod -R g=u /some/directory
Because the container user is always a member of the root group, the container user can read and write these files.

@jiridanek
Copy link
Member Author

This is to fix rh-messaging/shipshape#75

jiridanek added a commit to jiridanek/cli-java that referenced this issue Oct 28, 2022
It appears that not setting USER at all will take care of this.
@jiridanek jiridanek linked a pull request Oct 28, 2022 that will close this issue
@jiridanek
Copy link
Member Author

Actually, correct fix is

    shadow-utils \
 && microdnf clean all

RUN useradd --uid 10000 runner
USER 10000

as in https://github.com/skupperproject/skupper-router/pull/827/files

This follows the least-privilege in any Kubernetes, not just OpenShift. The idea with 10000 is not to clash with any user defined on the host system, https://kubesec.io/basics/containers-securitycontext-runasuser/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant