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

Merged
sirius merged 1 commit from wt/t_2bbe34a8 into master 2026-11-27 06:15:45 +00:00
Owner

What and why

Finding F6 (cluster netsec audit): every Forgejo runner ran a privileged: true dind sidecar with the runner container as uid 0, and no namespace in the cluster enforced Pod Security, so the next privileged pod would also be accepted silently.

A container runtime cannot run unprivileged in a pod on these nodes (measured three ways — cgroup fs mounted read-only, rootless dind cannot mount procfs, procMount: Unmasked needs hostUsers: false where subuid maps and /dev/net/tun are refused; see docs/pod-security.md). PSA has no per-workload exemption, so the only way to make any namespace enforce is to put the CI capsule somewhere that is allowed to be privileged.

This PR does exactly that:

  • new namespace forgejo-runners with enforce: privileged + warn/audit: restricted — contains the three runner Deployments, their PVCs, forgejo-runner-config, the two registration-token Secrets, and the prune SA/Role/RoleBinding/ConfigMap/CronJob;
  • namespace forgejo now enforces baseline (+ warn/audit restricted). Forgejo, the CNPG Postgres cluster and the cluster-backup CronJob all pass baseline (verified by server-side dry-run before flipping);
  • runner/prune monitoring queries and runbooks follow the move (cnpg_actions_* panels keep namespace="forgejo" — that label is the Postgres namespace);
  • docs/pod-security.md rewritten for the two enforced namespaces; stale runner rows in docs/cluster-overview.md and the commands in docs/arm64-runner-dind.md updated.

No privileged flag, hostPath or image was added anywhere; job containers stay unprivileged (container.privileged: false).

Storage was rebound, not recreated

runner.ini (the registration uuid) and the dind data-roots live on the PVCs. The two static local-static PVs on rpi and the dynamic local-path PV on siriussec were kept and rebound to the new claims by name:

  • static PVs: deleted the old PVCs (Retain), cleared claimRef, re-created the PVCs with the same volumeName;
  • amd64 PV: patched reclaimPolicy: Retain for the move, deleted/recreated the claim, then restored Delete.

Proof after the move: all three runner.ini uuids unchanged (91124ee3…, 4e07c1e9…, a41aad73…), dind image counts identical (19 / 2 / 31), canary files written before the move still present, all three runners 2/2 Running and polling Forgejo within seconds.

Acceptance

  1. kubectl -n forgejo get pods -o jsonpath='{..securityContext.privileged}' → false false (no true).
  2. Runner containers run as uid 1000 (image user); dind socket 0660 root:1000 via dockerd --group 1000.
  3. kubectl get ns forgejo -o jsonpath='{.metadata.labels}' includes pod-security.kubernetes.io/enforce: baseline; a privileged pod there is now Forbidden: violates PodSecurity "baseline:latest", while the same shape is admitted (with warnings) in forgejo-runners.
  4. A real CI image build completes after the change — run URL in the kanban card t_2bbe34a8.
  5. Every namespace carries warn/audit: restricted (cluster-owned ones out-of-band; flux-system audit label added now).

Rebased onto master after PR #70 (recursive actions-cache re-own) landed: this branch keeps that fix untouched and only moves the manifests' namespace/comments.

## What and why Finding F6 (cluster netsec audit): every Forgejo runner ran a `privileged: true` dind sidecar with the runner container as uid 0, and **no namespace in the cluster enforced Pod Security**, so the next privileged pod would also be accepted silently. A container runtime cannot run unprivileged in a pod on these nodes (measured three ways — cgroup fs mounted read-only, rootless dind cannot mount procfs, `procMount: Unmasked` needs `hostUsers: false` where subuid maps and `/dev/net/tun` are refused; see `docs/pod-security.md`). PSA has no per-workload exemption, so the only way to make *any* namespace enforce is to put the CI capsule somewhere that is allowed to be privileged. This PR does exactly that: * new namespace **`forgejo-runners`** with `enforce: privileged` + `warn`/`audit: restricted` — contains the three runner Deployments, their PVCs, `forgejo-runner-config`, the two registration-token Secrets, and the prune SA/Role/RoleBinding/ConfigMap/CronJob; * namespace **`forgejo`** now enforces **`baseline`** (+ warn/audit restricted). Forgejo, the CNPG Postgres cluster and the cluster-backup CronJob all pass baseline (verified by server-side dry-run before flipping); * runner/prune monitoring queries and runbooks follow the move (`cnpg_actions_*` panels keep `namespace="forgejo"` — that label is the Postgres namespace); * `docs/pod-security.md` rewritten for the two enforced namespaces; stale runner rows in `docs/cluster-overview.md` and the commands in `docs/arm64-runner-dind.md` updated. No privileged flag, hostPath or image was added anywhere; job containers stay unprivileged (`container.privileged: false`). ## Storage was rebound, not recreated `runner.ini` (the registration uuid) and the dind data-roots live on the PVCs. The two static `local-static` PVs on rpi and the dynamic local-path PV on siriussec were kept and rebound to the new claims by name: * static PVs: deleted the old PVCs (Retain), cleared `claimRef`, re-created the PVCs with the same `volumeName`; * amd64 PV: patched `reclaimPolicy: Retain` for the move, deleted/recreated the claim, then restored `Delete`. Proof after the move: all three `runner.ini` uuids unchanged (`91124ee3…`, `4e07c1e9…`, `a41aad73…`), dind image counts identical (19 / 2 / 31), canary files written before the move still present, all three runners `2/2 Running` and polling Forgejo within seconds. ## Acceptance 1. `kubectl -n forgejo get pods -o jsonpath='{..securityContext.privileged}'` → `false false` (no `true`). 2. Runner containers run as uid 1000 (image user); dind socket `0660 root:1000` via `dockerd --group 1000`. 3. `kubectl get ns forgejo -o jsonpath='{.metadata.labels}'` includes `pod-security.kubernetes.io/enforce: baseline`; a privileged pod there is now `Forbidden: violates PodSecurity "baseline:latest"`, while the same shape is admitted (with warnings) in `forgejo-runners`. 4. A real CI image build completes after the change — run URL in the kanban card `t_2bbe34a8`. 5. Every namespace carries `warn`/`audit: restricted` (cluster-owned ones out-of-band; `flux-system` audit label added now). > Rebased onto master after PR #70 (recursive actions-cache re-own) landed: this branch keeps that fix untouched and only moves the manifests' namespace/comments.
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).
sirius merged commit 77041b35ac into master 2026-11-27 06:15:45 +00:00
sirius deleted branch wt/t_2bbe34a8 2026-11-27 06:15:45 +00:00
Sign in to join this conversation.
No reviewers
No labels
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
sirius/homek8s!72
No description provided.