Rootless containers, capabilities and isolation
Running containers without root: namespaces, capabilities and what isolation misses.

A container is not a small virtual machine. A virtual machine gets its own kernel; a container shares the host’s, and its isolation is a set of kernel features that fence one group of processes off from another. The manual says: “A namespace wraps a global system resource in an abstraction that makes it appear to the processes within the namespace that they have their own isolated instance of the global resource.” Three mechanisms do the work — namespaces decide what a process can see, capabilities what it may do, cgroups how much it may consume.
WHAT CONFINEMENT IS MADE OF WHAT IT IS NOT
one shared host kernel a second kernel per guest
------------------------------------- ---------------------------
namespaces -> what it can SEE a hypervisor sitting between
pid net mnt ipc guest and host: a bug in the
uts time user guest kernel stops at that
cgroup guest alone
capabilities -> what it may DO
(CAP_*; an allowlist
by default, the rest
dropped)
cgroups -> how much it may USE
cpu memory io
a fence built by the kernel and a wall the kernel is outside
enforced by the same kernel of: a kernel bug is inside
every container at once
A container is a set of namespaces, not a machine
The kernel offers eight namespace types, isolating mount points, process IDs, network stacks, IPC queues, hostnames, clocks, the cgroup root, and user and group IDs. The manual says plainly that “One use of namespaces is to implement containers”; each process exposes them under /proc/<pid>/ns/, and they last until the last member leaves. Creating most of them “in most cases requires the CAP_SYS_ADMIN capability”. The user namespace is the exception: “since Linux 3.8, no privilege is required to create a user namespace”. Created first in the same call, it grants the caller privilege over the rest, so “Thus, it is possible for an unprivileged caller to specify this combination of flags.”
The user namespace: root that is not root
A user namespace isolates security-related identifiers, “in particular, user IDs and group IDs”. The heart of rootless: “a process can have a normal unprivileged user ID outside a user namespace while at the same time having a user ID of 0 inside the namespace; in other words, the process has full privileges for operations inside the user namespace, but is unprivileged for operations outside the namespace.”
The bridge is /proc/<pid>/uid_map and /proc/<pid>/gid_map: a new namespace starts unmapped, and “Each line in the uid_map file specifies a 1-to-1 mapping of a range of contiguous user IDs between two user namespaces”. The kernel translates IDs across the boundary; the namespaces nest up to “a limit of 32 nested levels of user namespaces”.
Inside, privilege reaches only what the namespace owns: “Having a capability inside a user namespace permits a process to perform operations (that require privilege) only on resources governed by that namespace.” Some operations belong to no namespace — “changing the system (i.e., calendar) time”, loading a module — and “Only a process with privileges in the initial user namespace can perform such operations.”
Capabilities: trimming what root may do
Unix gave a process all root’s power or none; capabilities break that into named pieces. “Capabilities are a per-thread attribute”, each granting one permission: CAP_CHOWN to change file ownership, CAP_DAC_OVERRIDE to “Bypass file read, write, and execute permission checks.” Each thread carries sets — permitted, effective, inheritable, ambient and bounding. The dropping rule is what makes this hardening. “If a thread drops a capability from its permitted set, it can never reacquire that capability”, and “Once a capability has been dropped from the bounding set, it cannot be restored to that set.” Drops are permanent, so they are done early: Docker starts containers with a reduced set — “an allowlist instead of a denylist approach” — and Podman’s --cap-drop=all removes the set outright.
cgroups: a limit on resources, not a boundary
Control groups do a different job. A cgroup “is a mechanism to organize processes hierarchically and distribute system resources along the hierarchy in a controlled and configurable manner”, and “every process in the system belongs to one and only one cgroup”. Controllers — memory, CPU, I/O — attach limits to a subtree, and because the hierarchy nests, restrictions nearer the root “can not be overridden from further away”. They meter and cap, but hide nothing. Docker’s guide is explicit — cgroups “do not play a role in preventing one container from accessing or affecting the data and processes of another container”, yet they “are essential to fend off some denial-of-service attacks”; version 1 spread the controllers across separate hierarchies and “the development of these controllers was largely uncoordinated”, while version 2 unified them.
Rootless: running the whole stack unprivileged
Rootless containers move the whole stack inside a user namespace. “Rootless mode executes the Docker daemon and containers inside a user namespace”, and unlike userns-remap, where the daemon still runs as root, “in rootless mode, both the daemon and the container are running without root privileges”. Docker “does not use binaries with SETUID bits or file capabilities” apart from newuidmap and newgidmap.
Those helpers write the subordinate ID maps, and the maps are the practical limit: the account needs “at least 65,536 subordinate UIDs/GIDs” from /etc/subuid and /etc/subgid. --userns=host runs in the caller’s namespace, where “processes running in the container have the same privileges on the host as any other process launched by the calling user”, so rootless defaults to a private user namespace.
At the bottom sits the OCI runtime, runc, “a CLI tool for spawning and running containers on Linux according to the OCI specification”; its rootless support rests on one kernel condition — user namespaces “must be compiled and enabled in your kernel”.
What the boundary does not cover
Namespaces are the visible fence: “Processes running within a container cannot see, and even less affect, processes running in another container, or in the host system.” But Docker’s guide names it: “the default set of capabilities and mounts given to a container may provide incomplete isolation, either independently, or when used in combination with kernel vulnerabilities”.
Three things blunt it. First, privilege handed back: CAP_SYS_ADMIN, CAP_SYS_PTRACE, CAP_MKNOD and CAP_SYS_MODULE “are particularly dangerous when they are not used within a user namespace”, and --privileged is worse — “A privileged container turns off the security features that isolate the container from the host.” Second, the host filesystem: a bind mount can point at the host’s own root, so “you can start a container where the /host directory is the / directory on your host”. Third, seccomp and AppArmor or SELinux rest on the same kernel.
There is one kernel. A virtual machine puts a hypervisor between guest and host, so a bug in its guest kernel stops there; a container does not, and a kernel vulnerability sits inside every container at once — which is why the hardening above matters more here.
Level and prerequisites
L4 — confinement-level: it explains what namespaces, capabilities and cgroups each enforce, how the whole stack runs without root, and where the boundary ends, without designing an orchestration platform. Prerequisites are the identity model in users-groups-and-permissions-in-practice (L2), which covers those IDs and classic permissions — here only their mapping inside a user namespace is added — plus the container lifecycle in docker-podman-and-compose, the image in container-images-registries-volumes-and-networks, and the L1 process model.
Where to go next
- Knowledge — the index.
- Server and virtualization — the area this sheet belongs to.
- Operating systems — this sheet’s node.
- Companion sheets, still in draft: container images, registries, volumes and networks; Docker, Podman and Compose; health checks, restart policies and logging.
References
- Linux man-pages — namespaces(7) — https://man7.org/linux/man-pages/man7/namespaces.7.html — the eight namespace types, the
/proc/<pid>/ns/handles, CAP_SYS_ADMIN for namespace creation, and the user-namespace exception. - Linux man-pages — user_namespaces(7) — https://man7.org/linux/man-pages/man7/user_namespaces.7.html — the uid_map/gid_map mapping, the nesting limit, capabilities inside a user namespace, and the operations reserved to the initial user namespace.
- Linux man-pages — capabilities(7) — https://man7.org/linux/man-pages/man7/capabilities.7.html — the capability list, the per-thread sets, and the dropping rules for the permitted and bounding sets.
- Linux man-pages — cgroups(7) — https://man7.org/linux/man-pages/man7/cgroups.7.html — cgroups v1 and v2, hierarchies, and resource controllers.
- Linux kernel — Control Group v2 — https://www.kernel.org/doc/html/latest/admin-guide/cgroup-v2.html — the authoritative design document for cgroup v2.
- Docker — Rootless mode — https://docs.docker.com/engine/security/rootless/ — daemon and containers inside a user namespace, subordinate ID ranges, and setuid-free operation.
- Docker — Docker security — https://docs.docker.com/engine/security/ — the review areas, namespaces and cgroups, the default capability allowlist, and userns-remap.
- Podman — podman-run(1) — https://docs.podman.io/en/latest/markdown/podman-run.1.html —
--userns,--cap-add/--cap-drop,--security-optand--privileged. - Open Container Initiative — runc — https://github.com/opencontainers/runc — the OCI runtime, the bundle, and rootless support.