Pod Security Admission prüft nur, ob runAsNonRoot true gesetzt ist. Ob das Image wirklich als Nicht-Root startet, merkt erst das kubelet vor dem Start des Containers. Läuft das Image als root, bleibt der Pod in CreateContainerConfigError.
Symptom
k -n tag09-strict apply -f shell.yaml pod/shell created NAME READY STATUS RESTARTS AGE shell 0/1 CreateContainerConfigError 0 7s
Der Pod wird angenommen – auch im Namespace mit enforce restricted. Der Fehler kommt erst beim Erzeugen des Containers.
Diagnose
Die Meldung steht in den Events des Pods.
k -n tag09-strict describe pod shell | grep -m1 'Error:' ... Error: container has runAsNonRoot and image will run as root (pod: "shell_tag09-strict(b26d…)", container: c)
Ursachen
busyboxDas Image hat keinen USER
busybox hat keinen USER und startet deshalb als root. runAsNonRoot verbietet das, nennt aber keinen anderen Benutzer.
Uid 65532Zum Vergleich – ein Image mit eigenem Benutzer
notes-api läuft als 65532 und startet im selben Namespace mit runAsNonRoot ohne Fehler. Entscheidend ist der Benutzer, mit dem das Image startet.
k -n tag09-strict exec deploy/notes -- \ grep -E '^Uid|CapEff|NoNewPrivs|Seccomp:' /proc/1/status Uid: 65532 65532 65532 65532
Lösung
k -n tag09-strict delete pod shell --now sed -i 's/^ runAsNonRoot: true/&\n runAsUser: 1000/' shell.yaml k -n tag09-strict apply -f shell.yaml k -n tag09-strict wait --for=condition=Ready pod/shell k -n tag09-strict exec shell -- id pod/shell condition met uid=1000 gid=0(root) groups=0(root)
Nicht tun: runAsNonRoot entfernen, damit der Pod startet. Im Namespace mit restricted lehnt die Admission ihn dann ab.
CKS zum Anfassen, Tag 9: Pod Security Admission mit warn, audit und enforce, Verstöße beheben und runAsNonRoot.
Zu Tag 9 →
Häufige Fragen
Warum lässt Pod Security Admission den Pod durch?
PSA prüft nur, ob runAsNonRoot true gesetzt ist, nicht den Benutzer im Image.