Skip to content

CL-0001: /var/run/docker.sock mounted — host control socket exposed, root-equivalent access

Severity: CRITICAL (how it is derived)

The service mounts the Docker socket, or a directory holding it, so code in the container can drive the daemon and start a privileged container on the host. :ro does not change that. Remove the mount, or put a filtering proxy between the service and the socket.

Fix

  1. Check whether the service needs the Docker API at all. Many do not: a log shipper can read Docker's log files, and a management UI may not need to live on the host. Real-world examples works through four deployed stacks and the four different correct answers.

  2. If it needs the API, give it a filtered socket. A proxy holds the real socket and publishes a restricted one that answers only the GET calls the service makes:

services:
  socket-proxy:
    image: wollomatic/socket-proxy:1@sha256:...   # pin the digest (CL-0019)
    user: "65534:${DOCKER_GID}"   # nobody, plus the host's docker group
    read_only: true
    cap_drop:
      - ALL
    security_opt:
      - no-new-privileges:true
    volumes:
      - /var/run/docker.sock:/var/run/docker.sock:ro
      - ./sockets:/sock
    command:
      - -proxysocketendpoint=/sock/docker.sock
      - -proxysocketendpointfilemode=432   # 0660, so a consumer in the docker group can connect
      # Only the GET endpoints the consumer calls; every write is refused.
      - -allowGET=^(/v[0-9]+\.[0-9]+)?/(_ping|version|info|images/json(\?.*)?|containers/json(\?.*)?|containers/[a-zA-Z0-9_.-]+/json(\?.*)?)$$

  consumer:
    image: myapp:1.0
    user: "65534:${DOCKER_GID}"
    environment:
      DOCKER_HOST: unix:///sock/docker.sock
    volumes:
      - ./sockets:/sock               # the filtered socket, not the real one
  1. Create the socket directory for the docker group before the first start, and put the group id where Compose reads it:
install -d -m 0770 -g docker sockets
echo "DOCKER_GID=$(getent group docker | cut -d: -f3)" >> .env

Without the first line the proxy, running as nobody, cannot create its socket and exits (captured on Docker 29.7.2, not CI-asserted):

level=ERROR msg="error creating socket" error="listen unix /sock/docker.sock: bind: permission denied"
  1. Check the filter. A read works and a write is refused:
docker compose up -d socket-proxy
docker compose run --rm consumer docker ps          # if the image has the docker CLI
# lists containers
docker compose run --rm consumer docker stop $(docker compose ps -q socket-proxy)
# Error response from daemon: Method Not Allowed

(Captured on Docker 29.7.2, not CI-asserted.)

  1. Check the findings. The consumer's finding is gone. The proxy still mounts the socket, so it keeps its finding; suppress it for that one service with the reason written down, and the rule stays live for every other service:
# .compose-lint.yml
rules:
  CL-0001:
    exclude_services:
      socket-proxy: "GET-only filtering proxy; consumers use the filtered socket"

Verified against Docker 29.7.2 with wollomatic/socket-proxy:1 and a docker:29-cli consumer: docker ps through the filtered socket listed containers, and docker stop and docker run both failed with Method Not Allowed. Constraining it when the need is real probes the filter endpoint by endpoint and explains why a unix socket beats a loopback TCP port here.

