User Namespace Remapping
What you'll learn: How to prevent a compromised container from gaining root privileges on your host system by remapping container UIDs to unprivileged host users.
The Core Problem
By default, when a process runs as root (UID 0) inside a container, it's also UID 0 from the host's perspective. If an attacker escapes the container through a kernel vulnerability or misconfiguration, they inherit root privileges on the entire host system—a catastrophic security failure.
How User Namespace Remapping Works
User namespace remapping creates an identity translation layer. The container believes a process is running as root (UID 0), but the host kernel maps that to an unprivileged user ID (like UID 100000).
Analogy: Think of it like a video game where a player feels like an all-powerful admin within their game world, but from the game server's perspective, they're just a regular user with limited system permissions.
This mapping happens transparently:
- Inside container: UID 0 (root)
- On host: UID 100000 (unprivileged)
If the container is compromised and an attacker escapes, they arrive on the host as user 100000—unable to read /etc/shadow, install backdoors, or modify system files.
Implementation Approach
Enable user namespace remapping in your container runtime (e.g., Docker daemon configuration), specifying the UID/GID range to map. The daemon handles all translation automatically. Files created by the container appear owned by remapped UIDs on the host filesystem.
Tradeoff: Some privileged operations won't work inside remapped containers, and volume permissions may require adjustment.
Key Takeaway: User namespace remapping dramatically reduces the blast radius of container escapes by ensuring container root never equals host root, containing breaches within unprivileged boundaries.