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

Allow passing any uid for container processes. #386

Merged
merged 1 commit into from
Dec 4, 2020

Conversation

ambarve
Copy link
Contributor

@ambarve ambarve commented Dec 3, 2020

Usually if a username is provided when starting a process inside the container we look inside the /etc/passwd file of the container to find the uid and gid for that user. However, if a uid is provided instead of a username there is no need to look into the /etc/passwd file to see if that user exists.

This is in accordance with how things are handled in linux as can be seen here: https://github.com/opencontainers/runc/blob/master/libcontainer/user/user.go#L291 (this is called by docker).
In fact in the same function if the user string is passed as uid:gid (switch case 2) then we don't look up the uid inside the /etc/passwd file.

anmaxvl
anmaxvl previously approved these changes Dec 3, 2020
Copy link
Contributor

@anmaxvl anmaxvl left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@kevpar
Copy link
Member

kevpar commented Dec 3, 2020

Would be good to check that a more typical Linux runtime (e.g. moby or containerd on Linux) works when you specify a UID that doesn't exist.

@ambarve
Copy link
Contributor Author

ambarve commented Dec 3, 2020

@kevpar Yeah actually it is very easy to test that. On a linux machine (or on docker running over WSL) you can do docker run -it ubuntu:20.04 and then exec inside that container with docker exec -u 12345 -it <cid> /bin/bash. This works without any issues. And if you run id -u on that prompt it shows that the user id is 12345.

Usually if a username is provided when starting a process inside the container
we look inside the /etc/passwd file of the container to find the uid and gid for that
user. However, if a uid is provided instead of a username there is no need to look into
the /etc/passwd file to see if that user exists.

Signed-off-by: Amit Barve <ambarve@microsoft.com>
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants