ci(runners): isolate the CI capsule in forgejo-runners, enforce baseline on forgejo

The three Actions runners (privileged dind sidecars) and the nightly prune
CronJob (hostPath /var/run/docker.sock) cannot live under PSA baseline, so
they move to their own namespace `forgejo-runners` with `enforce: privileged`
(plus warn/audit restricted). That lets `forgejo` — Forgejo, CNPG Postgres,
cluster-backup — enforce `baseline` instead of only warning.

The dind sidecars stay privileged: measured on these nodes, a non-privileged
pod cannot host a container runtime (cgroup fs is mounted ro; rootless dind
cannot mount procfs; procMount=Unmasked needs hostUsers=false where subuid
maps and /dev/net/tun are refused). See docs/pod-security.md.

- PVCs/PVs are reused, not recreated: the two static Retain PVs on rpi and the
  dynamic local-path PV on siriussec were rebound by name, so runner.ini
  (registration uuid), the dind data-root and the actions cache survive.
- prune CronJob + its SA/Role/RoleBinding/configmap move with the runners;
  NAMESPACE and the Role scope follow.
- monitoring: runner/prune queries and runbooks now select forgejo-runners;
  cnpg_actions_* panels keep namespace="forgejo" (that is the pg namespace).
- docs: pod-security.md rewritten for the two enforced namespaces.

Verified live: all three runners 2/2 Running in forgejo-runners with their
original registration uuids and image counts, forgejo rejects a privileged pod
at admission, and a real CI image build completes (see the card).
This commit is contained in:
Lancelot 2026-11-27 01:15:07 -05:00
commit 3d21e96a9c
18 changed files with 239 additions and 127 deletions

View file

@ -1,7 +1,10 @@
apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization
resources:
# Two namespaces: `forgejo` (enforce: baseline) and `forgejo-runners`
# (enforce: privileged — the CI capsule). Namespace objects sort first.
- namespace.yaml
- runner-namespace.yaml
- httproute.yaml
- pvc.yaml
- cluster.yaml
@ -12,6 +15,12 @@ resources:
- deployment.yaml
- service.yaml
- runner-configmap.yaml
# The runner PVCs/Deployments below and the prune CronJob — plus the two
# runner-token Secrets near the bottom — live in namespace `forgejo-runners`,
# not `forgejo`: the dind sidecars need `privileged` and the prune Job needs a
# hostPath socket, both of which `forgejo` now rejects at admission
# (enforce: baseline).
#
# Static PVs/PVCs pinned to rpi: dynamic local-path cannot provision there
# (its helper pod is hardcoded to siriussec). Must sort before the runner
# Deployments that consume the claims.

View file

@ -2,21 +2,28 @@ apiVersion: v1
kind: Namespace
metadata:
name: forgejo
# Pod Security: warn/audit only. `enforce: baseline` is deliberately NOT set
# yet: the three Actions runner Deployments in this namespace carry a
# docker-in-docker sidecar that cannot lose `privileged: true` on these nodes
# (see the long note in runner-amd64.yaml — procfs needs CAP_SYS_ADMIN,
# kubelet mounts /sys/fs/cgroup read-only for non-privileged pods, and
# rootless dind is blocked by the masked /proc and the absent /dev/net/tun).
# Baseline would reject those pods at admission, i.e. take CI down rather
# than harden it. The remaining fix (move the CI capsule to its own
# explicitly-privileged namespace, or exempt the runner ServiceAccount) is
# tracked on card t_2bbe34a8.
# Pod Security: `enforce: baseline` here. Everything that lives in this
# namespace — Forgejo itself, the CNPG Postgres cluster, the nightly
# cluster-backup CronJob — is baseline-clean (no privileged, no hostPath,
# no host namespaces, no added capabilities), so the enforcement is real
# rather than decorative.
#
# warn/audit at `restricted` means every future pod creation here prints its
# violations and records them as audit annotations, so the next privileged,
# hostPath or hostNetwork pod is visible even without enforcement.
# The Actions runners are NOT here any more. A docker-in-docker sidecar
# cannot lose `privileged: true` on these nodes (procfs needs CAP_SYS_ADMIN,
# kubelet mounts /sys/fs/cgroup read-only for non-privileged pods, rootless
# dind is blocked by the masked /proc and the absent /dev/net/tun — all
# measured, see docs/pod-security.md), so the three runner Deployments, their
# PVCs and the prune CronJob live in `forgejo-runners`, which enforces PSA at
# `privileged` on purpose. Moving them out is what lets this namespace
# enforce baseline: if a runner (or anything else privileged/hostPath) is
# ever added here, admission rejects it instead of silently accepting it.
#
# warn/audit stay at `restricted`: a future pod that is baseline-clean but
# not restricted-clean (e.g. missing seccomp/runAsNonRoot) is still printed
# and recorded as audit annotations.
labels:
pod-security.kubernetes.io/enforce: baseline
pod-security.kubernetes.io/enforce-version: latest
pod-security.kubernetes.io/warn: restricted
pod-security.kubernetes.io/warn-version: latest
pod-security.kubernetes.io/audit: restricted

