secops(f6): de-privilege CI job containers + runner uid, add Pod Security labels (#54)

This commit is contained in:
sirius 2026-11-27 05:42:39 +00:00
commit cb387a8121
20 changed files with 349 additions and 8 deletions

View file

@ -36,7 +36,9 @@ spec:
nodeSelector:
kubernetes.io/hostname: siriussec
securityContext:
fsGroup: 0
# Group on the data volume; matches the runner's gid so the cache dir
# stays writable even before fix-data-perms re-owns it.
fsGroup: 1000
initContainers:
- name: register
image: alex3305/forgejo-runner-dind:13-dind-rootless-28
@ -68,6 +70,32 @@ spec:
subPath: amd64.toml
- name: data
mountPath: /data
# The runner container runs as uid 1000 (the image's own user) and needs
# to read its registration and write the actions cache on this PVC.
# Both were created by root before this change, so re-own them once per
# start. Scoped on purpose: a recursive chown of the whole PVC would
# walk the dind data-root (tens of GB on the Pi).
- name: fix-data-perms
image: docker:27-dind
imagePullPolicy: IfNotPresent
securityContext:
# The image's own user. No root needed: the dind socket is created
# 0660 root:1000 by `dockerd --group 1000`, and fix-data-perms
# re-owns the PVC as 1000:1000 so the actions cache is writable.
runAsUser: 1000
runAsGroup: 1000
command:
- sh
- -c
- |
set -e
chown 1000:1000 /data
[ -f /data/runner.ini ] && chown 1000:1000 /data/runner.ini
[ -d /data/cache ] && chown -R 1000:1000 /data/cache
true
volumeMounts:
- name: data
mountPath: /data
containers:
- name: dind
image: docker:27-dind
@ -92,12 +120,14 @@ spec:
# layer uploads >~100MB, so in-cluster pushes are the reliable
# path for large images.
dockerd --host=unix:///var/run/docker.sock --tls=false --mtu=1420 \
--group 1000 \
--insecure-registry=forgejo.forgejo.svc.cluster.local:3000 &
pid=$!
i=0
while [ "$i" -lt 30 ]; do
# Readiness only: ownership is set by `dockerd --group 1000`
# (socket 0660 root:1000) so the runner's uid 1000 can use it.
if [ -S /var/run/docker.sock ]; then
chmod 666 /var/run/docker.sock
break
fi
i=$((i+1))
@ -105,6 +135,25 @@ spec:
done
wait "$pid"
securityContext:
# Cannot be dropped on these nodes. Verified live 2026-11-27
# (card t_2bbe34a8): a pod with `privileged: false` cannot host a
# container runtime in this cluster, at three independent points:
# 1. dind's own containers need CAP_SYS_ADMIN: runc mounts a fresh
# procfs per container, and without the capability the daemon
# fails with `mount src=proc ... operation not permitted`.
# 2. kubelet mounts /sys/fs/cgroup read-only for non-privileged
# pods, so dockerd cannot create /sys/fs/cgroup/docker
# ("read-only file system") and no container can start.
# 3. rootless dind (docker:27-dind-rootless) dies earlier: a
# nested user namespace cannot mount procfs because the pod's
# /proc is masked (kernel mount_too_revealing), and
# procMount: Unmasked is only accepted with hostUsers: false —
# where newuidmap cannot map subuids and /dev/net/tun cannot be
# created (mknod is refused in a userns pod, and hostPath is
# forbidden under Pod Security baseline).
# 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.
privileged: true
volumeMounts:
- name: dind-run