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. On any machine with kubectl access, list non-compliant pods using the audit command and capture the output for reference:
  2. For each non-compliant pod that is managed by a higher-level controller (Deployment, StatefulSet, DaemonSet, Job, CronJob), identify its owner and edit that resource to set runAsNonRoot: true at the pod level. Example for a Deployment owner in namespace my-namespace named my-app (replace with actual values from owner= in the audit output):
    In the opened manifest, under spec.template.spec, add or update:
    Save and exit to apply the change.
  3. If you prefer to patch instead of interactive edit, on any machine with kubectl access run a JSON patch for each affected controller. Example for the same Deployment (adjust kind/name/namespace per resource):
  4. For non-compliant pods that are not controlled by a higher-level resource (no owner= field in the audit output), retrieve the current pod manifest and recreate it with runAsNonRoot: true set. On any machine with kubectl access:
    Edit /tmp/my-pod.yaml and under spec add:
    Then delete and recreate the pod (it will not be automatically recreated because it has no controller):
  5. If any container must explicitly override the pod-level setting, ensure each container and initContainer that should be non-root has securityContext.runAsNonRoot: true defined. In the relevant controller or pod manifest, under each container:
    Apply the updated manifest using:
  6. After changes have rolled out and pods are running with updated specs, verify compliance from any machine with kubectl access by re-running the audit command and confirming no is_compliant=false lines remain:
On any machine with kubectl access:
  1. Identify non-compliant pods (from the audit output you already have) and note their controllers (Deployment/StatefulSet/DaemonSet/Job/CronJob) if present in the owner= field. Always fix the controller, not the live Pod.
  2. Edit the owning controller manifest and add runAsNonRoot: true under securityContext at the pod level (preferred) or per container.
Example: Deployment (pod-level securityContext)
Edit /tmp/deploy-nonroot.yaml and under spec.template.spec add:
Apply:
Example: Deployment (container-level securityContext if you cannot set pod-level)
  1. Repeat the same pattern for other controller types:
StatefulSet:
DaemonSet:
Job:
CronJob:
  1. For standalone Pods (no owner= in audit output), recreate them with a manifest that includes runAsNonRoot: true:
Edit /tmp/pod-nonroot.yaml to add:
or per container:
Delete fields that must not be reused (status, metadata.uid, metadata.resourceVersion, metadata.creationTimestamp, metadata.managedFields), then:
  1. Verification (on any machine with kubectl):