opencontainers / opencontainers/runc
UID/GID fields of devices are ignored when using user namespaces
Nobody has claimed this yet.
- Dominant language
- Go
- Stars
- 13.5k
- Forks
- 2.3k
- Avg merge
- 2d 8h
- Merged PRs (30d)
- 30
Description
When user-namespaces are enabled for a container, runc appears to ignore any UID/GID settings provided for a device in that container's configuration.
The device instead just ends up with the uid/gid as found under the host's /dev for the reasons explained here. Obviously you can't chown or chmod the device when it's bind-mounted from the host, so instead the uid/gid/fileMode fields are just ignored.
In theory, I suspect it's possible for runc to actually support configuring these fields when a userns is enabled. The basic idea being:
- Detect that device uids/gids are being specified along with a userns
- Before any namespaces are entered,
mknodthe devices somewhere under the container's runtime state directory. As long as runc itself has the ability to callmknod(i.e. this isn't a rootless runc invocation or setting up a nested userns), then it can set the uid/gid/fileMode as needed - Once inside the container, instead of bind-mounting from the host's
/dev, bind-mount the devices created in the above step into the container
If the above fix would indeed work, I think it's worth doing. While there are certainly ways for callers of runc to workaround this issue themselves, they all involve significant compromises (i.e. change permissions under the host's /dev or map uids/gids into the userns that otherwise shouldn't be needed) and/or significant complexity that it seems runc itself is meant to handle.
@cyphar @crosbymichael @mrunalp and others, please let me know what your thoughts are on the feasibility of the suggested fix. It's purely hypothetical at the moment so I certainly could be missing something.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reading libcontainer/rootfs_linux.go at the device bind-mount logic and the referenced runtime-spec UID/GID fields. Trace how user namespaces and the container runtime state directory are handled before namespace entry. Done means device uid, gid, and fileMode settings are honored when possible with user namespaces, while rootless or nested-userns limitations remain explicit.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- go
- Domain
- operating-systems, security
- Issue type
- Bug
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100