You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
userns.RunningInUserNS() misdetects systemd PrivateUsers=full as the initial user namespace #239
github.com/moby/sys/userns.RunningInUserNS() currently detects the initial user namespace by parsing /proc/self/uid_map:
// userns_linux.gofuncuidMapInUserNS(uidMapstring) bool {
...// As per user_namespaces(7), /proc/self/uid_map of// the initial user namespace shows 0 0 4294967295.initNS:=a==0&&b==0&&c==4294967295return!initNS
}
That assumes the only namespace that can contain 4294967295 UIDs is the initial namespace. However, uid_map describes ID mapping, not namespace identity. A non-initial user namespace can have a full identity map.
This now matters with systemd >= 260. (from: systemd/systemd@24c73c7) A service using PrivateUsers=full can run in a non-initial user namespace while still having a full identity UID/GID map:
0 0 4294967295
In that case, RunningInUserNS() returns false even though the process is in a user namespace.
We hit this through runc, which vendors moby/sys/userns. runc's cgroup-v2 device controller intentionally skips/ignores some eBPF device-controller failures when running in a user namespace:
Because RunningInUserNS() returns false under PrivateUsers=full, runc does not take that userns path and instead fails nested container startup with:
docker: Error response from daemon: failed to create task for container:
failed to create shim task: OCI runtime create failed: runc create failed:
unable to start container process: error during container init:
error setting cgroup config for procHooks process:
bpf_prog_query(BPF_CGROUP_DEVICE) failed: operation not permitted
...
The more robust check seems to be comparing /proc/self/ns/user to the kernel's initial user namespace inode, PROC_USER_INIT_INO (0xEFFFFFFD), rather than parsing /proc/self/uid_map. This is what systemd does, and what i propose we do in crun in containers/crun#2150
Would you accept a patch changing RunningInUserNS() to use the namespace inode check instead of the uid_map full-range heuristic?
when you run a unit with this setting, It removes all capabilities of the host userspace , but has full capabilities within the service's user namespace. At meta we run containers inside this types of transient units...
Activity
thaJeztah commentedon Jul 27, 2026
Thanks for reporting; contributions are definitely welcome; ISTR this code (which was extracted from runc) originally came from lxc, which also looks to still have the same logic, so probably needs to be adjusted as well? https://github.com/lxc/incus/blob/e45085dd42f826b3c8c3228e9733c0b6f998eafe/shared/util.go#L678-L700
cc @AkihiroSuda
AkihiroSuda commentedon Jul 28, 2026
How is this useful?
SGTM
aleivag commentedon Jul 28, 2026
when you run a unit with this setting, It removes all capabilities of the host userspace , but has full capabilities within the service's user namespace. At meta we run containers inside this types of transient units...
AkihiroSuda commentedon Jul 28, 2026
But why map the host root to the user-namespaced root?
aleivag commentedon Jul 29, 2026
Many container/runtime payloads expect to run as uid 0 and to have uid 0 capabilities for operations inside their own namespaces.
Mapping uid 0 to uid 0 keeps file ownership, bind mounts, and root-oriented setup code working normally.
kolyshkin commentedon Aug 11, 2026
Fixed in https://github.com/moby/sys/releases/tag/userns%2Fv0.2.0
CHANGELOG: add entry for moby/sys/userns bump
CHANGELOG: add entry for moby/sys/userns bump
CHANGELOG: add entry for moby/sys/userns bump
CHANGELOG: add entry for moby/sys/userns bump
CHANGELOG: add entry for moby/sys/userns bump