Skip to main content

01. Overview & Linux Isolation Primitives

Containers are often mistakenly referred to as lightweight Virtual Machines (VMs). In reality, containers are simply isolated Linux processes sharing the host operating system kernel.

Understanding container security requires a deep technical comprehension of how the Linux kernel isolates processes, where those boundaries break down, and how attackers leverage misconfigurations to execute container escapes.

[!IMPORTANT] A container breakout occurs when an attacker inside a container bypasses kernel isolation boundaries to execute arbitrary code, read sensitive data, or gain root access directly on the host operating system.


1. Containers vs. Virtual Machines: Architectural Boundaries​

To understand the attack surface, compare the virtualization boundary of Virtual Machines against the process boundary of Containers:

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚ VIRTUAL MACHINE ARCHITECTURE β”‚ β”‚ CONTAINER ARCHITECTURE β”‚
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€ β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
β”‚ β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”‚ β”‚ β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”‚
β”‚ β”‚ App A Code β”‚ β”‚ App B Code β”‚ β”‚ β”‚ β”‚ App A Code β”‚ β”‚ App B Code β”‚ β”‚
β”‚ β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€ β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€ β”‚ β”‚ β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€ β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€ β”‚
β”‚ β”‚ Guest OS A β”‚ β”‚ Guest OS B β”‚ β”‚ β”‚ β”‚ Binaries & β”‚ β”‚ Binaries & β”‚ β”‚
β”‚ β”‚ (Kernel A) β”‚ β”‚ (Kernel B) β”‚ β”‚ β”‚ β”‚ Libraries β”‚ β”‚ Libraries β”‚ β”‚
β”‚ β””β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”˜ β””β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”˜ β”‚ β”‚ β””β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”˜ β””β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”˜ β”‚
β”‚ β”‚ β”‚ β”‚ β”‚ β”‚ β”‚ β”‚
β”‚ β”Œβ”€β”€β”€β”€β”€β”€β–Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β–Όβ”€β”€β”€β”€β”€β”€β” β”‚ β”‚ β”‚ (Shared Syscalls) β”‚ β”‚
β”‚ β”‚ Hypervisor (Type 1 / KVM / ESXi) β”‚ β”‚ β”‚ β–Ό β–Ό β”‚
β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β”‚ β”‚ β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”‚
β”‚ β–Ό β”‚ β”‚ β”‚ Container Runtime (containerd) β”‚ β”‚
β”‚ β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”‚ β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β”‚
β”‚ β”‚ Host Hardware β”‚ β”‚ β”‚ β–Ό β”‚
β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β”‚ β”‚ β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”‚
β”‚ β”‚ β”‚ β”‚ Host Linux Kernel (Shared Ops) β”‚ β”‚
β”‚ β”‚ β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
  • Virtual Machines: Hypervisors enforce strict hardware-level isolation. Each VM executes its own independent operating system kernel. A vulnerability in Guest Kernel A cannot compromise Guest Kernel B unless a hypervisor breakout vulnerability exists.
  • Containers: Every container on a host shares the exact same host Linux kernel. Isolation relies entirely on kernel software constructs (Namespaces, cgroups, Capabilities, and Seccomp). If an attacker inside container A exploits a host kernel vulnerability, the entire underlying host is compromised.

2. Deep Dive: The 4 Core Linux Isolation Primitives​

Container runtimes like docker and containerd construct container isolation by orchestrating four primary Linux kernel features:

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚ THE 4 LINUX KERNEL ISOLATION PRIMITIVES β”‚
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
β”‚ Primitive β”‚ Core Function & Isolation Mechanism β”‚
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
β”‚ **1. Namespaces** β”‚ Virtualizes system resources so a process sees a privateβ”‚
β”‚ β”‚ copy of PID, Network, Filesystem, IPC, UTS, and Users. β”‚
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
β”‚ **2. cgroups** β”‚ Enforces resource quotas (CPU, RAM, Disk I/O, PIDs) to β”‚
β”‚ β”‚ prevent resource exhaustion and Denial of Service. β”‚
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
β”‚ **3. Capabilities**β”‚ Deconstructs the monolithic `root` power into 41 fine- β”‚
β”‚ β”‚ grained permissions, enabling dropping dangerous ops. β”‚
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
β”‚ **4. Seccomp** β”‚ Restricts which Linux system calls (syscalls) a process β”‚
β”‚ β”‚ can issue directly to the host kernel. β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

A. Linux Namespaces (Process Visibility Isolation)​

Linux Namespaces wrap global system resources into isolated abstractions. A process inside a namespace sees only the resources allocated to that namespace.

There are 7 primary Linux namespaces utilized by containers:

