-
Notifications
You must be signed in to change notification settings - Fork 95
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
Enhancement request: Use deterministic UID/GID in Dockerfile #1555
Comments
Signed-off-by: tdruez <[email protected]>
@ghsa-retrieval Could you confirm that the changes at https://github.com/aboutcode-org/scancode.io/pull/1569/files are good enough for your needs? |
@tdruez Yes, but this change should come with a big warning because it will likely cause issues for existing installations where the container image used a different uid/gid before and stored its data in a volume. This can result in a failure to start due to permissions errors and would require to chown the volume. While this could have happened unintentionally in the past as well, give the non-deterministic nature of the assignment, here it is expected to break. For comparison, my local compose install without the patch shows the following IDs: However, I have observed the IDs fluctuating on Kubernetes deployments, so I'm not sure if people just got lucky with their compose deployments in the past or if docker compose does some magic under the hood for this case. |
@ghsa-retrieval Thanks for the insight! Do you have any suggestions on how we can address this with minimal impact on existing instances? |
@tdruez Good question. It seems that docker compose does not provide an option to automatically modify the user permissions, unlike Kubernetes. What you could do is introduce a new service to the docker compose which modifies the permissions before starting web, worker, and nginx. I'm not sure if there is a cleaner solution for this, as this would only have to be run once on update to the new container image version. Note: This is just a quick example, you would likely want to put the UID and GID in the .env and reference the variables instead of hardcoding them as well as use a properly tagged version for the alpine image. I have also not checked if there are any files placed in the directories which may have been given ownership other than the one of the "app" user. The performance on startup will be impacted if there are many files to modify.
|
Is your enhancement request related to a problem? Please describe.
The UID and GID in the Dockerfile can change since the user and group are only created by name. This has implications for deployments that rely on identifying the user exactly. For example: Settings for the security context in Kubernetes/Helm charts, such as
runAsUser
andrunAsGroup
, cannot be applied, since the UID and GID are not known ahead of time and may change between versions. Similarly configurations to the user namespacing rely on this information.What are the benefits of the requested enhancement?
The user and group are no longer assigned a non-deterministic ID. You can set up user namespaces in a predictable way.
Describe the solution you would like
Modify the
adduser
andaddgroup
commands in the Dockerfile to use a numerical UID and GID instead of a name. The UID and GID should be ones that are not already occupied by the Python base image.Additional notes
Using a numerical UID and GID instead of name is also recommended according to Docker: https://docs.docker.com/build/building/best-practices/#user
The text was updated successfully, but these errors were encountered: