Lesson 7 of 14 · 10m
Mounting docker.sock Is Mounting root
The Docker API socket is a root daemon with no scoped permissions — mounting it, or exposing port 2375, is remote root on the host.
The socket is the daemon
/var/run/docker.sock is the Unix socket the Docker daemon listens on, and the daemon runs as root. The REST API on that socket can create containers — including privileged containers with arbitrary bind mounts. So a container with the socket mounted has an API that runs as root on the host, and the call that matters is:
POST /containers/create
{"Image": "alpine",
"HostConfig": {"Binds": ["/:/host"], "Privileged": true},
"Cmd": ["sh", "-c", "chroot /host"]}New container, host filesystem mounted at /host, privileged. One HTTP call from inside. This is why "mount the socket so the app can list containers" is never just listing containers — the Docker API has no concept of a read-only or low-privilege client. Whoever reaches the socket is root.
The wrong model here is thinking of the socket as a file. It is not data the container can read; it is a remote procedure call surface into a root daemon. Files mount into a container; sockets mount authority.
The pattern in the wild
The compose line that causes it appears constantly:
volumes:
- /var/run/docker.sock:/var/run/docker.sockCI runners mount it to spawn sibling builds. Dashboards mount it to show container stats. Portainer-style management UIs exist to be mounted with it — which is a design decision that makes compromise of the dashboard equal to compromise of the host.
Attackers know the equivalent on TCP. Docker can expose its API on port 2375 (plain HTTP, no auth) or 2376 (TLS). Internet-wide scans for 2375 are continuous; Juniper documented cryptojacking campaigns against exposed daemons back in 2019, and TeamTNT's worm campaigns through 2020-2021 did the same — find an open daemon, POST a privileged container running XMRig, done. It remains one of the cheapest mass-exploits on the internet because a single misconfig is the whole exploit.
The sibling sockets
Docker is not the only daemon. /run/containerd/containerd.sock drives containerd — image pulls, container lifecycle. /run/crio/crio.sock drives CRI-O. On Kubernetes nodes, /run/dockershim.sock variants and the kubelet's own API live on the node. Any of them mounted into a pod is node compromise.
One worth naming precisely: CVE-2020-15257, disclosed November 30, 2020 by Jeff Asper at Google. containerd's shim processes — the per-container middlemen between containerd and runc — listened on abstract Unix sockets named @containerd-shim-api/... that lived in the host's network namespace. Any container running --network host could connect to them and drive the shim: execute commands as root on the host. Fixed in containerd 1.3.9 and 1.4.3 by moving shims to vsock/non-network-visible transports. The escape did not require a socket mounted into the container — the socket was reachable through the shared network namespace. Two lessons in one: daemon sockets are root, and host network mode is never just about ports.
One more wrinkle for the model: the daemon API has no scoped permissions. There is no token shape that says "may list containers but not create them." TLS client certs on 2376 authenticate; they don't authorize. Every socket credential is a skeleton key, which is why the only safe mount is none.
What to actually do
- Never mount
docker.sock,containerd.sock, orcrio.sockinto a workload. Grep for them:docker inspect --format '{{range .Mounts}}{{.Source}}{{end}}'andhostPathin pod specs. - For "spawn a build from CI," use a dedicated builder: a rootless Docker or Podman daemon inside the job, kaniko-style daemonless builds, or a separate builder VM. The sibling-container pattern is the wrong tool.
- Never expose port 2375. If remote API access is truly required, TLS on 2376 with client certs — and even then, know that a cert is root on the host.
- For management UIs, run them on a host with nothing else to lose, or accept that their compromise is total. There is no middle setting.
Was this lesson helpful?
Keep reading
Related articles from the SudoSecurity blog.
A 257-Byte Password Is the Key: Inside the OpenSSH musl Bypass
CVE-2026-123158 lets an attacker log into a locked account on musl-based systems like Alpine by sending a password nobody set. The trigger is one number, 257, and the reason is a C library returning a single asterisk. I reproduced the exact boundary against musl 1.2.4 and read the fix.
A Password-Free Path to Root: Inside the macOS Screen Sharing Vulnerability Now Under Attack
A logic bug in screensharingd let attackers skip authentication entirely and land as root — no password required. Here's how it was found, patched, reverse-engineered, and finally weaponized.
CVE-2026-31431 "Copy Fail": How a 9-Year-Old Linux Kernel Bug Gives Any Local User Root in 732 Bytes
CVE-2026-31431 chains AF_ALG, splice(), and authencesn's ESN scratch write into a deterministic 4-byte page cache write that gives an unprivileged local user root. Full technical breakdown, exploit mechanics, detection, mitigation, and patch status per distro.
BlueHammer: The Unpatched Windows Zero-Day That Weaponizes Microsoft Defender Against Your Own System
BlueHammer is an unpatched, publicly released Windows local privilege escalation exploit that chains Microsoft Defender's update workflow, Volume Shadow Copy, Cloud Files callbacks, and opportunistic locks to reach NT AUTHORITY\SYSTEM from a standard user account.