Skip to content

Docker audit fix · Volume Permissions

How to Restrict Sensitive Host Path Mounts in Docker

A bind mount hands a container live access to a host directory, so a source of /, /etc, /root, /proc, /sys, /dev, /home, /var/lib/docker or docker.sock effectively gives it the host. Bind only the specific file or directory the workload needs.

Hiren KalariyaHiren KalariyaLast reviewed sensitive-host-path-mounts
CtrlOpsSensitive Host Path MountsHIGH

What did your audit say?

FAIL · when the audit printed

Any sensitive source mounted

At least one container has a bind mount of a host path that hands over the host, and the message names the container, source and destination for each hit.

Severity
High
Needs root or sudo
Yes
Results it can return
FAIL · SKIP · PASS
Check in this audit
1 of 7

Every threshold on this page is transcribed from the docker-security-volume-permissions audit script that CtrlOps runs, and a build check fails if the two ever disagree. See all 7 Volume Permissions checks, or how the audit runs.

For every container docker ps -a returns, running or not, the check inspects .Mounts, keeps only the entries whose Type is bind, and tests each one's source path against a single fixed regular expression. That pattern matches / exactly, and /etc, /root, /boot, /proc, /sys, /dev, /var/lib/docker or /home either on their own or with a trailing subpath, plus the daemon socket at /var/run/docker.sock or /run/docker.sock. One matching source anywhere on the host is enough to fail the check, and every hit is reported as container:src->dst; no match on any container is the PASS. The mount's read-only flag is never read, so a :ro bind of /etc still counts as a hit.

Needs the docker binary and daemon access; otherwise SKIP. Unlike the Container Hardening checks, this one iterates docker ps -a - every container, running or not - so a stopped container with a dangerous mount is still reported. It examines only Type == "bind" mounts, so a named volume that happens to hold sensitive data is not matched. The source path is tested against a fixed list: / exactly, /etc, /root, /boot, /proc, /sys, /dev, /var/lib/docker, /home, and the docker socket under either /var/run or /run. Sensitive paths outside that list (/srv, /opt/secrets, /var/lib/mysql) are not flagged, and the mount's read-only flag is deliberately ignored - read access to /etc or /root is itself the finding.

What each result means
ResultWhenWhat it means
SKIPDocker missing / daemon unreachableNothing was verified. No container was inspected, so a dangerous bind mount could be present and unseen.
FAILAny sensitive source mountedAt least one container has a bind mount of a host path that hands over the host, and the message names the container, source and destination for each hit.
PASSNoneNo container binds any path on the fixed sensitive list. Sources outside that list, and named volumes of any kind, were never assessed.

