Skip to content

Lesson 4 of 14 · 13m

Capabilities: The Real Permission System

Root is a bitmask: Docker keeps fourteen capabilities, drops the dangerous rest, and CAP_SYS_ADMIN is the new root.

Root is a bitmask

Inside a default container, your process runs as UID 0 and is not root. Linux split superuser into about forty capabilities — CAP_SYS_ADMIN, CAP_SYS_MODULE, CAP_NET_RAW, CAP_DAC_READ_SEARCH, and so on — and Docker keeps fourteen of them and drops the rest. The permission system you're thinking of, "it's root so it can do anything," governs nothing. What governs is the capability bounding set: a ceiling no setuid binary or exec can climb past.

The fourteen kept by default:

CHOWN DAC_OVERRIDE FSETID FOWNER MKNOD NET_RAW
SETGID SETUID SETFCAP SETMPCAP NET_BIND_SERVICE
SYS_CHROOT KILL AUDIT_WRITE

Read that list. NET_BIND_SERVICE so containers can bind low ports. KILL, SETUID, SETGID, CHOWN so normal Unix file and process work functions. NET_RAW for ICMP and raw sockets — which also permits ARP spoofing and crafted packets inside whatever network the container shares, a fact pentesters have used for years on flat container networks. MKNOD lets a container create device nodes; the cgroup device filter (or its eBPF replacement on v2) is what stops the open() call. Layers, not vibes.

Everything dangerous is dropped: CAP_SYS_ADMIN (mounts, cgroupfs, half of what root means), CAP_SYS_MODULE (load kernel modules), CAP_SYS_PTRACE (debug and inject into other processes), CAP_DAC_READ_SEARCH (read any file regardless of mode), CAP_SYS_RAWIO (/dev/mem, port I/O), CAP_NET_ADMIN (iptables, interfaces, netfilter).

CAP_SYS_ADMIN is the new root

That phrase is Brad Spengler's, and it is the single most important line in container security. CAP_SYS_ADMIN is the grab-bag capability — mount filesystems, umount2, bind mounts, cgroup operations, quota ioctls, dozens of unrelated privileges dumped into one bit because nobody wanted to add a new capability. Docker drops it. Every kernel feature reachable through it stays reachable only while it stays dropped.

Chain it once: CAP_SYS_ADMIN lets a container mount cgroupfs. Mounting cgroupfs — before the CVE-2022-0492 fix — let it write release_agent. release_agent executes on the host. One capability, one config mistake, host root.

CAP_SYS_MODULE is worse in one step: init_module inserts a kernel module, which is host-root-with-a-compiler. CAP_SYS_PTRACE scopes to the container's PID namespace, so it matters less alone — but pair it with --pid=host and it means attach-and-inject into arbitrary host processes. CAP_DAC_READ_SEARCH bypasses file read permissions; cryptomining crews have used it to read host files they could reach through sloppy mounts. CAP_NET_ADMIN reaches netfilter — which is how the nf_tables kernel bugs get armed from inside containers.

The bounding set is the audit artifact

Capabilities live in five sets — permitted, effective, inheritable, bounding, ambient — but for defense you care about two: the bounding set (the ceiling) and effective (what the process holds now). The bounding set is the part nobody can raise back: exec'ing a setuid root binary inside the container can't restore a dropped capability, because the set travels with the container and only capset inside the bounding set is legal. The ambient set is the exception-shaped corner — the kernel added ambient capabilities in 4.3 so non-root processes could hold a cap across exec, which is useful exactly as often as it is dangerous.

capsh --decode=<hex> decodes CapEff/CapBnd lines from /proc/<pid>/status. docker inspect shows the configured side:

docker inspect --format '{{.HostConfig.CapAdd}} {{.HostConfig.CapDrop}}' <ctr>

Kubernetes carries the same idea through securityContext.capabilities.add/drop, plus privileged: true which is the "give me all of them" flag.

What to actually do

Drop everything, then add back what the workload needs:

docker run --cap-drop=ALL --cap-add=NET_BIND_SERVICE nginx
securityContext:
  capabilities:
    drop: ["ALL"]
    add: ["NET_BIND_SERVICE"]

If a container genuinely cannot run without SYS_ADMIN, the answer is almost never --privileged; it is --cap-add=SYS_ADMIN with your eyes open, or finding out which specific mount it wants and doing it differently. And keep no-new-privileges in the picture — --security-opt=no-new-privileges:true sets PR_SET_NO_NEW_PRIVS, so even a setuid root binary inside the container cannot elevate past the ambient set. One flag, closes an entire escalation class.

Was this lesson helpful?

Sign in to rate

Keep reading

Related articles from the SudoSecurity blog.