View file

@ -35,18 +35,18 @@ apiVersion: v1
kind: ServiceAccount
metadata:
name: forgejo-prune
namespace: forgejo
namespace: forgejo-runners
labels:
app: forgejo-runner
role: prune
---
# Least privilege: the job needs to find dind pods (get/list) and to run
# docker inside them (pods/exec create) — in namespace forgejo only.
# docker inside them (pods/exec create) — in namespace forgejo-runners only.
apiVersion: rbac.authorization.k8s.io/v1
kind: Role
metadata:
name: forgejo-prune
namespace: forgejo
namespace: forgejo-runners
labels:
app: forgejo-runner
role: prune
@ -62,7 +62,7 @@ apiVersion: rbac.authorization.k8s.io/v1
kind: RoleBinding
metadata:
name: forgejo-prune
namespace: forgejo
namespace: forgejo-runners
labels:
app: forgejo-runner
role: prune
@ -73,13 +73,13 @@ roleRef:
subjects:
- kind: ServiceAccount
name: forgejo-prune
namespace: forgejo
namespace: forgejo-runners
---
apiVersion: v1
kind: ConfigMap
metadata:
name: forgejo-prune-scripts
namespace: forgejo
namespace: forgejo-runners
labels:
app: forgejo-runner
role: prune
@ -166,12 +166,12 @@ data:
dind-daemons.sh: |
#!/bin/sh
# Prune every in-cluster dind daemon, discovered by label.
# Selector: pods with app=forgejo-runner in namespace forgejo that have a
# Selector: pods with app=forgejo-runner in namespace forgejo-runners that have a
# container named `dind`. Nothing here is keyed to a pod name, so a new
# dind runner (e.g. the arm64 migration) is pruned the night it appears.
set -u
NS=${NAMESPACE:-forgejo}
NS=${NAMESPACE:-forgejo-runners}
CAP_BYTES=${CACHE_CAP_BYTES:-4000000000}
CACHE_AGE_H=${CACHE_AGE_H:-72}
CONTAINER_AGE_H=${CONTAINER_AGE_H:-48}
@ -263,7 +263,7 @@ apiVersion: batch/v1
kind: CronJob
metadata:
name: forgejo-runner-prune
namespace: forgejo
namespace: forgejo-runners
labels:
app: forgejo-runner
role: prune
@ -343,7 +343,7 @@ spec:
command: ["/bin/sh", "/scripts/dind-daemons.sh"]
env:
- name: NAMESPACE
value: forgejo
value: forgejo-runners
- name: CACHE_CAP_BYTES
value: "4000000000"
- name: CACHE_AGE_H

View file