NamespaceIdentifierIsolated System ResourceSecurity Impact if Shared (host* mode)
PIDCLONE_NEWPIDProcess IDs and process tree hierarchySetting hostPID: true allows the container to view, trace (ptrace), and kill all host processes.
NETCLONE_NEWNETNetwork devices, IP addresses, route tables, socketsSetting hostNetwork: true lets the container bind directly to host ports and sniff host network interfaces.
MNTCLONE_NEWNSFile system mount pointsMounting host / gives the container full read/write access to host OS files.
IPCCLONE_NEWIPCInter-Process Comm (System V IPC, POSIX message queues)Setting hostIPC: true permits reading/writing to shared memory segments used by host processes.
UTSCLONE_NEWUTSHostname and NIS domain namePermits changing the host system's domain name or hostname.
UserCLONE_NEWUSERUser and Group IDs mappingUnmapped container root (UID 0) equals host root (UID 0). User namespaces map container UID 0 to an unprivileged host UID (e.g. 100000).
CgroupCLONE_NEWCGROUPControl Group root directory viewPrevents containers from inspecting or altering parent cgroup resource limits.

B. Control Groups (cgroups v1 & v2)​

Control Groups (cgroups) throttle and monitor resource usage (CPU, memory, disk I/O, network bandwidth) for a collection of processes. Without cgroups, a single compromised container could consume 100% of host RAM and CPU, executing a Denial-of-Service (DoS) attack against all neighboring containers.

Key Security Limits:​

  1. Memory Quotas (memory.max): Restricts maximum RAM. When exceeded, the Linux Out-Of-Memory (OOM Killer) terminates the container process instead of crashing the host.
  2. CPU Quotas (cpu.max): Restricts CPU bandwidth per period, preventing cryptomining or resource exhaustion.
  3. PID Limits (pids.max): Restricts the maximum number of tasks inside the container cgroup. Crucial for mitigating fork bombs:
    # Classic bash fork bomb - mitigated by setting pids.max = 100
    :(){ :|:& };:

C. Linux Capabilities (CAP_SYS_ADMIN Hazard)​

Traditionally, Unix systems divided privileges into two categories: unprivileged (UID != 0) and privileged (UID = 0).

Linux Capabilities break down monolithic root privilege into 41 distinct capability flags. Even if a process executes as UID 0 inside a container, it only possesses the capabilities granted to its process header.

High-Risk Capabilities Matrix:​

[!WARNING] Granting CAP_SYS_ADMIN to a container is functionally equivalent to handing out host root access. It enables mounting filesystems, creating block devices, and altering kernel settings.

CapabilityPrivileges GrantedContainer Breakout Vector
CAP_SYS_ADMINOverly broad system admin operations (mount, swap, namespaces)Can mount host disks (/dev/sda1), load file systems, and execute host binaries.
CAP_NET_ADMINNetwork interface reconfiguration, promiscuous mode, IP spoofingCan alter host routing tables, intercept internal traffic, and perform ARP spoofing.
CAP_SYS_PTRACEArbitrary process tracing via ptrace system callCan inspect memory of host processes and inject shellcode into host binaries.
CAP_SYS_MODULELoading and unloading arbitrary Linux Kernel Modules (LKMs)Can insert a malicious kernel rootkit directly into the host kernel.
CAP_DAC_READ_SEARCHBypasses file read permission checks and directory searchesCan read any file on the host filesystem regardless of permission settings.
CAP_SYS_CHROOTExecution of chroot system callCan breakout of chroot jail environments if unmasked.

D. Seccomp (Secure Computing Mode)​

Seccomp (Secure Computing Mode) acts as a syscall firewall between user-space applications and the Linux kernel.

The x86_64 Linux kernel exposes over 350 system calls (sys_execve, sys_openat, sys_ptrace, etc.). A typical web server container (Node.js, Nginx, Python) only requires ~40 to 60 system calls during its operation.

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚ SECCOMP SYSTEM CALL FILTER β”‚
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
β”‚ Container Application Process (e.g. Node.js / Python) β”‚
β”‚ β”‚ β”‚
β”‚ β”œβ”€β–Ί Required Syscall: openat(), read(), write() ──► [ ALLOWED BY SECCOMP ]
β”‚ β”‚ β”‚
β”‚ └─► Dangerous Syscall: ptrace(), reboot(), kexec() ──► [ BLOCKED BY SECCOMP ]
β”‚ β”‚ β”‚
β”‚ β–Ό β”‚
β”‚ SIGSYS Signal Sent β”‚
β”‚ (Execution Denied) β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

Key Syscalls Blocked by Default Kubernetes/Docker Seccomp Profile:​

  • ptrace: Prevents process memory inspection and code injection.
  • sys_module / finit_module: Blocks loading host kernel modules.
  • kexec_load: Blocks loading a new kernel for execution.
  • reboot: Prevents shutting down or restarting the host kernel.
  • unshare: Blocks creation of new namespaces that could bypass restrictions.

3. Container Threat Landscape & Attack Vectors​

Container security risks span multiple operational layers:


4. Container Breakout Workflow​

The diagram below illustrates a classic privilege escalation and container breakout path when a pod runs with privileged: true or CAP_SYS_ADMIN:


Next Chapter: 02. Hardened Dockerfiles & Image Security β†’