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 the non‑compliant pods and pick the one(s) to fix:
  2. For a pod created from a higher‑level controller (Deployment, DaemonSet, StatefulSet, Job, CronJob), edit the controller manifest so the setting persists. For example, for a Deployment (run on any kubectl machine):
    Under spec.template.spec, add or update a pod‑level security context:
    If you need per‑container overrides instead (e.g., only some containers must be non‑root), set on each container:
    Save and exit; Kubernetes will roll out new pods.
  3. For standalone Pods not managed by a controller, first export the manifest (any kubectl machine):
    In /tmp/pod-POD_NAME.yaml, delete runtime‑only fields like status:, metadata.resourceVersion, metadata.uid, metadata.creationTimestamp, and metadata.managedFields. Under spec, add either:
    or, per container:
  4. Apply the corrected standalone Pod manifest and recreate the pod (any kubectl machine):
  5. For OKE workloads managed via IaC or GitOps, mirror the same securityContext.runAsNonRoot: true changes in the source manifests or Helm charts (e.g., in your Git repository) so future deployments do not revert the setting. Commit and redeploy via your normal pipeline.
  6. Verify all pods now comply (any kubectl machine):
    Confirm that either the output is exactly is_compliant=true or every listed container line ends with is_compliant=true.
On any machine with kubectl access:
  1. Identify non-compliant pods
  1. For a pod controlled by a Deployment/ReplicaSet/DaemonSet/Job/etc., patch the controller (example: Deployment)
Edit /tmp/deployment-<name>.yaml and under spec.template.spec add (or adjust) the pod-level security context:
Apply the updated manifest:
If you prefer to set it per container instead of pod-level:
  1. For standalone Pods (no ownerReferences.controller), edit and re-apply
Edit /tmp/pod-<pod-name>.yaml so the pod spec has one of:Pod-level:
Or per container:
Then recreate the pod:
  1. Verification (same audit logic as check)