For every container docker ps -a returns, the check inspects each entry in .Mounts - bind mounts, named volumes and tmpfs alike - and reads its Source and its RW flag. A mount with RW set to true increments the read-write counter and anything else increments the read-only counter, and both numbers end up in the message. The only condition that produces a finding is a read-write mount whose source is /var/run/docker.sock or /run/docker.sock, which FAILs and names each container. Every other combination is a PASS, including a host where all mounts are writable, so the counts carry more information than the status does.
Needs the docker binary and daemon access; otherwise SKIP. It iterates all containers (docker ps -a) and every mount type - bind mounts, named volumes and tmpfs alike - counting how many are read-write versus read-only. Only one condition produces a finding: the docker socket mounted read-write. Everything else is reported as a PASS carrying the counts, so a host where every mount is writable still passes with an advisory message. Read the counts, not just the status. Note that a read-only docker.sock mount is not a FAIL here - it is still a full host compromise, and is caught by the Docker Socket In Containers check instead.
| Result | When | What it means |
|---|---|---|
| SKIP | Docker not installed, or daemon unreachable | Nothing was verified. No mount was counted, so a read-write docker.sock could be present and unreported. |
| FAIL | docker.sock mounted read-write | A container has the Docker daemon socket mounted read-write, which is equivalent to root on the host. The message names each container. |
| PASS | No mounts at all | No container on this host mounts anything, so there is no writable host path to review. |
| PASS | Counts of RW and RO mounts (informational) | The socket is not mounted read-write, but this is an inventory rather than an all-clear: read the read-write count and add :ro wherever a container does not need to write. |
Same root cause as Docker Socket In Containers (daemon-socket script). This check adds the RW/RO inventory as a nudge toward read-only mounts (CIS Docker 5.12 spirit, OWASP Rule #8).
- A read-only socket mount (
:ro) does not prevent API calls (the client connects to the socket; it does not write the inode), so a PASS here with a:rosocket is still dangerous; the Docker Socket In Containers check catches both on running containers. /etc/hostsand/etc/resolv.conf, which Docker mounts into every container, are not in.Mountsand are not counted. The anonymous volumes Docker creates for an image'sVOLUMEdirectives are, and they are read-write.
List every mount and its RW flag
sh docker inspect -f '{{.Name}}{{range .Mounts}} {{.Source}}->{{.Destination}}(rw={{.RW}}){{end}}' $(docker ps -aq)Remove the docker.sock mount
Delete the
docker.sockline from the service and recreate it. If a tool genuinely needs the Docker API, put a filtering socket proxy in front of it, as the Docker Socket In Containers fix shows. Changing the mount to:roclears this check's FAIL but leaves the container in control of the host.Add :ro to mounts the container only reads
Config, certificates and static files rarely need write access.
sh docker run -v /srv/app/config:/etc/app:ro ...docker run --mount type=bind,src=/srv/app/config,dst=/etc/app,readonly ...In Compose:
yaml services: app: volumes: - ./config:/etc/app:ro - type: volume source: static target: /usr/share/nginx/html read_only: trueRecreate the containers
Mount options are fixed when a container is created.
sh docker compose up -d --force-recreate
# Every mount with its RW flag:docker inspect -f '{{.Name}}{{range .Mounts}} {{.Source}}->{{.Destination}}(rw={{.RW}}){{end}}' $(docker ps -aq)# expected: no docker.sock at all, and rw=false wherever the container does not need to write# Count them the way the check does:docker inspect -f '{{range .Mounts}}{{.RW}}{{println}}{{end}}' $(docker ps -aq) | sort | uniq -c# Prove a read-only mount is enforced:docker exec <name> sh -c 'touch /data/probe' 2>&1 # expected: Read-only file system- The check printed one of two messages. "Docker not installed" means
command -v dockerfound nothing on the audit account'sPATH. "Cannot query Docker daemon" means a plaindocker psfailed for the audit account and there was no root or sudo to retry with: run the audit as root, with sudo, or as a member of thedockergroup. The Docker Inventory check reports whether the daemon itself is reachable. - With root or sudo available, a stopped daemon does not produce a SKIP. The check goes on to
as_root docker ps -a, which fails quietly and returns no containers, so there are no mounts to count and the result is this PASS. On a host where Docker may be down, runsudo docker ps -abefore trusting it. - The check's normal output, not a clean bill of health. Every writable mount is a path a compromised container can modify on the host. Go through the list and append
:rowherever write access is not needed. - The most serious finding in this script: that container can create a privileged container and own the host. Remove the mount, or route the tool through a socket proxy exposing only the endpoints it needs. Changing it to
:rodowngrades this check but does not fix the problem - see the Docker Socket In Containers check. - Mount options are fixed at creation; recreate it (
docker compose up -d --force-recreate) and confirm withdocker inspect. Note also that:roon a named volume still allows another container with a writable mount of the same volume to change the data. - Every mount of every container is counted, including tmpfs and containers that are stopped. Use the first command to see exactly what is being counted.
