PC-019CRITICALDocker & Infrastructure

Privileged Container or Mounted /var/run/docker.sock

Catches Docker Compose and Kubernetes manifests enabling privileged: true or bind-mounting /var/run/docker.sock, which grants instant root-equivalent host escape.

Rule Slug
docker-privileged-mode-or-docker-sock
Affected Files
docker-compose*.yml, docker-compose*.yaml, compose*.yml, compose*.yaml, *.yml, *.yaml, Dockerfile*
Detection Method
Deterministic Regex
Live Rule Tester100% Browser-Local
CRITICAL: Detected 2 violations
Line 5:privileged: true
Line 7:/var/run/docker.sock

Vulnerable Pattern vs. Hardened Fix

Vulnerable Pattern
# docker-compose.yml
services:
  web-worker:
    image: myapp:latest
    privileged: true # CRITICAL: Full host kernel capabilities
    volumes:
      - /var/run/docker.sock:/var/run/docker.sock # CRITICAL: Root host escape
Recommended Fix
# docker-compose.yml
services:
  web-worker:
    image: myapp:latest
    user: "1000:1000"
    read_only: true
    cap_drop:
      - ALL
    security_opt:
      - no-new-privileges:true

Why This Fails in Production

Container isolation depends on Linux namespaces, cgroups, seccomp profiles, and dropped kernel capabilities to prevent a compromised web application from escaping onto the underlying host OS. Setting privileged: true disables virtually all of these kernel boundaries at once, granting the container full Linux capabilities (CAP_SYS_ADMIN, CAP_NET_ADMIN, etc.), disabling AppArmor and seccomp confinement, and exposing every host block device inside /dev.

Mounting the host Docker daemon socket (/var/run/docker.sock) into a container is functionally identical to handing that container unrestricted passwordless root access to the host server. Even if the container runs as a non-root user or mounts docker.sock with :ro (read-only mount flags do NOT restrict Unix socket writes), any process that compromises the container can send a single HTTP request over the Unix socket to launch a new container mounting the host root filesystem (/) and instantly write an SSH key to /root/.ssh/authorized_keys.

Developers frequently add privileged: true while troubleshooting permission errors or mount /var/run/docker.sock for reverse proxies (Traefik), log shippers, or CI runners, then reuse that template for public-facing services. If an attacker exploits any application bug (such as an RCE, SSRF, or vulnerable dependency) inside such a container, the blast radius escalates immediately from a single isolated container to total host takeover, compromising every sibling container, secret volume, and TLS key on the machine.

Always remove privileged: true in favor of adding only the exact minimal Linux capability needed via cap_add after cap_drop: [ALL], and if an infrastructure service genuinely requires Docker API metadata, isolate it behind a hardened read-only Docker socket proxy.

Remediation Steps

  1. 1Remove privileged: true immediately; use cap_drop: [ALL] and grant only specific, minimal capabilities via cap_add if required.
  2. 2Remove /var/run/docker.sock bind mounts from all application containers.
  3. 3For reverse proxies or monitoring agents that legitimately need container discovery, deploy a dedicated socket-proxy container (e.g., tecnativa/docker-socket-proxy) allowing only read-only GET /containers and /events endpoints.
  4. 4Run containers as an explicit non-root UID/GID with read_only: true and security_opt: [no-new-privileges:true].
OpsCheck: Audit Container Security & Healthchecks

Inspect Docker Compose privilege and restart policies on OpsCheck.

Open OpsCheck ↗

Frequently Asked Questions

Does mounting /var/run/docker.sock:ro make it safe?
No! The :ro flag only prevents deleting or renaming the socket inode itself; it does NOT block connecting to the Unix socket and issuing POST /containers/create API commands to spawn a root container on the host.
How should Traefik or Portainer read container labels safely?
Place a minimal socket proxy (such as docker-socket-proxy) on an internal-only Docker network with CONTAINERS=1 and POST=0, and connect Traefik to the proxy over TCP instead of mounting docker.sock directly into an internet-facing container.
What is the safest alternative to privileged: true when a container needs a special kernel feature?
Drop all capabilities with cap_drop: [ALL] and add only the single capability needed (for example, NET_BIND_SERVICE for binding port 80) alongside no-new-privileges:true.

Related Docker & Infrastructure Rules

Scan local project folder →