#3764·youki

[Bug]: containers with their own multi-range user namespace fail under rootless Podman (--userns=keep-id)

Author: ItzExoticalCreated Sep 29, 2026Updated Oct 2, 2026

Bug Description

Rootless Podman runs the OCI runtime as root (uid 0) of a user namespace that it maps with newuidmap/newgidmap from /etc/subuid. That namespace's /proc/self/setgroups is allow. For --userns=keep-id, Podman asks the runtime for a new user namespace with three ranges and additionalGids: [1000]. youki fails in two ways:

  • With additionalGids: validation refuses the spec: unprivileged user can't set supplementary groups.
  • Without additionalGids: the mapping is never written, and the container fails with EINVAL from setresgid(0).

crun runs both.

Cause, at eb07b60173fca880e4287d5bc0de2580edec2c91:

  1. utils::rootless_required() (crates/libcontainer/src/utils.rs:264) returns true for any process in a non-initial user namespace, so a root runtime in Podman's namespace counts as unprivileged:
    • UserNamespaceConfig::privileged (crates/libcontainer/src/user_ns.rs:223);
    • the supplementary-group check in validate_spec_for_new_user_ns() (user_ns.rs:290-311).
  2. Because it is unprivileged, several ranges go to newuidmap/newgidmap (user_ns.rs:164, write_id_mapping() at :403). Run by that namespace's root they are refused: newuidmap: uid range [0-1000) -> [1-1001) not allowed.
  3. write_id_mapping() doesn't check the helper's exit status (.output() at user_ns.rs:441). The uid_map/gid_map stays empty, and the intermediate process fails later at set_id(0, 0) (container_intermediate_process.rs:122) with EINVAL.

How the others do it:

  • crun (1.30, src/libcrun/linux.c write_id_map(), lines 4520-4537) runs the helper only when its euid isn't 0. As root it writes the full map to /proc/<pid>/uid_map itself.
  • runc (v1.4.1, libcontainer/init_linux.go:491-495) sets additionalGids whenever setgroups isn't deny.

Why it is safe: the kernel lets an unprivileged process map a new user namespace only after it writes deny to its setgroups (CVE-2014-8989, user_namespaces(7)). A namespace whose setgroups is allow was therefore mapped by a privileged writer. Its root may map ids it holds into a child namespace, and may set groups.

A related detail: set_supplementary_gids() (crates/libcontainer/src/process/init/process.rs:822) returns early when additionalGids is empty. The container process then keeps the supplementary groups of whoever started the runtime. runc and crun call setgroups with the empty list.

Steps to Reproduce

No Podman needed. The user namespace is made with util-linux's unshare --map-auto, which uses newuidmap/newgidmap the way Podman does:

bash
#!/bin/sh
# repro.sh <runtime> <groups|nogroups> [workdir]
set -eu
RT=$1; CASE=$2; W=${3:-$(pwd)/work-$RT-$CASE}
here=$(cd "$(dirname "$0")" && pwd)
rm -rf "$W"; mkdir -p "$W/bundle/rootfs"
tar -xzf "$here/alpine-minirootfs-3.24.2-x86_64.tar.gz" -C "$W/bundle/rootfs" 2>/dev/null
cd "$W/bundle"
"$RT" spec --rootless
python3 - "$CASE" <<'P'
import json, sys
s = json.load(open('config.json'))
s['process']['terminal'] = False
s['process']['args'] = ['sh', '-c', 'id; cat /proc/self/uid_map']
s['process']['user'] = {'uid': 1000, 'gid': 1000}
if sys.argv[1] == 'groups':
    s['process']['user']['additionalGids'] = [1000]
m = [{'containerID': 0, 'hostID': 1, 'size': 1000},
     {'containerID': 1000, 'hostID': 0, 'size': 1},
     {'containerID': 1001, 'hostID': 1001, 'size': 64536}]
s['linux']['uidMappings'] = m
s['linux']['gidMappings'] = m
json.dump(s, open('config.json', 'w'), indent=2)
P
echo "outer: $(tr -s ' ' < /proc/self/uid_map | tr '\n' ';') setgroups=$(cat /proc/self/setgroups)"
"$RT" --root "$W/state" run --bundle "$W/bundle" "repro-$CASE"
  1. Put alpine-minirootfs-3.24.2-x86_64.tar.gz (sha256 c5ca053cfe1d85c5b96dff8b9bc57045f7f184a30ffb6b65776409ca90388677) next to the script. You need an /etc/subuid and /etc/subgid entry for your user.
  2. unshare --user --map-auto --map-root-user ./repro.sh youki groups:
    outer:  0 1000 1; 1 100000 65536; setgroups=allow
    ERROR libcontainer::user_ns: user is unprivileged. Supplementary groups cannot be set in a rootless container for this user due to CVE-2014-8989 user=Uid(0)
    ERROR libcontainer::user_ns: failed to validate spec for new user namespace: unprivileged user can't set supplementary groups
    ERROR youki: error in executing command: invalid spec for new user namespace container
  3. unshare --user --map-auto --map-root-user ./repro.sh youki nogroups:
    ERROR libcontainer::syscall::linux: failed to set real, effective and saved set gid err=EINVAL gid=Gid(0)
    ERROR libcontainer::process::container_main_process: failed to run intermediate process EINVAL: Invalid argument
    ERROR youki: error in executing command: failed to create container: intermediate process error EINVAL: Invalid argument
  4. The same two commands with crun print uid=1000 gid=1000 groups=1000 and uid=1000 gid=1000, and the three-range uid_map.

The helper refusal can be seen on its own:

bash
unshare --user --map-auto --map-root-user sh -c 'unshare --user sleep 20 & q=$!; sleep 0.5; newuidmap $q 0 1 1000 1000 0 1 1001 1001 64536; echo rc=$?'
# newuidmap: uid range [0-1000) -> [1-1001) not allowed
# rc=1

With Podman: podman --runtime youki run --rm --userns=keep-id alpine id fails with unprivileged user can't set supplementary groups. The same command with crun prints uid=1000(emilio) gid=1000(emilio) groups=1000(emilio).

Expectation

As with crun: the container runs with the requested three-range mapping, as uid/gid 1000, with exactly the requested supplementary groups.

System and Setup Info

youki version: 0.7.0
commit: 0.7.0-eb07b60173fca880e4287d5bc0de2580edec2c91
Kernel-Release    7.2.7-1-cachyos
Operating System  CachyOS
Cgroup setup      unified

util-linux 2.42.4, Podman 6.1.2, crun 1.30.1.

Additional Context

The runtime spec (config.md, "User") only says additionalGids are group IDs "in the container namespace to be added to the process". It sets no restriction for runtimes that run inside a user namespace.