feat(ci-runners): run the deploy runner in a Kata microVM (staged)

The CI capsule cannot enforce PSA baseline: every nested dockerd needs
SYS_ADMIN+NET_ADMIN in the pod spec and baseline forbids exactly those, which
sysbox, gVisor and Kata all reproduce (measured on both arches, card
t_8aa4af50). What a runtime CAN change is what privileged:true means.

Stage 1, one runner: forgejo-runner-deploy-arm64 (rpi) gets
runtimeClassName: kata-qemu, so its privileged dind and job containers run
inside a QEMU/KVM microVM instead of on rpi's host namespaces. The amd64 and
shared arm64 runners stay on privileged dind under runc, untouched.

Kata-specific plumbing in the same Deployment:
- loop-backed ext4 data-root (16GiB image on the existing claim) because
  overlayfs refuses virtiofs and Docker would silently fall back to vfs;
- binfmt_misc + tonistiigi/binfmt --install amd64 on every start, because the
  guest kernel has no qemu handlers and deploy-site.yml cross-builds amd64;
- the runner waits for /var/run/dind-ready (touched after both are set up).

RuntimeClass kata-qemu is cluster-scoped; the containerd handler lives on rpi
only (/etc/containerd/conf.d/50-kata.toml, kata-static 4.4.0). Rollback is one
field. docs/pod-security.md records the measurement and states plainly that the
namespace stays enforce: privileged.
This commit is contained in:
Sirius DevOps 2026-11-27 02:08:47 -05:00
commit 989a0997fb
4 changed files with 180 additions and 14 deletions

View file

@ -0,0 +1,27 @@
---
# Kata Containers microVM RuntimeClass for the CI capsule (card t_8aa4af50).
#
# What this buys and what it does NOT: a pod using this class still declares
# `privileged: true` — a nested dockerd needs CAP_SYS_ADMIN + CAP_NET_ADMIN in
# the pod spec, and PSA `baseline` forbids exactly those two, so `ci-runners`
# stays at `enforce: privileged` (docs/pod-security.md). What changes is what
# privilege applies to: the container runs inside a QEMU/KVM microVM, so
# "privileged" means root in a VM with no host namespaces, no host kernel and
# only the volumes the pod mounts — an escape has to beat KVM first.
#
# The handler name `kata-qemu` must exist in containerd on every node that can
# run a pod with this class (drop-in /etc/containerd/conf.d/50-kata.toml,
# kata-static 4.4.0 under /opt/kata). Installed on rpi 2026-11-27; not yet on
# siriussec — that is why only the rpi-pinned deploy runner uses this class.
apiVersion: node.k8s.io/v1
kind: RuntimeClass
metadata:
name: kata-qemu
handler: kata-qemu
# VM overhead is charged to the pod so the scheduler accounts for it. The VM
# itself is sized from the pod's memory limits (2Gi here) plus the kata
# agent/kernel.
overhead:
podFixed:
cpu: 250m
memory: 160Mi

View file

@ -25,6 +25,9 @@ resources:
# (its helper pod is hardcoded to siriussec). Must sort before the runner
# Deployments that consume the claims.
- runner-dind-storage.yaml
# Cluster-scoped RuntimeClass for the Kata microVM that the rpi deploy runner
# uses (card t_8aa4af50). Its handler exists in containerd on rpi only.
- kata-runtimeclass.yaml
- runner-arm64.yaml
- runner-amd64.yaml
- runner-deploy-arm64.yaml

View file

