Part 6 of 7 · 3 min read
Limits of namespaces
What a namespace does not do
Think of rooms in a hotel that each have their own lock, key and number, while the power station, the water main and the fire alarm are shared. A guest who sets off the fire alarm affects every room. The analogy stops in one place: the hotel has a manager on duty, and the kernel does not stop one namespace from using most of the CPU.
In plain words: Namespaces change what a process sees, and nothing else. They do not limit CPU, memory, disk or network use (the next page does). They do not hide the kernel: the version in uname -r is the host's, and a kernel bug can be reached from any namespace, so a container escape is a kernel attack. Some things are not in any namespace: the system clock (except the time offsets), kernel modules and many files in /sys and /proc. And a namespace alone does not restrict what a root process can do, so containers add capabilities, seccomp filters and MAC policy (Level 10).
A worked example. A container is started with only PID, mount, UTS and network namespaces. A process inside runs a loop that allocates memory without end. The PID namespace hides other processes from it, and the mount namespace hides other files, but the loop uses real host memory until the host's memory is gone, because nothing limits it. Adding a memory limit (page 5) is the fix.
The key lines. Namespaces answer "what can it see?", control groups answer "how much can it use?", and capabilities, filters and policy answer "what may it do?". A container needs all three.
Container escape
A container escape is an attack in which a process inside a container gains access to the host or to other containers, usually through a flaw in the shared kernel or a misconfiguration such as too many capabilities or a mounted host directory.
Example: a container started with the host's root directory mounted can read and write every host file.
Check yourself: 1. Which question do namespaces answer: what a process can see, how much it uses or what it may do? 2. Why is a kernel bug dangerous to all containers? 3. Name one thing that is not in any namespace.
Words you will meet
| Word | Meaning |
|---|---|
| Namespace | A private view of one kind of kernel resource. |
| PID namespace | Its own numbering of processes, starting at 1. |
| User namespace | Own user IDs, mapped to outer IDs. |
unshare, clone, setns |
Create, move into, or join namespaces. |
| veth pair | A virtual cable joining two network namespaces. |
| Container escape | An attack that leaves the container. |
Quick notes
- A namespace limits what a process can see and name. It shares the kernel.
- Eight kinds: mount, PID, network, UTS, IPC, user, cgroup, time.
clonecreates,unsharemoves,setnsjoins.lsnslists.- The first process of a PID namespace is number 1, and has two numbers (inside and outside).
- A user namespace maps IDs, so root inside need not be root outside.
- Namespaces do not limit resource use or rights. They do not hide the kernel.