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 —postinstallscripts are a classic — exfiltrates credentials and pivots to everything else the runner can reach. - Exposed TCP.
dockerd -H tcp://0.0.0.0:2375without 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/createwith 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, likeCONTAINERSGET, 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:dindwith 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 contextover 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 — treatdocker buildin CI with the same suspicion. - Detect the pattern in your fleet:
docker ps --filter volume=/var/run/docker.socklists 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/jsonis 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/jsonis the whole attack — no exploit, no CVE, just the API doing its job.
Was this lesson helpful?
Keep reading
Related articles from the SudoSecurity blog.
PostgreSQL 19 Is Out. REPACK Kept My Writes Running. The Docker Upgrade Will Stop Your App.
PostgreSQL 19 shipped on November 19 with REPACK (CONCURRENTLY), which removes table bloat without blocking writes. I measured it against VACUUM FULL, ran the upgrade from 18, and checked what breaks for self-hosters: Docker tags that refuse to start, a config setting that stops the server, and...
Self-Hosting Prometheus and Grafana: Infrastructure Monitoring That Actually Works
Build a production-grade monitoring stack with Prometheus and Grafana from scratch. Covers architecture, Docker Compose deployment, Node Exporter, alerting with Alertmanager, PromQL from basics to advanced, pre-built dashboards, and everything SudoSecurity uses to monitor its own infrastructure.
What is Kubernetes? Container Orchestration at Scale
Kubernetes runs your Docker containers across a cluster of machines, handles scheduling, health checking, rolling deployments, auto-scaling, and self-healing. When your application outgrows a single server, Kubernetes is how it runs on ten.
What is Docker? Containers, Images, and Why Every Developer Needs to Know This
Docker packages your application and everything it needs to run into a container that behaves identically on your laptop, your teammate's machine, and the production server. "It works on my machine" stops being a problem. Here is how it actually works and what production usage looks like.