Skip to content

Lesson 13 of 19 · 18m

The Docker Socket Is Root

The daemon API has no authorization layer — mounting /var/run/docker.sock or opening :2375 hands the caller host root; proxies and rootless builders are the fix.

Somewhere in your organization a CI job mounts /var/run/docker.sock "so the pipeline can build images," and a dashboard container mounts it "so it can show container status." Both are documented in a thousand tutorials. Both hand the container root on the host — no authentication, no audit trail, no halfway point.

Why the socket is total access

The Docker API has no authorization model — no scopes, no roles, no read-only flag. The socket is a Unix socket; access is governed by file permissions alone, and any client that can write to it can issue any call. That includes POST /containers/create with a body requesting HostConfig: {"Binds": ["/:/host"], "Privileged": true} — a container with the host filesystem mounted and full privileges, which is root on the host in every way that matters. From there: read /host/etc/shadow, chroot into the host fs, write a systemd unit that survives reboot. There is no read-only mode: docker.sock:ro restricts nothing about which API calls are accepted; it only prevents the container from unlinking the socket itself.

Where it bites in the real world

  • CI builds. "Mount the socket so the job can run docker build" is the era-2017 GitLab/Jenkins pattern, and it makes every pull request host-root on the runner. A malicious dependency — postinstall scripts are a classic — exfiltrates credentials and pivots to everything else the runner can reach.
  • Exposed TCP. dockerd -H tcp://0.0.0.0:2375 without TLS is an unauthenticated root API on the network. Mass exploitation of port 2375 for cryptomining has been a sustained campaign since 2018 — scanners find an open daemon within hours, and the payload is always the same trick: POST /containers/create with the host root filesystem mounted. Port 2376, TLS with client certificates, is the configured version.
  • Admin UIs. Portainer-style tools legitimately need the socket; that is an admin plane, and it should be isolated and authenticated like one — separate host, its own credentials, not beside your app containers.

TLS on 2376 authenticates the client but still does not authorize — a valid client certificate buys the same total access as the socket's file permission. There is no read-only credential to hand out. Docker has an authorization-plugin hook (--authorization-plugin) for exactly this, but the maintained plugin ecosystem is thin enough that the honest answer remains a filtering proxy.

What to do instead

  • Need read-only status? Put a filtering proxy in front — docker-socket-proxy (the tecnativa pattern) exposes only the endpoints you allow, like CONTAINERS GET, and refuses create/delete.
  • Need image builds inside CI? Use daemon-less builders: kaniko, buildah, or rootless BuildKit. None of them requires a socket mount.
  • Genuinely need a daemon? docker:dind with TLS client certs runs a nested daemon — isolated, but with its own storage-driver and nesting costs.
  • Change the whole equation: rootless Docker and podman run the daemon itself unprivileged, so socket compromise is not host compromise.

Try this

On a disposable box: docker run --rm -v /var/run/docker.sock:/var/run/docker.sock docker:cli ps. You are driving the host daemon from inside a container. Now read that line again as "every job in our CI can do this," and check whether yours can.

Field notes

  • docker context over SSH (ssh:// contexts) is the sane way to drive remote daemons — no TCP port, no TLS certificate distribution.
  • BuildKit runs its own daemon (buildkitd) with its own socket — treat docker build in CI with the same suspicion.
  • Detect the pattern in your fleet: docker ps --filter volume=/var/run/docker.sock lists every container currently holding host root.
  • Audit for the pattern: grep -r docker.sock --include='*.yml' --include='*.yaml' across repos finds every mount somebody forgot the meaning of.
  • GET /containers/json is what status dashboards actually need; if the proxy cannot express "list but not create," it is not a proxy.
  • The same reasoning covers podman.sock — the API compatibility means the same total access under a different filename.
  • curl --unix-socket /var/run/docker.sock http://localhost/containers/json is the whole attack — no exploit, no CVE, just the API doing its job.

Was this lesson helpful?

Sign in to rate

Keep reading

Related articles from the SudoSecurity blog.