@ -2,7 +2,7 @@ apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: forgejo-runner-amd64
namespace: forgejo
namespace: forgejo-runners
spec:
accessModes:
- ReadWriteOnce
@ -15,7 +15,7 @@ apiVersion: apps/v1
kind: Deployment
metadata:
name: forgejo-runner-amd64
namespace: forgejo
namespace: forgejo-runners
labels:
app: forgejo-runner
arch: amd64
@ -170,6 +170,12 @@ spec:
# What this file *does* remove: the runner's uid 0, the privileged
# flag on CI job containers (runner configmap), and the old
# chmod-666 socket race.
#
# Consequence: this Deployment cannot live in namespace
# `forgejo` (PSA enforce: baseline there). All three runners,
# their PVCs and the prune CronJob live in `forgejo-runners`,
# which enforces PSA at `privileged` by design — keep that
# namespace free of anything but this CI capsule.
privileged: true
volumeMounts:
- name: dind-run

View file

@ -2,7 +2,7 @@ apiVersion: apps/v1
kind: Deployment
metadata:
name: forgejo-runner-arm64
namespace: forgejo
namespace: forgejo-runners
labels:
app: forgejo-runner
arch: arm64
@ -136,6 +136,8 @@ spec:
# is forbidden by Pod Security baseline).
# What *is* removed: privileged job containers (runner configmap),
# the runner's uid 0, and the host docker socket (no hostPath).
# This pod lives in namespace forgejo-runners (enforce:
# privileged), not forgejo (enforce: baseline) — see runner-amd64.yaml.
privileged: true
volumeMounts:
- name: dind-run

View file

@ -2,7 +2,7 @@ apiVersion: v1
kind: ConfigMap
metadata:
name: forgejo-runner-config
namespace: forgejo
namespace: forgejo-runners
data:
arm64.toml: |
log:

View file

@ -19,7 +19,7 @@ apiVersion: apps/v1
kind: Deployment
metadata:
name: forgejo-runner-deploy-arm64
namespace: forgejo
namespace: forgejo-runners
labels:
app: forgejo-runner
arch: arm64
@ -148,6 +148,8 @@ spec:
# 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 forgejo-runners (enforce: privileged),
# not forgejo (enforce: baseline) — see runner-amd64.yaml.
privileged: true
volumeMounts:
- name: dind-run

View file

@ -64,7 +64,7 @@ apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: forgejo-runner-arm64-dind
namespace: forgejo
namespace: forgejo-runners
labels:
app: forgejo-runner
arch: arm64
@ -108,7 +108,7 @@ apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: forgejo-runner-deploy-arm64-dind
namespace: forgejo
namespace: forgejo-runners
labels:
app: forgejo-runner
role: deploy

View file

@ -0,0 +1,31 @@
apiVersion: v1
kind: Namespace
metadata:
name: forgejo-runners
# The Forgejo Actions CI capsule: three runner Deployments (each with a
# privileged docker-in-docker sidecar), their data PVCs, and the nightly
# prune CronJob (hostPath `/var/run/docker.sock`).
#
# `enforce: privileged` is deliberate and is the whole point of this
# namespace existing. Pod Security has no per-workload exception: if these
# pods share `forgejo`, that namespace can only ever be warn/audit, i.e. no
# namespace in the cluster enforces anything. Isolating the capsule here lets
# `forgejo` enforce `baseline` (Forgejo, Postgres, backups) while this
# namespace keeps the one shape that genuinely needs node root and is
# labelled as such in Git.
#
# This is containment, not a grant of new privilege: the dind sidecar was
# already privileged, and CI job containers are unprivileged
# (`container.privileged: false` in the runner ConfigMap). Keep this
# namespace free of anything that is not part of the CI capsule, and give it
# its own NetworkPolicy/RBAC scope rather than widening it.
#
# warn/audit at `restricted` still print and record every violation, so a new
# privileged/hostPath pod here is visible even though it is admitted.
labels:
pod-security.kubernetes.io/enforce: privileged
pod-security.kubernetes.io/enforce-version: latest
pod-security.kubernetes.io/warn: restricted
pod-security.kubernetes.io/warn-version: latest
pod-security.kubernetes.io/audit: restricted
pod-security.kubernetes.io/audit-version: latest

