feat(ci-runners): run the deploy runner in a Kata microVM (staged) #79
4 changed files with 180 additions and 14 deletions
27
apps/base/forgejo/kata-runtimeclass.yaml
Normal file
27
apps/base/forgejo/kata-runtimeclass.yaml
Normal 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
|
||||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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))
|
||||
|
|
|
|||
|
|
@ -99,11 +99,86 @@ What was already removed from the runner shape (same change, card
|
|||
|
||||
Residual risk, stated plainly: a privileged dind container is node root on the
|
||||
node it runs on, and a CI job can reach that daemon socket by design. The
|
||||
capsule therefore means "trusted CI code" rather than isolation. The remaining
|
||||
hardening path is a runtime that virtualises the container runtime (sysbox or
|
||||
gVisor) behind a `RuntimeClass`, which would allow `enforce: baseline` on the
|
||||
capsule too; that is a separate design card because it changes how every job
|
||||
container executes.
|
||||
capsule therefore means "trusted CI code" rather than isolation. The one
|
||||
hardening path that changes what `privileged: true` *means* is a virtualised
|
||||
runtime behind a `RuntimeClass`; it was evaluated and staged on one runner —
|
||||
see below.
|
||||
|
||||
## `enforce: baseline` on `ci-runners` is unreachable by any runtime (measured)
|
||||
|
||||
All three candidate runtimes were installed on **both** arches and exercised
|
||||
against the live cluster on 2026-11-27 (v1.36.4, containerd 2.3.4/2.3.5, Cilium
|
||||
native routing). Architecture was never the blocker: sysbox-ce 0.7.2 ships an
|
||||
arm64 `.deb`, gVisor publishes `gvisor-aarch64`, Kata publishes
|
||||
`kata-static-4.4.0-arm64`, and `/dev/kvm` exists on siriussec **and** rpi.
|
||||
|
||||
The blocker is a contradiction, not a bug:
|
||||
|
||||
> PSA `baseline` forbids adding any capability outside `AUDIT_WRITE, CHOWN,
|
||||
> DAC_OVERRIDE, FOWNER, FSETID, KILL, MKNOD, NET_BIND_SERVICE, SETFCAP, SETGID,
|
||||
> SETPCAP, SETUID, SYS_CHROOT` — and every nested dockerd needs `SYS_ADMIN`
|
||||
> (overlay, mounts) + `NET_ADMIN` (docker0, iptables) **in the pod spec**.
|
||||
|
||||
Measured verdicts, each on a live cluster:
|
||||
|
||||
| runtime | verdict |
|
||||
|---|---|
|
||||
| sysbox-ce 0.7.2 | The only one **admitted** at `enforce: baseline` with a clean spec (id-mapped userns, `uid_map 0 427680 65536`), but its inner dockerd cannot use the CNI-owned pod netns: `Failed to create bridge docker0 via netlink: operation not permitted`, `iptables ... Could not fetch rule set generation id: Permission denied`, and with `--bridge=none` every `docker run` dies on `failed to set into network namespace ... operation not permitted`. sysbox also bans inner `--net=host`, so there is no egress fallback. Also needs `enable_unprivileged_ports=false` + `enable_unprivileged_icmp=false` under containerd 2.x. |
|
||||
| gVisor | Full CI shape works (nested run, pull, build, overlay2) **only** with `capabilities.add: ["ALL"]`; with a baseline-clean spec dockerd never starts (`failed to mount overlay: operation not permitted`). |
|
||||
| Kata 4.4.0 | `privileged: false` hits the same caps wall *inside the guest*. With `privileged: true` the whole CI shape works on amd64 **and** arm64 (nested run, bridge+NAT egress, `docker build`) — but `/var/lib/docker` is virtiofs, overlayfs refuses it, and Docker falls back to `vfs`. |
|
||||
|
||||
So the letter of the original audit finding (drop `privileged`, enforce
|
||||
`baseline`) cannot be met by swapping a runtime; only reworking CI off
|
||||
docker-in-docker could, and that rewrites every workflow. The operator's
|
||||
decision (card `t_8aa4af50`) was to take the one option that changes the
|
||||
*consequence* of the flag, staged to a single runner.
|
||||
|
||||
## Kata microVM on the deploy runner (`forgejo-runner-deploy-arm64`, staged)
|
||||
|
||||
`forgejo-runner-deploy-arm64` (rpi) now runs with
|
||||
`runtimeClassName: kata-qemu`. **Read this precisely:**
|
||||
|
||||
* the pod **still declares `privileged: true`** and `ci-runners` **still
|
||||
enforces `privileged`**. Nothing about this namespace's PSA level changed; a
|
||||
privileged pod in `forgejo` is still rejected;
|
||||
* what changed is the blast radius: the dind sidecar and the job containers
|
||||
live in a QEMU/KVM microVM with no host namespaces, no host kernel and only
|
||||
the volumes the pod mounts. An escape from CI has to beat KVM, not just the
|
||||
container runtime. On a runc runner the same flag is direct root on rpi;
|
||||
* `forgejo-runner-amd64` and `forgejo-runner-arm64` are untouched (still
|
||||
privileged dind under runc), so `docker-amd64` and `runs-on: docker` are
|
||||
unchanged. Converting them is a separate decision, taken on the measured cost
|
||||
of this one.
|
||||
|
||||
How it is wired (all in `apps/base/forgejo/`):
|
||||
|
||||
* `kata-runtimeclass.yaml` — `RuntimeClass` `kata-qemu`, handler `kata-qemu`;
|
||||
* rpi's containerd has the handler via the drop-in
|
||||
`/etc/containerd/conf.d/50-kata.toml` (`io.containerd.kata.v2`,
|
||||
`privileged_without_host_devices = true` — a privileged container otherwise
|
||||
receives all 218 of the node's `/dev` nodes, which is meaningless inside a VM
|
||||
and makes runtime-rs fail the create with `get host path failed`), with
|
||||
kata-static 4.4.0 under `/opt/kata` and
|
||||
`/etc/kata-containers/configuration.toml` symlinked to the runtime-rs QEMU
|
||||
config;
|
||||
* the dind sidecar builds its own ext4 data-root: a 16 GiB image file at
|
||||
`/data-docker/kata-ext4.img` on the existing claim, attached with
|
||||
`losetup /dev/loop0` (the guest has to `mknod` the node — only
|
||||
`/dev/loop-control` exists) and mounted at `/var/lib/docker`. This is what
|
||||
restores `overlay2`; without it Docker silently uses `vfs`;
|
||||
* the guest kernel has **no** binfmt registrations (the host's are not visible
|
||||
from inside the VM), so every start mounts `binfmt_misc` and runs
|
||||
`tonistiigi/binfmt --install amd64`. Without that, `deploy-site.yml`'s
|
||||
`docker buildx build --platform linux/amd64` dies with `exec format error` /
|
||||
`buildkit-qemu-x86_64: executable file not found`;
|
||||
* the runner container waits for `/var/run/dind-ready`, which the dind sidecar
|
||||
touches **after** the data-root and binfmt are set up, so a job can never
|
||||
start against a half-initialised daemon.
|
||||
|
||||
Rollback is one field: drop `runtimeClassName: kata-qemu` from that Deployment
|
||||
(Flux) — the pod returns to runc/privileged dind on the same claim, and the
|
||||
`kata-ext4.img` is an unused file until then (it is a cache; deleting it is
|
||||
safe). The containerd drop-in on rpi is inert once no pod asks for the handler.
|
||||
|
||||
## Why the dind sidecar keeps `privileged` (measured, do not re-derive)
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue