Container Has runAsNonRoot & Image Runs as Root
Fix Pod Security Standards Restricted rejection when an image defaults to UID 0.
Root Cause
Pod securityContext enforces runAsNonRoot: true, but the container image metadata specifies USER root (or omits USER) without a numeric runAsUser in the manifest.
How to Fix
- Set a numeric USER (e.g. USER 10001:10001) in the Dockerfile, or set securityContext.runAsUser: 10001 in the Pod manifest.
- Ensure the app binds to an unprivileged port (>1024, such as 8080) instead of port 80/443.
- Mount an emptyDir volume at /tmp or cache paths if readOnlyRootFilesystem: true is enabled.
Diagnostic Commands
kubectl get pod <pod> -n <ns> -o jsonpath="{.spec.securityContext}"