Skip to content

Docker audit fix · Volume Permissions

How to Secure File Ownership on Docker Volumes on VPS

Each Docker volume's _data directory is owned by whichever UID wrote to it, and a UID that matches no host user and no container's configured user usually means data left behind by a removed image. Confirm what it holds before deleting it.

Hiren KalariyaHiren KalariyaLast reviewed volume-ownership
CtrlOpsVolume OwnershipMEDIUM

What did your audit say?

WARN · when the audit printed

Volumes owned by a UID nobody uses

At least one volume is owned by a UID that resolves to no host user and no container's configured user, which usually means stale data from a removed image. Confirm each before deleting it.

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

The check first builds an allow-list of UIDs: it reads .Config.User from every container on the host, takes the part before any colon, and keeps only the entries that are purely numeric. Then, for each /var/lib/docker/volumes/*/_data directory, it takes the owning UID with stat -c '%u' run through as_root. A volume is reported only when both conditions hold: the UID resolves to no host account through getent passwd, and it is absent from that container allow-list. Any volume meeting both is a WARN listing volume:uid for up to five of them; no volume meeting both is the PASS.

Needs root or sudo and an existing /var/lib/docker/volumes; otherwise SKIP (a custom data-root or a rootless daemon therefore SKIPs). For each */_data directory it takes the owner UID and reports it only if that UID has no /etc/passwd entry and matches no numeric .Config.User of any container on the host. That second condition is what stops normal image UIDs (postgres 999, nginx 101) from being reported. At most 5 volumes are listed. The finding is about stale data, not permissions - a volume owned by an unknown UID is usually left over from a removed image, which is why it is a WARN and the message says to confirm before deleting.

What each result means
ResultWhenWhat it means
SKIPNo root / directory absentNothing was verified. No volume ownership was read at all.
WARNVolumes owned by a UID nobody usesAt least one volume is owned by a UID that resolves to no host user and no container's configured user, which usually means stale data from a removed image. Confirm each before deleting it.
PASSEvery volume's owner is a host user or a configured container userEvery volume owner resolves to something known on this host, so nothing looks orphaned. This says nothing about the modes on that data.

Data left behind by removed containers/images may hold secrets or backups that nobody audits, and a future account or container that reuses that UID silently inherits it. Housekeeping and least privilege; NIST SP 800-190 4.4.4 (persistent storage).

  • Images that drop privileges inside the entrypoint (postgres runs as UID 999, nginx as 101, redis as 999) have an empty .Config.User, so those UIDs are not in CUIDS. If the host also has no user with that UID, their volumes are flagged as orphans even though they are in active use. This is a common false positive; the message already says "confirm before deleting".
  • A container configured with a user name (USER node, --user www-data) adds nothing to the allow-list, because only purely numeric values are kept. Its volume is reported unless the host also has an account with that UID.
  • A rootless daemon keeps its volumes under ~/.local/share/docker, so this check SKIPs. With userns-remap the daemon stores volumes under /var/lib/docker/<uid>.<gid>/volumes, so the check either SKIPs or reads what is left in /var/lib/docker/volumes from before remapping was turned on, and those leftovers really are unused.
  • Anonymous volumes are handled by the Anonymous/Dangling Volumes check.
  1. Find out whether anything uses the volume

    Any container listed, running or stopped, still references it.

    sh
    docker ps -a --filter volume=<name> --format '{{.Names}}\t{{.Status}}'

  2. If a container uses it, make the UID known

    The data is live, so leave it where it is. Either give the UID a host account with no login, or set the container's user to the numeric UID so it joins the check's allow-list. Both clear the finding. Use the UID the WARN message printed after the volume name; 999 below is an example.

    sh
    sudo useradd --system --no-create-home --shell /usr/sbin/nologin --uid 999 volume-999

    Or in Compose, user: "999:999" on the service. Test that one first: some images expect to start as root and only drop to their own user in the entrypoint.

  3. If nothing uses it, look at the data

    sh
    docker run --rm -v <name>:/mnt:ro alpine ls -la /mntsudo du -sh /var/lib/docker/volumes/<name>/_data

  4. Back it up, then remove it

    sh
    docker run --rm -v <name>:/src:ro -v "$PWD":/backup alpine tar czf /backup/<name>.tgz -C /src .docker volume rm <name>

sh
# Owner of every volume, with the name resolved where possible:# (inside sudo sh -c, because your own shell cannot expand a glob under /var/lib/docker)sudo sh -c "stat -c '%n %u %U' /var/lib/docker/volumes/*/_data"# The UIDs containers are configured to run as (the check's allow-list):docker ps -aq | xargs -I{} docker inspect -f '{{.Config.User}}' {} | cut -d: -f1 | grep -E '^[0-9]+$' | sort -u# Before deleting anything, find out whether a volume is referenced:docker volume ls -f dangling=truedocker ps -a --filter volume=<name>sudo du -sh /var/lib/docker/volumes/<name>/_data

Debugging

  • There is no unprivileged fallback, and membership of the docker group is not enough: it reaches the daemon, not /var/lib/docker/volumes. Run the audit as root or give the audit account sudo.
  • Docker keeps its data somewhere else. docker info --format '{{.DockerRootDir}}' shows where: a custom data-root, a rootless daemon or userns-remap all land here. Run the stat command from the verify step against the real path.
  • Happens when the container declares no .Config.User (so it contributes no UID to the allow-list) while its process still writes as an image-internal UID. Confirm with docker ps -a --filter volume=<name>; if a container uses it, this is a false positive to record, not data to delete.
  • Check it is dangling and look at the size and contents before removing: docker volume inspect <name>, then docker run --rm -v <name>:/mnt alpine ls -la /mnt. Only then docker volume rm <name>.
  • docker volume prune deletes every unused anonymous volume at once, and docker volume prune --all every unused named one too, including a database whose container was recreated under a different name. Confirm each one first.
  • The message truncates at 5. Use the stat command above for the full picture.
  • Ownership here is a staleness signal. For actual exposure, see World-Writable Volumes and Volume Directory Permissions.

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