secops(f6): de-privilege CI job containers + runner uid, add Pod Security labels (#54)
This commit is contained in:
parent
9822647bf9
commit
cb387a8121
20 changed files with 349 additions and 8 deletions
|
|
@ -23,6 +23,10 @@ spec:
|
|||
spec:
|
||||
nodeSelector:
|
||||
kubernetes.io/hostname: rpi
|
||||
# Group on the data volume; matches the runner gid so the actions cache
|
||||
# stays writable after fix-data-perms re-owns it.
|
||||
securityContext:
|
||||
fsGroup: 1000
|
||||
tolerations:
|
||||
- key: dedicated
|
||||
operator: Equal
|
||||
|
|
@ -31,6 +35,33 @@ spec:
|
|||
# No supplementalGroups: there is no host docker socket and no host
|
||||
# docker gid to match any more. The only daemon this runner talks to is
|
||||
# the privileged `dind` sidecar below.
|
||||
# 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:
|
||||
# Image default user (uid 1000). No root needed: the dind socket is
|
||||
# 0660 root:1000 (dockerd --group 1000) and fix-data-perms owns the
|
||||
# PVC as 1000:1000.
|
||||
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:
|
||||
# In-pod Docker daemon. Same shape as forgejo-runner-amd64: privileged,
|
||||
# socket on an emptyDir shared with the runner, data-root on the PVC.
|
||||
|
|
@ -58,12 +89,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))
|
||||
|
|
@ -71,6 +103,23 @@ 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 containers need CAP_SYS_ADMIN (runc mounts a fresh
|
||||
# procfs per container).
|
||||
# 2. kubelet mounts /sys/fs/cgroup read-only for non-privileged
|
||||
# pods, so dockerd cannot create /sys/fs/cgroup/docker
|
||||
# ("read-only file system") — 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 allowed with hostUsers: false,
|
||||
# where newuidmap cannot map subuids, and /dev/net/tun cannot
|
||||
# be created (mknod is refused inside a userns pod; hostPath
|
||||
# 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).
|
||||
privileged: true
|
||||
volumeMounts:
|
||||
- name: dind-run
|
||||
|
|
|
|||
Loading…
Reference in a new issue