Skip to main content

More Info:

Verifies runAsNonRoot is set at pod or container level. Running as root inside a container widens the impact of a container escape.

Risk Level

High

Address

Security

Compliance Standards

  • Cloudanix Best Practice

Triage and Remediation

Remediation

Manual Steps

  1. Identify non-compliant pods (run on any machine with kubectl access):
  2. For standalone Pods (not controlled by a higher-level object), export, edit, and re-apply the manifest (run on any machine with kubectl access). Example for one pod:
    Edit /tmp/pod-POD_NAME.yaml and add or adjust at the pod spec level:
    or, if you cannot set it at pod level, add it to every container and initContainer:
    Then re-create the pod (Pods are immutable):
  3. For pods owned by a controller (Deployment/ReplicaSet/StatefulSet/DaemonSet/Job/CronJob), edit the controller so all future pods are compliant (run on any machine with kubectl access). Example for a Deployment:
    In the editor, under spec.template.spec, set:
    If needed, also set on each container:
    Save and exit; Kubernetes will roll out updated pods.
  4. Repeat step 3 for other controllers (StatefulSet, DaemonSet, Job, CronJob) that own non-compliant pods, using kubectl edit on the appropriate resource type and setting spec.template.spec.securityContext.runAsNonRoot: true or per-container securityContext.runAsNonRoot: true.
  5. If any image fails to start with runAsNonRoot: true, review that image on your image build system: ensure the container’s default user is non-root (e.g., via a USER directive in the Dockerfile) or explicitly set a non-root runAsUser together with runAsNonRoot: true in the pod spec, then redeploy.
  6. Verify compliance (run on any machine with kubectl access):
On any machine with kubectl access:
  1. Identify non-compliant Pods
  1. Edit each affected workload manifest and set pod-level runAsNonRoot: true (preferred). For example, for a Deployment owning the Pod:
Under spec.template.spec, ensure:
If you cannot set it at pod level (e.g., mixed containers), set it on each container instead:
Apply the same pattern to other controllers (StatefulSet, DaemonSet, Job, CronJob) using:
For standalone Pods managed directly (not recommended in GKE production), edit and re-apply:
Edit /tmp/pod.yaml to include:
Then delete and recreate:
  1. Verification
Run the benchmark audit command again from any machine with kubectl access: