Kubernetes check

Container requests or may default to root

K8S-SEC-004MediumSecurity

Trigger condition

A regular, init, or live ephemeral container's effective runAsUser is 0, or is unspecified without an effective runAsNonRoot of true. runAsUser and runAsNonRoot are resolved independently, with an explicit container-level value always taking precedence over the Pod's own value; an explicit positive UID, or an unspecified UID with runAsNonRoot enforced, is not flagged. A Pod or Deployment template explicitly declaring spec.os.name as windows is skipped; an unspecified OS is evaluated using the Linux UID rules.

Evidence

States the container's type and name, its effective runAsUser and runAsNonRoot values (or 'unspecified' when neither the container nor the Pod sets one), and which level -- the container's own securityContext or the Pod's -- each effective value came from.

Impact

An effective runAsUser of 0 configures the container's entrypoint to start as root. The privileges actually available to it depend on what else is configured -- added Linux capabilities, whether the root filesystem is writable, allowPrivilegeEscalation, and any other security controls in effect -- not on this setting alone. Setting runAsUser to 0 together with runAsNonRoot: true is a conflicting, startup-blocking configuration that Kubernetes refuses to run at all, rather than a running security exposure. When runAsUser is left unspecified and runAsNonRoot is not enforced, the container's actual startup user depends entirely on the image's own USER directive (or its absence, which defaults to root), so nothing in the spec itself would catch a root default.

Recommendation

Set runAsUser to a compatible, nonzero numeric UID, verifying both the application and its file permissions are compatible with that UID, and set runAsNonRoot to true to enforce non-root startup. For a Deployment-managed container, make the change in the Deployment's own Pod template and roll out the change. For a Pod with no verified owning Deployment, if a controller manages it (e.g. a DaemonSet or StatefulSet), make the change in that workload's own source configuration and follow its normal update process; if the Pod is standalone, make the change in its own source manifest and recreate it -- either way, a running Pod's container spec cannot be edited in place, so check workload availability before it is replaced. When a live Pod's container carries a different risk than its Deployment template's own matching container reports, check the Deployment's rollout status (an older replica may predate a template correction) and whether an admission-time mutation (e.g. a mutating webhook) altered that Pod independently of its template -- investigate through the owning controller rather than editing the Pod directly. For an ephemeral container, apply this corrected configuration to any future debug container attached to the Pod; clearing this existing one requires replacing the Pod itself, through the Eviction API or a normal Deployment rollout, after checking available capacity and any PodDisruptionBudget.

Important limitations

This check evaluates only runAsUser and runAsNonRoot. It does not detect root-equivalent access achieved through other means, such as added Linux capabilities, a writable root filesystem, or allowPrivilegeEscalation, and it does not inspect the image itself -- an 'unspecified UID' finding reflects what the spec does not enforce, not a confirmed root default in the image.

← Back to the check catalogue