View file

@ -4,7 +4,7 @@ data:
kind: Secret
metadata:
name: forgejo-runner-amd64-token
namespace: forgejo
namespace: forgejo-runners
type: Opaque
sops:
age:
@ -18,6 +18,6 @@ sops:
-----END AGE ENCRYPTED FILE-----
recipient: age12zdn7x72zrgu9cdv8wdj7xfx42nz09nrwpc2g09cwx5fwdm0ry6qp5h4jp
encrypted_regex: ^(data|stringData)$
lastmodified: "2026-11-27T05:16:42Z"
mac: ENC[AES256_GCM,data:ew8vSr7GtItgOJfbvZAPWd/gQrSnMP+FNNx0P2AWBx+miBsj8sWckGqgHwVzgIPTDh9kjX4bz2i78HYR6sfDMTYPIbxTQJH/7bzhmBWDqQcb2MklE6Gn/vF6qiTn1GimPIn5xuxfyEJCIBQKzNDp3oMqvBPqQhwes4KnCgkZF4A=,iv:HzNfofZIpPEijLRqbb4/5OttlksbAWE9DY4L9HUKB+g=,tag:ucrfUYY8dKHOU33yF1WXnA==,type:str]
lastmodified: "2026-11-27T06:12:09Z"
mac: ENC[AES256_GCM,data:F0c0O4Nq6rUEKepp75smiiLz1dbwtvGpHXBkWqZ6NQhwZPyb/nPKcW+uyZZRHPtgt7qsMVe3ETu8p0PNflI6v5D6TesEwOsnhAoff+fjS+CgUUl8wEW4o4mK0uHsYoN7BJ2yog238LGEqkqU4t7yj0xBbBR4gicN3Dhkuhb++Io=,iv:B9Kqk7oPL8Miip6viXU7HJnUBHlf866+E47sC+BsaaA=,tag:r3/z+/4aIlWrdUaO9nt8aQ==,type:str]
version: 3.13.3

View file

@ -4,7 +4,7 @@ data:
kind: Secret
metadata:
name: forgejo-runner-deploy-arm64-token
namespace: forgejo
namespace: forgejo-runners
type: Opaque
sops:
age:
@ -18,6 +18,6 @@ sops:
-----END AGE ENCRYPTED FILE-----
recipient: age12zdn7x72zrgu9cdv8wdj7xfx42nz09nrwpc2g09cwx5fwdm0ry6qp5h4jp
encrypted_regex: ^(data|stringData)$
lastmodified: "2026-11-27T05:16:42Z"
mac: ENC[AES256_GCM,data:1RxSAz4VP9qtxi9AcBxgXhb/ynWuHTj1Cor/A4igCapedCchKCjCcfjBfJgnwilDmQSvZ27VT8sBVwGnzmI05zrfPrhiV39xXtyyNmoVwjU8XBoNrRZMYN5Sow5/1JWhf0NqdoofJ/JTsVg4hyRiPvRQ9xRG1gldjsbVH4XNy34=,iv:UZg6/yBdf4LamyLPjXPiGQYIE/7aJAzSk9MvWHLHMhs=,tag:Rgt9HjB5RANsDouByPtIQQ==,type:str]
lastmodified: "2026-11-27T06:12:09Z"
mac: ENC[AES256_GCM,data:HcIUcXyxgkJyaQiQVUWdMSYDWWgltavFC5RtKn/+vWJ2Lm8tyXgqLCpmEuFxkYwf+WyQrqmyi++0EzMfBxnsRAE+b7U5PS5VqX+pvq0nD4SAPMSm1B+cXz/zrHAzLBVXHHhOzvK8yJtTXqb9iM89bagXiwFIVNCuvhwzDACtX3k=,iv:m3Lb4CiRz0nEOVLUI6MdtUuPTGx2b8zeFE6Mvkb9EIg=,tag:zOHLyo3Uv1uTMQayMywjOQ==,type:str]
version: 3.13.3