liveBook · Manning

Container escape vulnerability

As explained in Kubernetes for Developers

A container escape vulnerability is a flaw that allows a process confined in a container to access resources or privileges outside the container.

A container escape vulnerability is a flaw in Linux containerization that lets a process cross its sandbox and gain access to the node. Because containers are host processes isolated with cgroups and namespaces, the escaped process inherits the privileges of its container user: a root container could expose full root access on the node. section 12.4 section 12.7.2

Reduce the consequences of an escape with layered defenses:

  • Run containers as non-root users so an escape does not immediately provide elevated node privileges. section 12.4
  • Use Pod Security admission to limit container access, then add a secure runtime when container isolation alone is insufficient. section 12.7.2
  • Configure RuntimeClass with an additional sandbox such as gVisor when running untrusted code, accepting a performance penalty. section 12.7.2

Making a timeserver compatible with non-root execution

Set runAsNonRoot to true. If the image still defaults to root, Kubernetes reports CreateContainerConfigError; define USER 1001 in the Dockerfile and runAsUser: 1001 in the Pod. Because non-root processes cannot bind port 80, change the server to port 8080 and target that port from the Service. Adjust log-directory permissions so the application can write its logs. section 12.4

Listing 12.6 Chapter12/12.4_NonRootContainers/1_permission_error/deploy.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
  name: timeserver
spec:
  replicas: 1
  selector:
    matchLabels:
      pod: timeserver-pod
  template:
    metadata:
      labels:
        pod: timeserver-pod
    spec:
      containers:
      - name: timeserver-container
        image: docker.io/wdenniss/timeserver:6
        securityContext:         #1
          runAsNonRoot: true     #1
#1 Prevent running this container as the root user.

Inspect the Kubernetes Deployment fragment that prevents the container from running as root. section 12.4

How Kubernetes for Developers covers it

How deep it goes
Explains privilege inheritance, non-root mitigation, runtime isolation, and deployment failures without detailing escape exploits.
Examples
Uses a Kubernetes timeserver deployment, permission errors, port changes, and a non-root Dockerfile.
What it assumes
Assumes basic containers and Kubernetes Pods while teaching container processes, root privileges, and isolation from first principles.
What you can do after
Apply it via Kubernetes securityContext and RuntimeClass settings to reduce node compromise from escaped containers.
How it connects
Connects container isolation with Linux cgroups, namespaces, Pod Security admission, RuntimeClass, gVisor, and defense in depth.

Also explained in

Compare how 2 books explain container escape vulnerability →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Kubernetes for Developers. The section links point to the parts of the book it draws on.