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 a standalone Pod (no owner/controller), edit the Pod manifest to set runAsNonRoot: true at pod level (preferred) or per container (run on any machine with kubectl access):
    Edit /tmp/pod-fixed.yaml:
    • Under spec:, add or update:
    • Remove metadata.resourceVersion, metadata.uid, metadata.creationTimestamp, and status: block. Apply the fixed manifest:
  3. For pods managed by a controller (Deployment/StatefulSet/DaemonSet/Job/CronJob), patch the controller spec so all current and future pods inherit runAsNonRoot: true (run on any machine with kubectl access). Example for a Deployment:
    If you must set it per container (e.g., pod-level context not desired), patch each container by name:
  4. If initContainers are present and not covered by pod-level securityContext, ensure they also have runAsNonRoot: true (run on any machine with kubectl access). Example for the first initContainer:
  5. For GitOps or manifest-driven environments, update the source manifests instead of live objects (run on any machine with repo access): in each PodTemplate (Deployment/StatefulSet/DaemonSet/Job/CronJob), set:
    Commit and apply via your normal pipeline so changes persist.
  6. Verification (run on any machine with kubectl access): re-run the audit and confirm only is_compliant=true remains, or no is_compliant=false lines:
On any machine with kubectl access:
  1. Edit the affected Pod’s owning workload (Deployment, StatefulSet, etc.) manifest and set runAsNonRoot: true at pod level.
Example for a Deployment:
Edit /tmp/deploy-run-as-non-root.yaml and ensure the pod template has:
Apply the updated manifest:
For a naked Pod (no controller), edit and apply similarly:
Note: Updating the pod template for controllers will recreate pods; direct Pod changes require deletion and re-creation.Verification (same machine with kubectl):