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
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 to | Host kernel | Sentry, a user-space kernel | Guest kernel in a VM |
| What separates it from the host | Namespaces, cgroups, seccomp, AppArmor | Sentry plus a small, filtered set of host syscalls | Hardware virtualization |
Typical containerd runtime_type | io.containerd.runc.v2 | io.containerd.runsc.v1 | io.containerd.kata.v2 |
| Node needs | Nothing extra | runsc installed | Virtualization support (KVM, nested or bare metal) |
| Costs | Lowest | Slower syscalls and I/O, some syscalls unsupported | VM start time and memory per Pod |
| Good for | Trusted workloads | Untrusted code with modest I/O | Untrusted or multi-tenant workloads that need full Linux behavior |
| Symptom | Cause | Fix |
|---|---|---|
FailedCreatePodSandBox: no runtime for "runsc" is configured | Node has no handler with that name | Install and configure the runtime, or use scheduling.nodeSelector |
| Pod rejected at create time | RuntimeClass nodeSelector conflicts with the Pod's nodeSelector | Align the labels |
| Pod rejected: RuntimeClass not found | Wrong runtimeClassName | kubectl get runtimeclass and fix the name |
| Nodes run out of memory with many sandboxed Pods | No overhead set | Set overhead.podFixed in the RuntimeClass |
| App errors only in the sandbox | Unsupported syscall or kernel feature | Test 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
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