Docker Socket Mounted Into a Container
A container has the Docker daemon's socket mounted, which lets anyone in the container control Docker on the host and so gain root on it.
| Severity | High |
| CVSS 3.1 | 8.8 CVSS:3.1/AV:L/AC:L/PR:L/UI:N/S:C/C:H/I:H/A:H Open in the calculator |
| CVSS 4.0 | 9.3 CVSS:4.0/AV:L/AC:L/AT:N/PR:L/UI:N/VC:H/VI:H/VA:H/SC:H/SI:H/SA:H Open in the calculator |
| CWE | CWE-250: Execution with Unnecessary Privileges |
| MITRE ATT&CK | T1610 Deploy Container, T1611 Escape to Host |
| Category | Security Misconfiguration |
Description
The Docker daemon is controlled through a Unix socket, normally /var/run/docker.sock, which offers the full Docker Engine API to any process that can connect to it. Through the API, a client can create and start containers with any settings, including privileged containers that mount the host's root filesystem. Mounting this socket into a container, with -v /var/run/docker.sock:/var/run/docker.sock or a hostPath volume, therefore gives that container control of the host: an attacker who gains code execution in the container, or can influence the requests it sends to Docker, can use the socket to gain root on the host.
From there they can read the data and secrets of every other container, tamper with images and workloads, and use the host's own credentials to move further into the environment; on a Kubernetes node, this means the compromise of the node and every pod scheduled on it. Mounting the socket read-only does not help, because the API remains reachable through it. The same applies to the sockets of other container runtimes, such as containerd's /run/containerd/containerd.sock and CRI-O's /var/run/crio/crio.sock, and to mounts of a parent directory that contains them.
The mount is common in CI/CD runners, monitoring agents, reverse proxies that discover containers, and container management tools. It can be found in pod specifications and Compose files, or from inside a container by locating the socket and querying it, for example with curl --unix-socket /var/run/docker.sock http://localhost/version.
Remediation
- Remove the socket mount from every container that does not strictly need it; most applications never need to talk to the container runtime.
- For CI/CD builds, use an image builder that does not need the host's daemon, such as a rootless or daemonless builder, or run builds on dedicated hosts that hold nothing else of value.
- Where a tool only needs information about containers, give it a narrower interface, such as the Kubernetes API with a read-only role, or a filtering proxy in front of the socket that allows only the specific API calls it needs.
- Where Docker is used directly, consider rootless mode, so that control of the daemon does not mean root on the host.
- Prevent new mounts of runtime sockets with the Baseline Pod Security Standard, which forbids hostPath volumes, or with a policy engine rule.
As an interim measure, restrict the affected workloads to dedicated nodes and limit who can deploy them or execute commands in them. Confirm the fix by searching pod specifications and Compose files for docker.sock, containerd.sock and crio.sock, and checking that no running container has them mounted.
References
Add This Finding to Your Library
In Pental this write-up is in Settings, Library. Add to my library copies it into your own, rated in your firm's CVSS version, ready to put in your own words.
Free trialYour trial starts when your portal goes live, not when you sign up, so the time you spend setting up does not count. · No card required
Only need the reporting? Our reporting tool is free and open source, with the same library.