@ -52,6 +52,13 @@ spec:
operator: Equal
value: network
effect: PreferNoSchedule
# Kata microVM (apps/base/forgejo/kata-runtimeclass.yaml, installed on rpi
# only). The pod is still `privileged: true` — a nested dockerd needs
# SYS_ADMIN+NET_ADMIN in the spec and PSA baseline forbids those two, so
# `ci-runners` stays at enforce: privileged (docs/pod-security.md). Kata
# changes the *consequence*: that privilege is VM root, not rpi's host
# root. Rollback of this whole experiment is this one field.
runtimeClassName: kata-qemu
# Group on the data volume, matching the runner gid (see fix-data-perms).
securityContext:
fsGroup: 1000
@ -125,6 +132,24 @@ spec:
- sh
- -c
- |
set -e
# --- Data root: ext4 on a loop device, not the virtiofs mount ---
# Under Kata every Kubernetes volume is a virtiofs share, and
# overlayfs refuses virtiofs as an upperdir ("failed to mount
# overlay: invalid argument"), which leaves Docker on `vfs`
# (layer copies). A loop-backed ext4 image on the PVC restores
# overlay2: measured inside the guest 2026-11-27, Storage Driver
# overlay2, 16 GiB volume, survives pod restarts because the image
# file lives on the claim. Losing it only costs a cold image cache.
IMG=/data-docker/kata-ext4.img
[ -f "$IMG" ] || fallocate -l 16G "$IMG"
[ -b /dev/loop0 ] || mknod /dev/loop0 b 7 0
if ! losetup -a | grep -q "$IMG"; then
losetup /dev/loop0 "$IMG"
fi
blkid /dev/loop0 | grep -q 'TYPE="ext4"' || mkfs.ext4 -q -F -L katadocker /dev/loop0
mount /dev/loop0 /var/lib/docker
echo "dind data-root: $(df -hT /var/lib/docker | tail -1)"
# --insecure-registry: the Pi registry is plain HTTP on the WG
# hub IP. Docker only treats 127.0.0.0/8 as insecure by default,
# so without this `docker push 10.10.0.1:5000/...` from a job
@ -142,20 +167,52 @@ spec:
i=$((i+1))
sleep 1
done
# --- binfmt: the deploy cross-builds linux/amd64 under qemu ---
# deploy-site.yml runs `docker buildx build --platform linux/amd64`
# and until now that worked because the Pi HOST kernel had the
# qemu binfmt handlers registered. A Kata pod has its own guest
# kernel, so nothing is registered and the build dies with
# `exec format error` / `buildkit-qemu-x86_64: not found`.
# Registering inside the guest is per-VM state: it must run on
# every pod start. The tonistiigi/binfmt image is cached in the
# data-root after the first start, and the registration uses the
# F flag (interpreter fd is held by the kernel), so the image can
# exit immediately afterwards.
mount -t binfmt_misc binfmt_misc /proc/sys/fs/binfmt_misc 2>/dev/null || true
if ! grep -q . /proc/sys/fs/binfmt_misc/qemu-x86_64 2>/dev/null; then
i=0
until docker run --rm --privileged tonistiigi/binfmt --install amd64 >/dev/null 2>&1; do
i=$((i+1))
if [ "$i" -ge 3 ]; then
echo "WARNING: could not register qemu-x86_64 binfmt; amd64 cross builds will fail" >&2
break
fi
sleep 3
done
fi
grep -q . /proc/sys/fs/binfmt_misc/qemu-x86_64 2>/dev/null &&
echo "binfmt: qemu-x86_64 registered" || echo "binfmt: NOT registered" >&2
# Job containers must not start before the daemon AND the
# cross-build emulation are ready; the runner waits on this file.
touch /var/run/dind-ready
wait "$pid"
securityContext:
# Cannot be dropped on these nodes: see the long note in
# runner-amd64.yaml (procfs without CAP_SYS_ADMIN, /sys/fs/cgroup
# mounted read-only by kubelet, rootless dind blocked by masked
# /proc + missing /dev/net/tun). Verified live 2026-11-27.
# Lives in namespace ci-runners (enforce: privileged),
# not forgejo (enforce: baseline) — see runner-amd64.yaml.
# Still required UNDER KATA: the caps a nested dockerd needs
# (SYS_ADMIN for mounts/overlay, NET_ADMIN for docker0/iptables)
# are caps the pod spec must add, and PSA `baseline` forbids both —
# no runtime works around that (measured: sysbox, gVisor, Kata, see
# docs/pod-security.md). What Kata changes is the blast radius: this
# is root inside a QEMU/KVM microVM, with no host namespaces and no
# host kernel, not root on rpi. On a runc runner the same flag is
# host root.
privileged: true
volumeMounts:
- name: dind-run
mountPath: /var/run
# The claim holds the loop-backed ext4 image (kata-ext4.img) rather
# than being dockerd's data-root directly: see the startup script.
- name: data
mountPath: /var/lib/docker
mountPath: /data-docker
subPath: docker
resources:
# Deliberately smaller than the shared runner's 4Gi. A deploy is two
@ -186,9 +243,13 @@ spec:
- -c
- |
set -e
# Wait for the dind sidecar AND its per-VM extras (loop-backed
# data-root, qemu-x86_64 binfmt) — under Kata both are set up
# inside the guest on every pod start, so the socket alone is not
# "ready". dind touches /var/run/dind-ready last.
i=0
while [ "$i" -lt 60 ]; do
if [ -S /var/run/docker.sock ]; then
while [ "$i" -lt 90 ]; do
if [ -S /var/run/docker.sock ] && [ -e /var/run/dind-ready ]; then
break
fi
i=$((i+1))