Skip to content

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.sock

CI 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, or crio.sock into a workload. Grep for them: docker inspect --format '{{range .Mounts}}{{.Source}}{{end}}' and hostPath in 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?

Sign in to rate

Keep reading

Related articles from the SudoSecurity blog.