Skip to content

Add targeted supplementary GID mappings - #1834

Open
maxbeckmann wants to merge 3 commits into
containers:mainfrom
maxbeckmann:main
Open

Add targeted supplementary GID mappings#1834
maxbeckmann wants to merge 3 commits into
containers:mainfrom
maxbeckmann:main

Conversation

@maxbeckmann

Copy link
Copy Markdown

This change lets a Toolbox container receive selected supplementary host groups through explicit GID mappings. A mapping can be supplied when the container is created:

$ toolbox create --gid-map 971:100000

The option is repeatable. The same policy can be made persistent in toolbox.conf, including the host-wide /etc/containers/toolbox.conf:

[general]
gid_maps = ["971:100000"]

Command-line mappings replace the configured list. If neither interface is used, container creation keeps its existing --userns keep-id behaviour.

Each entry maps HOST_GID to CONTAINER_GID and adds the latter to the container's supplementary groups. Toolbox checks that the host GID is one of the calling user's supplementary groups and rejects duplicate or conflicting mappings. The host administrator must also delegate the host GID through subgid(5); for example:

# usermod --add-subgids 971-971 user
# podman system migrate

Mappings are fixed when a container is created, so existing containers must be recreated after changing them.

Motivation

This addresses the still-open Toolbox supplementary-group problem tracked by issue #1348, including the VirtualBox failure in #1589 and related device-access reports such as the USB printer in #1617. Toolbox recursively bind-mounts the host's /dev, but the runtime normally clears the user's host supplementary groups while setting up the container. This makes some devices visible but unusable. Even more severely, it can prevent the container from starting at all when the runtime cannot traverse a group-restricted device tree.

VirtualBox USB devices are one example. They are normally owned by root:vboxusers, with 0750 directories and 0660 device nodes below /dev/vboxusb. Membership in vboxusers grants access on the host but is dropped by crun when starting the container unless instructed otherwise.

As far as I understood, there is no general Podman-side fix foreseeable. Podman treats this as an authorization and namespace-policy decision, not a group it can transparently infer and expose. Membership in a host group permits a process to retain its existing credential, but it does not authorize namespace root to manufacture that credential later. A real mapping therefore requires prior administrator delegation through /etc/subgid.

Podman maintainers have improved the explicit mapping primitives in PR #18713, but have not adopted automatic mapping of all current supplementary groups. The general rootless group-mapping issue #13090 remains open, while the exact VirtualBox report #14284 was closed without a general solution. A more recent attempt to warn and recommend mappings, PR #29208, is still a draft with changes requested; its review again directs the simple case to crun's keep-groups.

Podman therefore already provides the mechanism needed by this change, while Toolbox must provide the opt-in integration and the host administrator must provide the authorization. This proposal replaces --userns keep-id with equivalent explicit mappings for the calling user's primary UID and GID, adds only the requested supplementary GID mappings, and passes their container-side GIDs through --group-add.

This is deliberately narrower than crun's --group-add keep-groups. Retaining all host supplementary credentials would change how the runtime establishes the container's group set and would hence displace container-native groups such as wheel, affecting sudo and login behaviour. Explicit mappings preserve normal OCI group handling, allow container-native groups to coexist, and make each additional host authority an administrator-approved opt-in through /etc/subgid.

Relationship to existing Toolbox proposals

No existing Toolbox pull request implements targeted host-to-container GID mappings. This change is distinct from the three current proposals around /dev and supplementary groups:

  • PR #1647 conditionally adds crun's --group-add keep-groups. It is still open and stalled after its broader host group set invalidated existing group expectations.
  • PR #1732 also uses keep-groups, without checking for crun. It has changes requested, testing demonstrated loss of wheel/sudo, and its author subsequently pointed to PR cmd/create: stop bind-mounting the host /dev , fixing VirtualBox issues #1778 instead.
  • PR #1778 stops mounting the whole host /dev during OCI setup and projects selected entries later. This improves startup robustness and preserves container groups, but deliberately does not grant access to group-restricted host devices and relies on a hard-coded exclusion policy.

The whole-host /dev bind originated in PR #119 to make dynamic host devices visible. This change retains that visibility model and addresses its missing authorization half. It neither preserves every host group nor creates a new policy for which /dev entries Toolbox should expose: it maps only the groups explicitly selected and delegated by the host administrator.

Why not adjust the device permissions with udev?

A host udev rule is a workable local fix. For /dev/vboxusb, for example, it can add traversal permission to the generated directories and grant a named host user access to each device node with an ACL.

That approach changes the permission policy of every offending device tree. It requires device- and vendor-specific rules, per-user ACLs, and careful handling of creation events and rule ordering. Each new group-restricted device family needs another exception.

A host-wide Toolbox configuration that pins mappings for device-controlling groups is a better policy boundary for this use case, in my opinion. It leaves the ownership and modes chosen by the device provider intact, authorizes the mapping once for the controlling group, and applies to every path governed by that group. In other words, it carries the host's existing group-based authorization into selected Toolbox containers instead of bending each device's permissions around the container runtime.

@centosinfra-prod-github-app

Copy link
Copy Markdown

Build failed.
https://gateway-cloud-softwarefactory.apps.ocp.cloud.ci.centos.org/zuul/t/local/buildset/9dc3e8b0046248d789fe3ac1846b9e73

