Skip to content

runAsNonRoot and non-numeric user: pod stuck in CreateContainerConfigError

Kubernetestested on kind v0.33.0, Kubernetes v1.37.0

The pod is created but never comes up: status CreateContainerConfigError. The kubelet has to enforce runAsNonRoot, but the image only names its user (USER node). Without a number the kubelet cannot prove it is not root.

Symptom

kubectl get pods -l app.kubernetes.io/name=web
NAME                   READY   STATUS                       RESTARTS   AGE
web-79cdcdcd9c-qmw5p   0/1     CreateContainerConfigError   0          15s
web-857bcf49dc-cc95h   1/1     Running                      0          4m57s
web-857bcf49dc-xpkxw   1/1     Running                      0          4m57s

The new pod with a hardened securityContext gets stuck, the old ones keep running. The rollout stands still, the application notices nothing.

Diagnosis

The events with reason Failed name the cause verbatim.

kubectl get events --field-selector reason=Failed -o custom-columns=MSG:.message
Error: container has runAsNonRoot and image has non-numeric user (node), cannot
verify user is non-root (pod: "web-79cdcdcd9c-qmw5p_notes(…)", container: web)

Causes

USER nodeThe image sets a user name instead of a UID

The Node image sets USER node. The kubelet does not look into the image's /etc/passwd and therefore cannot check whether node has UID 0.

runAsNonRoot without runAsUserrunAsNonRoot needs a number it can verify

runAsNonRoot: true alone is only enough if the image sets a numeric UID. The same error hits every image with a name in USER, in the course also curlimages/curl (curl_user, UID 100).

Fix

Name the UID in the pod's own securityContext – 1000 in the course, as id showed in the container before. After that the rollout completes.
securityContext:
  runAsNonRoot: true
  runAsUser: 1000
  runAsGroup: 1000
kubectl apply -f k8s/web.yaml
deployment.apps/web configured
service/web unchanged
kubectl rollout status deploy/web --timeout 120s
deployment "web" successfully rolled out

Don't: Removing runAsNonRoot to make the pod start. Under Pod Security “restricted” admission then rejects it.

▶
Break it yourself and find it – free
Kubernetes hands-on, Day 8: every pod under Pod Security “restricted” – no root, no capabilities, read-only.
Go to day 8 →

FAQ

Where do I get the right UID?

From the running container with id, or from the image's Dockerfile. In the course id shows uid=1000(node).

Does this only affect the Node image?

No, every image that sets a name instead of a number in USER.

Why did admission not reject the pod?

Pod Security only checks the manifest. What is in the image is only seen by the kubelet at start.

Related error patterns

More