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

@ -46,6 +46,9 @@ spec:
operator: Equal
value: network
effect: PreferNoSchedule
# Group on the data volume, matching the runner gid (see fix-data-perms).
securityContext:
fsGroup: 1000
initContainers:
# Registration guard, NOT a registration step. The runner's identity
# (`runner.ini`, action_runner id 14 / uuid a41aad73-…) is copied onto
@ -73,6 +76,28 @@ spec:
volumeMounts:
- 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.
- name: fix-data-perms
image: docker:27-dind
imagePullPolicy: IfNotPresent
securityContext:
runAsUser: 0
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
@ -86,12 +111,13 @@ spec:
# so without this `docker push 10.10.0.1:5000/...` from a job
# fails with "server gave HTTP response to HTTPS client".
dockerd --host=unix:///var/run/docker.sock --tls=false --mtu=1420 \
--group 1000 \
--insecure-registry=10.10.0.1:5000 &
pid=$!
i=0
while [ "$i" -lt 30 ]; do
# Readiness only: ownership is set by `dockerd --group 1000`.
if [ -S /var/run/docker.sock ]; then
chmod 666 /var/run/docker.sock
break
fi
i=$((i+1))
@ -99,6 +125,10 @@ spec:
done
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.
privileged: true
volumeMounts:
- name: dind-run
@ -125,7 +155,11 @@ spec:
image: code.forgejo.org/forgejo/runner:5.0.1
imagePullPolicy: IfNotPresent
securityContext:
runAsUser: 0
# Image default user. The dind socket is 0660 root:1000
# (`dockerd --group 1000`) and fix-data-perms owns the PVC as
# 1000:1000, so no root is needed here.
runAsUser: 1000
runAsGroup: 1000
command:
- sh
- -c