A bind mount is a hole in the container boundary. / or /etc lets a compromised container rewrite passwd, sudoers, cron, or SSH keys; /dev exposes block devices; /proc and /sys expose kernel tunables and /proc/sysrq-trigger; /var/lib/docker exposes every other container's layers and volumes; /home exposes user files and SSH keys. CIS Docker 5.5 "Ensure sensitive host system directories are not mounted on containers"; OWASP Docker Cheat Sheet Rule #1 and Rule #8; NIST SP 800-190 4.4.4.

  • Developer bind mounts under /home/<user>/project are extremely common and match ^/home($|/). On a production VPS that is usually a deployment smell (code should be baked into the image or live in /srv//opt), but for dev hosts it is a loud false positive. On a server, moving the project to /srv or /opt, or building it into the image, clears it; on a dev host, record it as an exception.
  • Monitoring agents (node-exporter, cAdvisor, Datadog, Netdata) mount /proc, /sys, / read-only by design. Read-only reduces but does not remove risk (/proc still leaks host process info). Keep them :ro, drop capabilities, and document.
  • Certificate mounts like /etc/letsencrypt:/certs:ro and /etc/localtime:/etc/localtime:ro match /etc, and so does every path beneath it. Narrowing the bind to one file under /etc reduces the risk but does not clear the finding; copying the file to a path outside the list does. /etc/localtime is harmless but still reported.
  • Named volumes (Type == volume) are never flagged.
  • Stopped containers count; remove stale ones (docker container prune) to clear findings.
  1. List every bind mount

    Stopped containers count too, so list them all.

    sh
    docker inspect -f '{{.Name}}{{range .Mounts}}{{if eq .Type "bind"}} {{.Source}}->{{.Destination}}{{end}}{{end}}' $(docker ps -aq)

  2. Move data and code off the host paths

    Data belongs in a named volume, which this check never flags; code belongs in the image. A project that has to stay on the host lives under /srv or /opt, not /home.

    yaml
    services:  app:    volumes:      - appdata:/var/lib/appvolumes:  appdata:

  3. Copy the files a container needs out of the listed paths

    The pattern matches every path under /etc, so a bind of /etc/ssl/certs/ca.pem is still reported. Copy the file to a directory outside the list and bind that instead. For Let's Encrypt certificates, a certbot deploy hook keeps the copy current on every renewal:

    sh
    sudo install -d -m 750 /srv/app/certssudo tee /etc/letsencrypt/renewal-hooks/deploy/copy-to-app.sh >/dev/null <<'EOF'#!/bin/shcp -L "$RENEWED_LINEAGE/fullchain.pem" "$RENEWED_LINEAGE/privkey.pem" /srv/app/certs/EOFsudo chmod +x /etc/letsencrypt/renewal-hooks/deploy/copy-to-app.sh

    Run the cp once by hand for the first copy. For the time zone, set TZ=Europe/Berlin (or your zone) in the container's environment instead of mounting /etc/localtime.

  4. Keep only documented read-only exceptions

    A monitoring agent or a socket proxy may genuinely need one of these paths. Mount it read-only and as narrowly as the tool allows (/proc rather than /), run it non-root with --cap-drop ALL, and record the exception: the check has no allow-list and ignores the read-only flag, so the finding stays.

  5. Recreate and clean up

    Mounts are fixed when a container is created, and a stopped container still counts.

    sh
    docker compose up -d --force-recreatedocker rm <old-container>     # or: docker container prune

sh
# Every bind mount on every container, with its read-only flag:docker inspect -f '{{.Name}}{{range .Mounts}}{{if eq .Type "bind"}} {{.Source}}->{{.Destination}}(rw={{.RW}}){{end}}{{end}}' $(docker ps -aq)# expected: no source under /, /etc, /root, /boot, /proc, /sys, /dev, /var/lib/docker, /home, or docker.sock# Check the definitions too, so the finding does not come back on the next deploy:grep -rn -E 'volumes:|/etc|/root|docker.sock' docker-compose.yml compose.yaml 2>/dev/null# Confirm what a container can actually reach:docker exec <name> ls -la /host-etc 2>/dev/null

Debugging

  • The check printed one of two messages. "Docker not installed" means command -v docker found nothing on the audit account's PATH. "Cannot query Docker daemon" means a plain docker ps failed 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 the docker group. 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, and an empty list has no sensitive mounts in it, so the result is PASS. On a host where Docker may be down, run sudo docker ps -a before trusting that PASS.
  • Expected, and worth fixing rather than ignoring: the mount takes effect the moment someone starts it. docker rm it if it is obsolete.
  • cAdvisor, node-exporter, Datadog and similar genuinely mount /proc, /sys and sometimes /. Mount them read-only, scope them as narrowly as the agent allows (/proc rather than /), keep the container non-root, and record the exception. The check has no allow-list, so the finding will persist.
  • A very common and low-risk pattern that the ^/etc($|/) pattern still matches. Confirm the exact source from the message; a read-only single-file mount of /etc/localtime is a false positive worth recording. Setting the TZ environment variable instead removes the mount entirely.
  • The path is outside the fixed list, or it is a named volume rather than a bind mount. Review the full mount list with the first command above, not just the flagged ones.
  • Deliberate overlap: this check finds it on any container, the Docker Socket In Containers check looks at running ones, and Writable Volume Mounts escalates when it is writable. Remove the mount and all three clear. A socket proxy still mounts the real socket read-only, so it stays in this check's FAIL; record it as the accepted exception.

Sources

Next

Re-run the Volume Permissions audit after applying the fix and confirm this check moves to PASS. CtrlOps runs all 7 checks over your existing SSH connection and scores the result, so the change is visible without reading another config file.

Download for MacDownload for WindowsAll 7 Volume Permissions fixes

14-day free trial, no credit card required.

Explore article with AI tools

Written by

Hiren Kalariya

Co-Founder & CEO, TST Technology

Hiren Kalariya is the Co-Founder and CEO of TST Technology and the product lead behind CtrlOps, a local-first desktop app that makes Linux server management fast and easy for developers and DevOps teams. Over the past five years he has shipped 60+ production systems, and he still tests every tool he writes about on real servers.

Stop juggling tools. Start managing fleets.

PuTTY
Termius
MobaXterm
WinSCP
SecureCRT
Royal TS
Warp
CtrlOps14 tools left
Webmin
aaPanel
RunCloud
Dokploy
IP spreadsheet
bash (2)
sticky notes

One app. All your servers. No context switching. Free to start, free to leave.

Start instantly · No credit card · Cancel anytime

Your privacy preferences. We use product analytics to improve CtrlOps. Google Analytics cookies and live chat stay off until you allow them. Cookie policy