CCyberwiki

Docker socket exposure

Docker socket exposure
ClassAccess control
Also known asExposed Docker daemon, mounted docker.sock
CWECWE-250: Execution with Unnecessary Privileges
OWASP Top 10A02:2025 Security Misconfiguration
Typical severityCritical
AffectsLinux servers that run Docker Engine: Compose services that mount /var/run/docker.sock, daemons listening on TCP port 2375, and accounts in the docker group

The Docker daemon runs as root. Anyone who can send it commands can start a container with the host's whole file system attached and so become root on the host.12 Docker socket exposure is the misconfiguration that hands that power to a container, a network client or a user account that should not control the server.

Description

Docker Engine consists of a background service, the daemon, and the docker command, which sends it requests over a REST API. By default the daemon listens on the unix socket /var/run/docker.sock, which is owned by root; other users reach it through sudo or by membership of the docker group.34 The daemon itself always runs as root unless Docker is installed in rootless mode.2

The API has no finer permissions of its own. Its built-in authorization model is "all or nothing": any caller that can reach the daemon can run any command.5 Access to the socket, a TCP listener or the docker group is therefore access to everything the daemon can do; membership of the group "grants root-level privileges to the user".3 A tool that only needs to list containers ends up running with far more privilege than its job requires.6

Three configurations expose the API. A Compose file or docker run command bind-mounts the socket into a container so that the service inside can manage other containers. The daemon is started with -H tcp://0.0.0.0:2375 for remote management; by convention port 2375 carries unencrypted traffic and 2376 carries TLS, and a plain TCP socket has no encryption or authentication by default.4 Or an account that runs untrusted code is added to the docker group. All three are configuration choices, which places the problem under security misconfiguration.7 A host firewall leaves a gap in the TCP case, since a TCP endpoint closed to other hosts can still be reached from containers on the same machine.2

Mechanism

A monitoring service in a Compose file is given the socket so that it can list containers:

services:
  monitor:
    image: example/monitor
    volumes:
      - "/var/run/docker.sock:/var/run/docker.sock"

An attacker who finds a flaw in that service, such as Command injection, can run code inside its container. The code connects to the socket and asks the daemon to create a new container whose configuration binds the host's root directory into it. In the campaign Datadog documented in 2024, the request body contained:8

{
  "Image": "alpine",
  "HostConfig": {
    "Binds": ["/:/mnt"]
  }
}

The daemon, running as root, starts the container as asked. Inside it, /mnt is the host's file system with full write access, and a chroot /mnt makes every later command act on the host directly. A container started with the host's / as a shared directory "can alter your host filesystem without any restriction", in the words of Docker's security documentation.2 The attack has two recorded steps, deploying a container through the API and escaping from it to the host, and a mounted docker.sock is a known route for the second.910

Adding the :ro flag to the mount changes nothing here. A process that can connect to a read-only socket can still send requests that change containers or the host.1

Impact

Control of the daemon gives the attacker root on the host. From there they can read the environment variables and volumes of every container on the server, including database passwords and API keys, change or delete application data, and add cron jobs or SSH keys that survive a restart. Through one flawed service that holds the socket, the attacker reaches every application on the server.10

Notable incidents

In 2024 Datadog Security Labs described a campaign that scanned the internet for hosts with port 2375 open and no authentication. After a docker version request confirmed that the API answered, the attackers started an Alpine container with the host's root directory bound to /mnt, used chroot to write a downloader to /usr/bin/vurl, and added entries to /etc/crontab and /etc/cron.d/zzh that fetched further payloads. The goal was Cryptojacking malware. Datadog linked the campaign to Spinning YARN, which Cado Security had reported in March 2024.8

Detection

Search Compose files, docker run commands and CI configuration for docker.sock. On the server, the volume filter of docker ps lists running containers that have a volume or bind mount at a given path:11

docker ps --filter volume=/var/run/docker.sock --format "table {{.ID}}\t{{.Names}}\t{{.Mounts}}"

Check the daemon's start options for an -H tcp:// address, and test from another machine whether ports 2375 and 2376 answer. Review which accounts belong to the docker group and treat each one as an administrator.

Prevention

Remove the socket mount from every container that does not need to manage other containers, and leave the TCP socket switched off.1 When a tool requires the socket, run it as a deliberate administrative component and keep the application code that faces the internet in other containers.

Keep the daemon on its default Unix socket and allow no unauthenticated access to the API.9 For remote management, Docker supports SSH and TLS.12 An SSH context sends the API traffic through an SSH login:

docker context create \
  --docker host=ssh://docker-user@host1.example.com \
  --description="Remote engine" \
  my-remote-engine

With TLS, the daemon is started with tlsverify and a CA certificate, and it accepts only clients holding a certificate signed by that CA.12

Rootless mode runs the daemon and its containers as a non-root user inside a user namespace, to contain flaws in the daemon and the container runtime.13 Authorization plugins can restrict which API requests a caller may send.5 Leave accounts out of the docker group unless they are meant to have root, in line with the principle of least privilege.

Prompt for a coding agent

Search this project for every place that gives a container or a process access to the Docker daemon: volumes or bind mounts of /var/run/docker.sock in docker-compose files, docker run commands, Kubernetes manifests and CI configuration, and any DOCKER_HOST or dockerd setting that uses tcp://. For each one, explain what the service uses the Docker API for. Remove the mount where the service does not need it. Where it does, say so and suggest running that tool as a separate administrative container with nothing exposed to the internet. Do not rely on a read-only (:ro) mount as a fix. List every file and line you changed.

In SecFlash

SecFlash reports a container that can reach the Docker socket as SF-SRV-402 and accounts in the docker group as SF-SRV-304, both on the Server page. A Compose service that mounts the socket is reported as SF-CLD-907 on the Cloud page. A Docker API port that answers from the internet is reported as SF-SRV-101 on the Server page.

See also

References

  1. a b c OWASP (n.d.). "Docker Security Cheat Sheet". OWASP Cheat Sheet Series.
  2. a b c d Docker (n.d.). "Docker Engine security". Docker Docs.
  3. a b Docker (n.d.). "Linux post-installation steps for Docker Engine". Docker Docs.
  4. a b Docker (n.d.). "dockerd". Docker Docs, CLI reference.
  5. a b Docker (n.d.). "Access authorization plugin". Docker Docs.
  6. back "CWE-250: Execution with Unnecessary Privileges". Common Weakness Enumeration. MITRE.
  7. back "A02:2025 Security Misconfiguration". OWASP Top 10:2025. OWASP Foundation.
  8. a b Muir, M. (2024). "Attackers deploying new tactics in campaign targeting exposed Docker APIs". Datadog Security Labs.
  9. a b "Deploy Container, Technique T1610". MITRE ATT&CK.
  10. a b "Escape to Host, Technique T1611". MITRE ATT&CK.
  11. back Docker (n.d.). "docker container ls". Docker Docs, CLI reference.
  12. a b Docker (n.d.). "Protect the Docker daemon socket". Docker Docs.
  13. back Docker (n.d.). "Rootless mode". Docker Docs.