Skip to main content
Security & multi-tenancyLesson 11 of 13

Sandboxed container runtimes — gVisor, Kata and RuntimeClass (CKS)

This covers "Understand and implement isolation techniques (multi-tenancy, sandboxed containers, etc.)" in the CKS Minimize Microservice Vulnerabilities domain. We run one untrusted Pod on a normal runtime, see why that is risky, and move it to a sandbox with a RuntimeClass.

How namespaces and cgroups isolate a container is in How Linux Isolates a Container, and seccomp, AppArmor and Falco are in Runtime security — catching abnormal behavior (CKS). Here we look at what changes when the kernel itself is no longer shared.

Runtimerunc
Boundary to hostnamespaces · cgroups
PodRunning
Node · containerdRuntimeClassgvisor → runscSchedulernodeSelectorDeveloperruntimeClassNamePod (runc)untrusted codePod (gVisor)runtimeClassNamePod (Kata)runtimeClassNameruncdefault handlergVisor Sentryuser-space kernelKata VMguest kernelcontainerdruntime handlersHost kernelone per nodestarted bysyscalls
RequestWatchAppears in a later step

What you will learn

  • Why a kernel exploit escapes a normal container
  • How gVisor and Kata put another kernel in front of the host
  • Handlers in containerd, RuntimeClass and runtimeClassName
  • What happens when a node lacks the handler, and how scheduling avoids it
  • Overhead and the trade-offs of sandboxing

runc, gVisor and Kata compared​

runc (default)gVisor (runsc)Kata Containers
Kernel the app talks toHost kernelSentry, a user-space kernelGuest kernel in a VM
What separates it from the hostNamespaces, cgroups, seccomp, AppArmorSentry plus a small, filtered set of host syscallsHardware virtualization
Typical containerd runtime_typeio.containerd.runc.v2io.containerd.runsc.v1io.containerd.kata.v2
Node needsNothing extrarunsc installedVirtualization support (KVM, nested or bare metal)
CostsLowestSlower syscalls and I/O, some syscalls unsupportedVM start time and memory per Pod
Good forTrusted workloadsUntrusted code with modest I/OUntrusted or multi-tenant workloads that need full Linux behavior
SymptomCauseFix
FailedCreatePodSandBox: no runtime for "runsc" is configuredNode has no handler with that nameInstall and configure the runtime, or use scheduling.nodeSelector
Pod rejected at create timeRuntimeClass nodeSelector conflicts with the Pod's nodeSelectorAlign the labels
Pod rejected: RuntimeClass not foundWrong runtimeClassNamekubectl get runtimeclass and fix the name
Nodes run out of memory with many sandboxed PodsNo overhead setSet overhead.podFixed in the RuntimeClass
App errors only in the sandboxUnsupported syscall or kernel featureTest in the sandbox, or keep that app on runc

Try it yourself​

# On a node: is the handler configured?
grep -n 'runtimes.runsc\|runtimes.kata' /etc/containerd/config.toml

# A RuntimeClass that only lands on labeled nodes
kubectl label node worker-1 sandbox=gvisor
cat <<EOF | kubectl apply -f -
apiVersion: node.k8s.io/v1
kind: RuntimeClass
metadata:
name: gvisor
handler: runsc
scheduling:
nodeSelector:
sandbox: gvisor
EOF
kubectl get runtimeclass

# A Pod that uses it
kubectl run sandboxed --image=busybox:1.36 --restart=Never \
--overrides='{"spec":{"runtimeClassName":"gvisor"}}' -- sleep 3600
kubectl get pod sandboxed -o wide # NODE should be worker-1
kubectl exec sandboxed -- dmesg # gVisor prints its own boot messages
kubectl describe pod sandboxed | grep -A5 Events # FailedCreatePodSandBox if the handler is missing

Check yourself

  1. A Pod is hardened with seccomp RuntimeDefault and AppArmor, and still runs on runc. Why can a kernel exploit through an allowed syscall still reach the host?
  2. A Pod with runtimeClassName: gvisor shows FailedCreatePodSandBox: no runtime for "runsc" is configured. What is the best fix for a cluster where only some nodes have gVisor?
  3. Many Kata Pods fit on a node by requests, but the node runs out of memory. What is missing?

Further reading: Runtime Class · Pod Overhead · gVisor · Kata Containers · How Linux Isolates a Container · Runtime security — catching abnormal behavior (CKS) · Pod Security Standards and securityContext