Skip to content

Docker audit fix · Volume Permissions

How to Find and Secure World-Writable Docker Volumes

A volume's _data directory under /var/lib/docker/volumes is world-writable when its mode carries the o+w bit, letting any local account plant files a container will read or execute. Fix the ownership with chown, then clear the bit with chmod o-w.

Hiren KalariyaHiren KalariyaLast reviewed world-writable-volumes
CtrlOpsWorld-Writable VolumesMEDIUM

What did your audit say?

FAIL · when the audit printed

One or more _data dirs are o+w

At least one volume's data directory can be written by any local account, or by another container sharing that UID space. Up to three paths are named.

Severity
Medium
Needs root or sudo
Yes
Results it can return
FAIL · SKIP · PASS
Check in this audit
3 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.

Run through as_root, the check executes find /var/lib/docker/volumes -mindepth 2 -maxdepth 2 -type d -perm -0002 and counts the directories it returns. Pinning both -mindepth and -maxdepth to 2 holds the scan to exactly one level, each volume's own _data directory, and -perm -0002 is the test for the world-write bit. A single match is enough for a FAIL, which quotes the first three paths; no match at all is the PASS. The result list is capped with head -10 before it is counted, so on a badly affected host the reported number is a floor rather than a total.

Needs root or sudo - without it the check SKIPs before doing anything - and needs /var/lib/docker/volumes to exist. A host using a custom data-root, a rootless daemon (volumes live under ~/.local/share/docker), or no Docker at all therefore SKIPs, which is not a pass. The scan is narrow by design: -mindepth 2 -maxdepth 2 -type d -perm -0002 matches each volume's _data directory itself, not the files inside it, and at most 10 are reported. A volume whose _data is correctly 755 but full of world-writable files passes.

What each result means
ResultWhenWhat it means
SKIPNo root, or /var/lib/docker/volumes absent (different data-root, rootless, or no Docker)Nothing was verified. No directory was scanned, so world-writable volume data may exist and go unreported.
PASSNone world-writableNo volume's _data directory carries the world-write bit. The files inside those directories were not examined.
FAILOne or more _data dirs are o+wAt least one volume's data directory can be written by any local account, or by another container sharing that UID space. Up to three paths are named.

Volume data lives on the host filesystem. A world-writable _data lets any local user (or a different container with the same UID space) plant or modify files that another container will execute or trust. Least privilege on data directories; CIS Docker 1.2.x host configuration and 5.x volume guidance.

  • Images that chmod 777 their data dir in the Dockerfile (VOLUME + chmod 1777), or operators who ran chmod -R 777 to "fix permissions" instead of chowning to the container UID.
  • Only the volume root directory is checked, not files beneath it.
  • On a default install /var/lib/docker is 710 root:root, which keeps non-root local accounts away from every volume, so host-side exposure also needs that parent loosened (a chmod -R over /var/lib/docker does both at once). Cross-container and in-container escalation apply either way.
  • Custom data-root in daemon.json → SKIP. Adjust the path.
  1. Find the container and the UID it writes as

    The directory name under volumes/ is the volume name. docker top shows the UID the container's process really runs as, which matters for images that start as root and drop privileges in their entrypoint.

    sh
    docker volume inspect <vol> --format '{{.Mountpoint}}'docker ps -a --filter volume=<vol> --format '{{.Names}}'docker top <container> -eo uid,gid,comm

  2. Give the data directory to that UID

    sh
    sudo chown -R <uid>:<gid> /var/lib/docker/volumes/<vol>/_data

  3. Clear the world-write bit

    sh
    sudo chmod o-w /var/lib/docker/volumes/<vol>/_datadocker restart <container>docker logs --tail 50 <container>

    A "Permission denied" in the logs means the UID from the first step was not the one writing; check it again rather than putting the bit back.

  4. Remove the cause

    Delete the chmod 777 or chmod -R 777 from the Dockerfile, entrypoint or deploy script. Set ownership in the image instead, with COPY --chown or RUN chown on the directory before its VOLUME line: a new named volume copies that directory's owner and mode the first time it is mounted.

sh
# Reproduce the check:sudo find /var/lib/docker/volumes -mindepth 2 -maxdepth 2 -type d -perm -0002# expected: no output# Go one level deeper than the check does, into the contents:sudo find /var/lib/docker/volumes -xdev -perm -0002 ! -type l | head -20# Confirm where volumes actually live on this host:docker info --format '{{.DockerRootDir}}'

Debugging

  • Re-run the audit as root or with sudo; there is no unprivileged fallback. Membership of the docker group is not enough here: it reaches the daemon, not this directory.
  • Check docker info --format '{{.DockerRootDir}}'. A custom data-root in daemon.json, a rootless daemon storing volumes under $HOME/.local/share/docker, or userns-remap (volumes under /var/lib/docker/<uid>.<gid>/volumes) puts them somewhere this check never looks. Run the find above against the real path.
  • Map the volume name to its users: docker volume ls, then docker ps -a --filter volume=<name>. The directory name under volumes/ is the volume name.
  • The container was relying on world-write because its process UID does not own the data. Fix it properly with ownership: sudo chown -R <uid>:<gid> /var/lib/docker/volumes/<name>/_data, matching the UID the container's process runs as. docker top <name> -eo uid,gid,comm shows it; docker inspect -f '{{.Config.User}}' is empty for images that start as root and drop privileges in their entrypoint, such as postgres and redis.
  • Only the _data directory itself is tested, not its contents. Use the deeper find above.
  • Safe for ownership and permissions, but do not add or remove files there by hand; use docker run --rm -v <name>:/mnt alpine … so the daemon's view stays consistent.

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