✔️ unit-test SUCCESS in 2m 23s
✔️ unit-test-migration-path-for-coreos-toolbox SUCCESS in 3m 17s
✔️ unit-test-restricted SUCCESS in 2m 14s
✔️ system-test-fedora-rawhide-commands-options SUCCESS in 42m 22s
✔️ system-test-fedora-rawhide-runtime-environment-arch-fedora SUCCESS in 32m 20s
✔️ system-test-fedora-rawhide-runtime-environment-ubuntu SUCCESS in 8m 28s
system-test-fedora-44-commands-options FAILURE in 56m 21s
✔️ system-test-fedora-44-runtime-environment-arch-fedora SUCCESS in 35m 54s
✔️ system-test-fedora-44-runtime-environment-ubuntu SUCCESS in 7m 18s
✔️ system-test-fedora-43-commands-options SUCCESS in 41m 41s
✔️ system-test-fedora-43-runtime-environment-arch-fedora SUCCESS in 35m 37s
✔️ system-test-fedora-43-runtime-environment-ubuntu SUCCESS in 7m 22s
✔️ system-test-fedora-42-commands-options SUCCESS in 34m 48s
✔️ system-test-fedora-42-runtime-environment-arch-fedora SUCCESS in 26m 16s
✔️ system-test-fedora-42-runtime-environment-ubuntu SUCCESS in 6m 22s
✔️ system-test-fedora-coreos-next-commands-options SUCCESS in 55m 01s
✔️ system-test-fedora-coreos-next-runtime-environment-arch-fedora SUCCESS in 31m 24s
✔️ system-test-fedora-coreos-next-runtime-environment-ubuntu SUCCESS in 9m 24s
✔️ system-test-fedora-coreos-stable-commands-options SUCCESS in 53m 15s
✔️ system-test-fedora-coreos-stable-runtime-environment-arch-fedora SUCCESS in 41m 56s
✔️ system-test-fedora-coreos-stable-runtime-environment-ubuntu SUCCESS in 12m 17s
✔️ system-test-fedora-coreos-testing-commands-options SUCCESS in 54m 58s
✔️ system-test-fedora-coreos-testing-runtime-environment-arch-fedora SUCCESS in 29m 18s
✔️ system-test-fedora-coreos-testing-runtime-environment-ubuntu SUCCESS in 9m 01s

Signed-off-by: Max Beckmann <37029778+maxbeckmann@users.noreply.github.com>
Signed-off-by: Max Beckmann <37029778+maxbeckmann@users.noreply.github.com>
Signed-off-by: Max Beckmann <37029778+maxbeckmann@users.noreply.github.com>
@maxbeckmann

maxbeckmann commented Aug 9, 2026

Copy link
Copy Markdown
Author

If this approach seems useful, I’d be happy to explore further directions, like automatically forwarding supplementary GIDs delegated to the user creating a toolbox, automatically resolving collisions, and preserving host group names.

@centosinfra-prod-github-app

Copy link
Copy Markdown

Build succeeded.
https://gateway-cloud-softwarefactory.apps.ocp.cloud.ci.centos.org/zuul/t/local/buildset/b09f1d48a50a4d10a4a954a7f3e108c9

✔️ unit-test SUCCESS in 2m 18s
✔️ unit-test-migration-path-for-coreos-toolbox SUCCESS in 3m 19s
✔️ unit-test-restricted SUCCESS in 2m 08s
✔️ system-test-fedora-rawhide-commands-options SUCCESS in 50m 54s
✔️ system-test-fedora-rawhide-runtime-environment-arch-fedora SUCCESS in 38m 52s
✔️ system-test-fedora-rawhide-runtime-environment-ubuntu SUCCESS in 8m 17s
✔️ system-test-fedora-44-commands-options SUCCESS in 52m 55s
✔️ system-test-fedora-44-runtime-environment-arch-fedora SUCCESS in 28m 35s
✔️ system-test-fedora-44-runtime-environment-ubuntu SUCCESS in 9m 39s
✔️ system-test-fedora-43-commands-options SUCCESS in 49m 53s
✔️ system-test-fedora-43-runtime-environment-arch-fedora SUCCESS in 38m 07s
✔️ system-test-fedora-43-runtime-environment-ubuntu SUCCESS in 9m 09s
✔️ system-test-fedora-42-commands-options SUCCESS in 45m 52s
✔️ system-test-fedora-42-runtime-environment-arch-fedora SUCCESS in 23m 59s
✔️ system-test-fedora-42-runtime-environment-ubuntu SUCCESS in 8m 57s
✔️ system-test-fedora-coreos-next-commands-options SUCCESS in 48m 00s
✔️ system-test-fedora-coreos-next-runtime-environment-arch-fedora SUCCESS in 46m 26s
✔️ system-test-fedora-coreos-next-runtime-environment-ubuntu SUCCESS in 8m 49s
✔️ system-test-fedora-coreos-stable-commands-options SUCCESS in 53m 02s
✔️ system-test-fedora-coreos-stable-runtime-environment-arch-fedora SUCCESS in 45m 38s
✔️ system-test-fedora-coreos-stable-runtime-environment-ubuntu SUCCESS in 14m 43s
✔️ system-test-fedora-coreos-testing-commands-options SUCCESS in 38m 28s
✔️ system-test-fedora-coreos-testing-runtime-environment-arch-fedora SUCCESS in 38m 56s
✔️ system-test-fedora-coreos-testing-runtime-environment-ubuntu SUCCESS in 15m 06s

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 this pull request may close these issues.

1 participant