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:
parent
0fdd918875
commit
3d21e96a9c
18 changed files with 239 additions and 127 deletions
|
|
@ -1,22 +1,25 @@
|
|||
# Pod Security posture (2026-11-27)
|
||||
|
||||
Status of Pod Security Admission (PSA) labels per namespace, why some namespaces
|
||||
enforce and others only warn/audit, and the one workload that cannot be
|
||||
de-privileged on these nodes.
|
||||
Status of Pod Security Admission (PSA) labels per namespace, why one workload
|
||||
still needs `privileged`, and what is enforced where. Two namespaces now
|
||||
*enforce*, not just warn: `forgejo` at `baseline` and the CI capsule
|
||||
`forgejo-runners` at `privileged`.
|
||||
|
||||
## Levels in use
|
||||
|
||||
| level | namespaces |
|
||||
|---|---|
|
||||
| `enforce: baseline` + `warn`/`audit: restricted` | `customer1`, `metabase`, `osint`, `piedmont`, `secops`, `sirius-growth`, `siriusdevops`, `cert-manager` |
|
||||
| `warn`/`audit: restricted` only | `forgejo`, `netsec`, `monitoring`, `node-io`, `internal`, `gateway-system`, `local-path-storage`, plus cluster-owned `kube-system`, `kube-public`, `kube-node-lease`, `default`, `cnpg-system`, `cilium-secrets`, `logging`, `flux-system` |
|
||||
| `enforce: baseline` + `warn`/`audit: restricted` | `cert-manager`, `customer1`, `forgejo`, `metabase`, `osint`, `piedmont`, `secops`, `sirius-growth`, `siriusdevops` |
|
||||
| `enforce: privileged` + `warn`/`audit: restricted` | `forgejo-runners` (the Actions CI capsule), `logging` |
|
||||
| `warn`/`audit: restricted` only | `netsec`, `monitoring`, `node-io`, `internal`, `gateway-system`, `local-path-storage`, plus cluster-owned `kube-system`, `kube-public`, `kube-node-lease`, `default`, `cnpg-system`, `cilium-secrets`, `flux-system` |
|
||||
|
||||
The enforced set was picked by reading the live pods first: every namespace in
|
||||
it had zero baseline violations (no `privileged`, no `hostNetwork`/`hostPID`/
|
||||
`hostIPC`, no `hostPath`, no `hostPort`, no capability additions, no
|
||||
`seccompProfile: Unconfined`) on 2026-11-27. Enforcement is per *pod creation*,
|
||||
so a namespace that later needs one of those shapes has to be moved to
|
||||
warn/audit deliberately, with a comment, instead of being allowed by accident.
|
||||
The enforced set was picked by reading the live workload templates first: every
|
||||
namespace in it had zero baseline violations (no `privileged`, no
|
||||
`hostNetwork`/`hostPID`/`hostIPC`, no `hostPath`, no `hostPort`, no capability
|
||||
additions, no `seccompProfile: Unconfined`) on 2026-11-27. Enforcement is per
|
||||
*pod creation*, so a namespace that later needs one of those shapes has to be
|
||||
moved to warn/audit deliberately, with a comment in Git, instead of being
|
||||
allowed by accident.
|
||||
|
||||
The warn/audit-only set is the opposite list — each one hosts a workload that
|
||||
baseline forbids today:
|
||||
|
|
@ -25,12 +28,11 @@ baseline forbids today:
|
|||
|---|---|
|
||||
| `kube-system` | Cilium agent/envoy (hostNetwork, hostPath, privileged init, hostPorts), static control-plane pods |
|
||||
| `monitoring` | node-exporter (hostNetwork + hostPID + hostPath `/proc`,`/sys`,`/`) |
|
||||
| `logging` | Alloy DaemonSet (hostPath `/var/log`, journal, machine-id) |
|
||||
| `logging` | Alloy DaemonSet (hostPath `/var/log`, journal, machine-id) — enforced at `privileged` because the shape is expected |
|
||||
| `netsec` | hubble-flow-collector (hostPath socket + log dir) |
|
||||
| `node-io` | etcd-io-guard (privileged, hostPID, hostPath) |
|
||||
| `local-path-storage` | provisioner helper pods are privileged (created on every PVC) |
|
||||
| `internal`, `gateway-system` | reserved for hostNetwork Cilium Gateway listeners |
|
||||
| `forgejo` | Actions runner dind sidecars, see below |
|
||||
|
||||
`kube-system`, `kube-public`, `kube-node-lease`, `default`, `cnpg-system`,
|
||||
`cilium-secrets`, `logging` and `flux-system` are not declared in this repo
|
||||
|
|
@ -47,13 +49,61 @@ for ns in kube-system kube-public kube-node-lease default cnpg-system cilium-sec
|
|||
done
|
||||
```
|
||||
|
||||
## Why the Forgejo CI runners are still `privileged`
|
||||
## The Forgejo CI capsule (`forgejo-runners`)
|
||||
|
||||
The three runner Deployments (`forgejo-runner-amd64`, `forgejo-runner-arm64`,
|
||||
`forgejo-runner-deploy-arm64`) keep a docker-in-docker sidecar with
|
||||
`privileged: true`. That is the reason `forgejo` is not in the enforced set:
|
||||
baseline rejects those pods at admission, so enforcing it would break Actions
|
||||
rather than harden it.
|
||||
The three Actions runners (`forgejo-runner-amd64`, `forgejo-runner-arm64`,
|
||||
`forgejo-runner-deploy-arm64`) each carry a docker-in-docker sidecar with
|
||||
`privileged: true`, and the nightly prune CronJob mounts the Pi's host
|
||||
`/var/run/docker.sock`. PSA has no per-workload exception, and baseline rejects
|
||||
both shapes (`privileged`, `hostPath`) at admission. While those pods lived in
|
||||
`forgejo`, that namespace could only ever be warn/audit — which is why
|
||||
originally *nothing* in the cluster enforced.
|
||||
|
||||
The fix is the first option that was open: the **CI capsule moved to its own
|
||||
namespace**, `apps/base/forgejo/runner-namespace.yaml`, which enforces PSA at
|
||||
`privileged` *on purpose*, and `forgejo` now enforces `baseline`. This is
|
||||
containment, not a new grant: the dind sidecar was already privileged. What the
|
||||
split buys:
|
||||
|
||||
* `forgejo` (Forgejo itself, the CNPG Postgres cluster, the nightly
|
||||
cluster-backup CronJob) is now protected by admission — a future privileged,
|
||||
hostPath or hostNetwork pod added there is rejected instead of silently
|
||||
accepted;
|
||||
* the only namespace allowed to run a privileged pod is the one whose name says
|
||||
so, labelled as such in Git, and it holds nothing but the CI capsule;
|
||||
* the capsule keeps `warn`/`audit: restricted`, so every privileged/hostPath
|
||||
pod there is still printed and recorded as an audit annotation.
|
||||
|
||||
What is inside `forgejo-runners`: the three runner Deployments, their PVCs
|
||||
(`forgejo-runner-amd64` on siriussec's local-path, `forgejo-runner-arm64-dind`
|
||||
200 Gi and `forgejo-runner-deploy-arm64-dind` 40 Gi as static Retain PVs on
|
||||
rpi), the `forgejo-runner-config` ConfigMap, the two registration-token
|
||||
Secrets, and the prune ServiceAccount/Role/RoleBinding/ConfigMap/CronJob. The
|
||||
capsule's Deployments use the namespace's `default` ServiceAccount, which has
|
||||
**no** RBAC; only the prune Job can `get/list` pods and `create pods/exec`, and
|
||||
only in this namespace.
|
||||
|
||||
What was already removed from the runner shape (same change, card
|
||||
`t_2bbe34a8`):
|
||||
|
||||
* the runner container no longer runs as uid 0 — it uses the image's uid 1000,
|
||||
and the dind socket is created `0660 root:1000` via `dockerd --group 1000`
|
||||
(which also removes the old one-shot `chmod 666` race that forced root);
|
||||
* CI **job** containers are no longer privileged (`container.privileged: false`
|
||||
in the runner ConfigMap) — previously every job container was privileged
|
||||
inside a privileged dind;
|
||||
* the runners have no `hostPath`, no `hostNetwork` and no host docker socket;
|
||||
the only hostPath left in the capsule is the prune Job's Pi socket.
|
||||
|
||||
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.
|
||||
|
||||
## Why the dind sidecar keeps `privileged` (measured, do not re-derive)
|
||||
|
||||
Three independent attempts to drop the flag were measured live on 2026-11-27
|
||||
(siriussec, kernel 6.18.50-lts; rpi reproduced the procfs failure):
|
||||
|
|
@ -77,20 +127,19 @@ Three independent attempts to drop the flag were measured live on 2026-11-27
|
|||
/dev/net/tun` is refused, so rootless dind has neither a uid map nor the
|
||||
tun device it needs for networking.
|
||||
|
||||
What *was* removed in the same change:
|
||||
## Verification
|
||||
|
||||
* the runner container no longer runs as uid 0 — it uses the image's uid 1000,
|
||||
and the dind socket is created `0660 root:1000` via `dockerd --group 1000`
|
||||
(which also removes the old one-shot `chmod 666` race that forced root);
|
||||
* CI **job** containers are no longer privileged (`container.privileged: false`
|
||||
in the runner ConfigMap) — previously every job container was privileged
|
||||
inside a privileged dind;
|
||||
* there is still no `hostPath`, no `hostNetwork` and no host docker socket in
|
||||
any runner pod.
|
||||
```sh
|
||||
# no privileged container left in the Forgejo namespace (empty output = pass)
|
||||
kubectl -n forgejo get pods -o jsonpath='{..securityContext.privileged}'
|
||||
|
||||
Remaining options for dropping `privileged` (each needs a design decision, not
|
||||
a manifest edit): move the runner Deployments into their own
|
||||
`pod-security.kubernetes.io/enforce: privileged` namespace so `forgejo` can
|
||||
enforce baseline; exempt the runner ServiceAccount from PSA via the API server
|
||||
`AdmissionConfiguration`; or introduce a runtime that virtualises the container
|
||||
runtime (sysbox / gVisor) and a matching `RuntimeClass`.
|
||||
# forgejo enforces baseline; the capsule is explicitly privileged + audited
|
||||
kubectl get ns forgejo forgejo-runners -o jsonpath='{range .items[*]}{.metadata.name}{" "}{.metadata.labels}{"\n"}{end}'
|
||||
|
||||
# admission really rejects the shape in forgejo (expect Forbidden)
|
||||
kubectl -n forgejo run probe-bad --image=busybox --restart=Never \
|
||||
--overrides='{"spec":{"containers":[{"name":"p","image":"busybox","securityContext":{"privileged":true}}]}}'
|
||||
|
||||
# the prune CronJob (and its RBAC) now live in the capsule
|
||||
kubectl -n forgejo-runners get cronjob,role,rolebinding,sa -l app=forgejo-runner
|
||||
```
|
||||
|
|
|
|||
Loading…
Reference in a new issue