| name | docker-namespace-security |
| description | How to understand, test, and harden Docker namespace isolation for security. Use this skill whenever the user mentions Docker security, container isolation, namespace escapes, privilege escalation, container breakout, or needs to audit namespace configurations. This skill covers PID, Mount, Network, IPC, UTS, Time, and User namespaces. |
Docker Namespace Security
This skill helps you understand and secure Docker container namespace isolation. Namespaces are a Linux kernel feature that provides process isolation, and Docker uses them extensively to isolate containers from the host and from each other.
What are Namespaces?
Namespaces wrap a global system resource in an abstraction that makes it appear to the processes within the namespace that they have their own isolated instance of that resource. Docker uses six main namespace types:
- PID - Process ID isolation
- Mount - Filesystem mount point isolation
- Network - Network stack isolation
- IPC - Inter-process communication isolation
- UTS - Hostname and domain name isolation
- User - User and group ID isolation
Quick Reference
Check Your Current Namespaces
ls -la /proc/self/ns/
readlink /proc/self/ns/pid
readlink /proc/self/ns/mnt
readlink /proc/self/ns/net
Inspect Container Namespace Configuration
docker inspect <container_id> | grep -A 20 Namespaces
docker inspect <container_id> | grep -i "hostpid\|hostnetwork\|hostipc"
Namespace Types Deep Dive
PID Namespace
Purpose: Isolates process IDs so containers see their own process tree.
Security Implications:
- Without PID namespace isolation, containers can see and potentially signal host processes
- PID namespace escapes can lead to full container breakout
Hardening:
docker inspect <container> | grep -i "pidmode"
Testing for PID Namespace Escape:
ps aux
ls /proc/1/root
Mount Namespace
Purpose: Isolates filesystem mount points.
Security Implications:
- Mount namespace isolation prevents containers from seeing host mounts
- Improperly configured volumes can expose sensitive host paths
- Mount namespace escapes are a common privilege escalation vector
Hardening:
-v /host/path:/container/path:ro
docker inspect <container> | grep -A 50 Mounts
Testing for Mount Namespace Issues:
mount | grep -v "cgroup\|tmpfs"
ls -la /proc/1/root 2>/dev/null
ls -la /etc/passwd
Network Namespace
Purpose: Isolates network stack (interfaces, routing tables, ports).
Security Implications:
- Network namespace isolation prevents containers from directly accessing host network
--network=host shares the host network namespace (high risk)
- Network namespace escapes can enable lateral movement
Hardening:
docker network create mynetwork
docker run --network=mynetwork ...
docker inspect <container> | grep -i "networkmode"
Testing for Network Namespace Issues:
ip addr show
ping <host_internal_ip>
IPC Namespace
Purpose: Isolates inter-process communication (shared memory, semaphores).
Security Implications:
- IPC namespace isolation prevents containers from sharing memory with host
--ipc=host shares host IPC namespace (can leak sensitive data)
Hardening:
docker inspect <container> | grep -i "ipcmode"
UTS Namespace
Purpose: Isolates hostname and domain name.
Security Implications:
- UTS namespace isolation prevents containers from changing host hostname
--uts=host shares host UTS namespace (can cause confusion in logging)
Hardening:
docker inspect <container> | grep -i "utsmode"
User Namespace
Purpose: Isolates user and group IDs, allowing root in container to map to non-root on host.
Security Implications:
- User namespace isolation is CRITICAL for security
- Without it, root in container = root on host
- Many Docker security features depend on user namespaces
Hardening:
{
"userns-remap": "default"
}
--userns=host
docker inspect <container> | grep -i "userns"
id
Testing for User Namespace Issues:
id
Common Namespace Escape Vectors
1. Privileged Containers
docker run --privileged ...
docker run --cap-add=NET_ADMIN ...
2. Host Namespace Sharing
docker run --pid=host ...
docker run --network=host ...
docker run --ipc=host ...
docker run --uts=host ...
docker inspect <container> | grep -E "pidmode|networkmode|ipcmode|utsmode"
3. Sensitive Volume Mounts
-v /:/host
docker run -v /etc:/etc ...
docker run -v /proc:/proc ...
-v /specific/path:/container/path:ro
4. Capabilities Abuse
docker run --cap-add=ALL ...
docker run --cap-drop=ALL --cap-add=NET_BIND_SERVICE ...
Security Checklist
Use this checklist when auditing Docker containers:
Quick Audit Script
Run this on the host to check container namespace security:
#!/bin/bash
echo "=== Docker Namespace Security Audit ==="
echo
for container in $(docker ps -aq); do
echo "Container: $container"
if docker inspect $container | grep -q '"Privileged": true'; then
echo " ⚠️ PRIVILEGED MODE ENABLED"
fi
if docker inspect $container | grep -q '"PidMode": "host"'; then
echo " ⚠️ Shares host PID namespace"
fi
if docker inspect $container | grep -q '"NetworkMode": "host"'; then
echo " ⚠️ Shares host network namespace"
fi
if docker inspect $container | grep -q '"IpcMode": "host"'; then
echo " ⚠️ Shares host IPC namespace"
fi
if docker inspect $container | grep -E '"Source": "/|"Source": "/etc|"Source": "/proc|"Source": "/sys"' | grep -v '"Mode": "ro"'; then
When to Use This Skill
Use this skill when you need to:
- Audit container security - Check if containers are properly isolated
- Understand namespace escapes - Learn how attackers might break out of containers
- Harden Docker configurations - Apply security best practices
- Debug namespace issues - Troubleshoot container isolation problems
- Design secure container architectures - Plan namespace isolation for new deployments
Related Topics
- Docker capabilities (
--cap-add, --cap-drop)
- Seccomp profiles for syscall filtering
- AppArmor/SELinux for mandatory access control
- Docker security scanning (Trivy, Clair, Docker Scan)
- Runtime security (Falco, Sysdig)