How does enabling userns-remap on the Docker daemon stop the volume-mount privilege-escalation attack?
It maps container UID 0 to an unprivileged high host UID (e.g. 231072). Files the "root" container process creates on a bind mount are owned by that harmless UID on the host, so the attacker gains no real host privileges.
Earlier, container-root writing to a bind-mounted host folder created root-owned files on the host — the basis of the escalation. User namespaces break that link.
With userns-remap set, the daemon runs containers under a remapped ID range. Docker's --userns-remap=default creates a user dockremap and allocates it a sub-ID block in /etc/subuid and /etc/subgid, e.g.:
testuser:231072:65536
meaning container UID 0 → host UID 231072, and the next 65536 IDs follow. Now:
- A process that is root inside the container is UID 231072 on the host — an unprivileged, essentially fictitious user that owns nothing.
- Files it creates on a mounted volume are owned by that remapped UID, not host root. Reading a host file like
/tmp/rootfile.txt(owner root,0644) from the container shows it is not writable, because the container's "root" is really 231072. - If an attacker escapes the container, on the host they have only that high, powerless UID — no host privileges.
It is the strongest structural defence against the privilege-escalation chain, because it removes the very premise ("container root = host root") the attacks rely on. (Enabling it needs a daemon restart, and comes with some storage/compatibility trade-offs.)
* Container root maps to a powerless high UID on the host. *
Go deeper:
Docker Docs: Isolate containers with a user namespace — enabling userns-remap and its trade-offs.
man7.org: user_namespaces(7) — the subuid/subgid mapping in detail.