Tested on: Docker 29.7.2 with Compose 5.5.0, on a host without AppArmor (Yama ptrace_scope 1); the Fix steps above were re-run there in October 2026. Also measured in throwaway VMs in October 2026 (Docker 29.9.1 or 29.1.3): on Fedora 43 with SELinux enforcing, a socket mounted into a labelled container is refused (permission denied while trying to connect to the docker API at unix:///var/run/docker.sock, captured, not CI-asserted) and works only with label:disable. Rootless Docker 29.9.1 on Debian 13: through its socket, a container that mounts host / was refused /root and /etc/shadow and wrote the daemon user's home as that user; a write into /etc landed in rootlesskit's private copy, not the host's. Not tested: Podman sockets.

When to suppress

  • The service is the daemon-management tool you trust (Portainer, Watchtower) and you've accepted the blast radius. Suppress with a reason: naming the tool and the user/network boundary that contains it.

What it detects

Two shapes, both mode-independent:

  1. A mount naming a control socket — docker.sock, containerd.sock, crio.sock, or podman.sock, including read-only mounts (:ro) and rootless variants ($XDG_RUNTIME_DIR/docker.sock). Detection is substring-based, so atypical paths (e.g. a named volume literally called docker.sock) can produce false positives; suppress with a reason: if so.
  2. A mount of a directory that contains one — /run, /var/run, /run/containerd, /run/systemd, or any directory above them such as /var or the whole root /. This was the rule's blind spot: mounting /run hands over both daemon sockets without naming either, and it used to be reported as a generic sensitive-path finding one tier down (or, before #513, not at all). A whole-root mount is included in either mode — a read-only / still exposes the socket, and used to be under-graded to CL-0013's HIGH because CL-0025 (writable only) declined it.

The direction matters. A sibling under /run that holds no socket — /run/myapp, /run/user/1000, /run/dbus — is not flagged, because mounting it exposes no control channel. /run/systemd/private is flagged by name, since it is a socket that does not end in .sock.

containerd.sock is core Docker coverage rather than multi-engine support: Docker Engine is containerd since 18.09, so a stock Docker host always runs it — and it is a lower-level API with no authorization-plugin layer above it. podman.sock and crio.sock belong to other ecosystems but stay flagged, because this rule is about what a compose file exposes into a container, not about which engine started it (ADR-020).

/run/systemd deserves its own mention: a container can connect to /run/systemd/private and authenticate to it at default capabilities, then drive StartTransientUnit — command execution on the host, without going through Docker at all.

A socket can also reach a container through a named volume that is a bind mount under another name — driver_opts: {type: none, device: /var/run, o: bind} under the local driver. That is detected by the shape the kernel acts on (type: none plus an absolute device), not by the o: string being exactly bind, so the whole bind family counts: o: rbind is a recursive bind of the same host path, and matching the token literally let it through. A driver_opts naming something that is not a host path — type: nfs, type: tmpfs — is not claimed as a bind.

A socket can also arrive as a secrets: or configs: file. Outside swarm, secrets: dsock: file: /var/run/docker.sock is a read-only bind mount of that host file at /run/secrets/dsock — the same mount volumes: would make, under another key. Measured on Docker 29.7.2 / Compose 5.4.0: the container saw the host inode, and docker -H unix:///run/secrets/dsock version was answered by the daemon. Read-only changes nothing here, as above. The rule reads both channels for a service that references the entry (short list or long source:); a project-relative file: ./secrets/… — the pattern CL-0020 recommends — is not a host path and is not graded, nor is an external: true or environment:-sourced entry.

The Compose key use_api_socket: true mounts this same socket, read-write, without a volumes: entry, and copies the registry logins of the user running the stack into the container beside it. That is not a spelling of this rule's grant but a bundle of two, so it has its own rule, CL-0031; a service that sets the key and also mounts the socket here carries both.

A mount can also be inherited through volumes_from:, which mounts every volume of the named service, bind mounts included. No rule reads that key, so a service that inherits the socket from a neighbour gets no finding of its own. That is a demand decision, not a judgement that the inheritance is safe: every corpus service that inherits a socket this way also mounts the socket under its own volumes: and is already flagged here, so a finding on the inheritance would ask for a fix the author is already being given (Triage for a newly found gap in ASSURANCE.md). The count, the volumes_from: container:<name> form that names a container outside the file and cannot be resolved, and the open question of whether to report on the inheriting or the source service are in #1076; it is recounted at each corpus refresh. The same applies to a sensitive or root-equivalent host path (CL-0013, CL-0025) or a shared propagation flag (CL-0017) reached through volumes_from.

Why it matters

Mounting the Docker socket gives a container full root-level access to the host's Docker daemon. A compromised container can:

  • Create new privileged containers
  • Access data from all other containers
  • Escape to the host entirely

Read-only mounts (:ro) do not mitigate this — :ro only affects the inode permissions on the socket file. The Docker API is read-write over any open connection regardless of the mount flag, and docker run --privileged is a single API call.

Rootless Docker and Podman sockets are slightly less catastrophic — escape lands you as the unprivileged daemon user, not host root (measured for rootless Docker; see Tested on in Fix) — but they still grant full container-management privilege over every container that user controls. Treat them as the same severity unless you've verified the threat model.

ATT&CK coverage

Remediating this finding contributes to mitigating the following MITRE ATT&CK techniques (pinned to ATT&CK v18). compose-lint is a static analyser, so this is mitigation coverage — it detects nothing at runtime.

Technique Tactic
T1610 Deploy Container Execution
T1609 Container Administration Command Execution
T1611 Escape to Host Privilege Escalation
T1612 Build Image on Host Stealth
T1552.007 Unsecured Credentials: Container API Credential Access
T1613 Container and Resource Discovery Discovery

See also

  • Real-world examples — four deployed stacks that trip this rule and the four different correct answers: delete the service, re-architect so the socket isn't needed, constrain it behind a GET-only proxy, or suppress it with the residual risk written down
  • CL-0031 — use_api_socket: true, the Compose key that mounts this socket and copies the deploying user's registry logins in beside it; its own rule because the second grant is not a socket mount
  • CL-0024 — cap_add: [ALL], functionally similar in blast radius
  • CL-0025 — writable root-equivalent host mounts, the other no-technique route to host root
  • CL-0013 — sensitive host paths that are not control sockets
  • Hardening guide, step 9 — where this rule fits when hardening a whole file

Severity derivation

Derivation (see severity model):

  • Baseline: A — the attacker already has code execution in this container, as the workload uid
  • Precondition: Direct — talking to the daemon over the socket is a supported API call; no technique and no second defect
  • Impact: Host — the daemon API creates privileged containers, so it is host control
  • Qualifier/modifier: none — :ro does not earn the read-only qualifier, because the flag applies to the socket file, not to the read-write API behind it
  • Derived: Direct × Host = CRITICAL
  • Shipped: CRITICAL
  • Scoping assumptions: scored for a service that runs as root, which a service does unless the file or its image says otherwise, or as any uid given the socket's group. The socket keeps its host ownership and mode inside the container (mode 660, root:docker at Docker's defaults), so a non-root uid outside that group is refused. The rule fires on it all the same: user: is a sibling key and an image's uid is not in the file, and a score does not branch on either (no context sensitivity)
  • Evidence: _cl0001 and _cl0001_ro_socket in scripts/validate_rule_premises.py — a :ro-mounted socket answered HTTP/1.1 200 OK on the daemon API, so the mount flag narrows nothing. _cl0001_nonroot_socket backs the scoping assumption: uid 65534 was refused on the mounted socket and answered 200 OK once the socket's group was added

References: - OWASP Docker Security Rule #1 - CIS Docker Benchmark 5.32 — Ensure that the Docker socket is not mounted inside any containers

A reference means the rule relates to that source. It does not mean a file with no finding complies with it. The CIS, OWASP and ATT&CK mapping for every rule, and the tags SARIF output carries for it, are on Standards mapping.