More Info:
Security contexts restrict privileges, capabilities, volumes, and root access for pods and containers. Apply restrictive policies broadly and scope privileged access to specific service accounts and namespaces.Risk Level
LowAddress
SecurityCompliance Standards
- CIS OKE
Triage and Remediation
- Remediation
Remediation
Manual Steps
Manual Steps
-
Identify pods and namespaces with missing or weak securityContext
- On any machine with kubectl access:
- On any machine with kubectl access:
-
Review securityContext details for suspicious pods
- For each namespace/pod pair from step 1, inspect full spec:
- Manually check for:
securityContext.privileged: trueallowPrivilegeEscalation: trueor unsetrunAsUser: 0orrunAsNonRoot: false/unset- Use of
hostNetwork,hostPID,hostIPC, andhostPathvolumes - Absence of
capabilities.drop: ["ALL"]
- For each namespace/pod pair from step 1, inspect full spec:
-
Decide which workloads truly need elevated privileges and scope them
- Classify each privileged/high‑risk pod as:
- System-critical (needs elevated privileges) – e.g. CNI, kube-proxy, node/logging/monitoring agents. Prefer to run these in a dedicated namespace like
kube-systemor another clearly named “system” namespace. - Business application (should be restricted) – typical app workloads that should run non-root and non-privileged.
- System-critical (needs elevated privileges) – e.g. CNI, kube-proxy, node/logging/monitoring agents. Prefer to run these in a dedicated namespace like
- For system-critical pods:
- Ensure they use dedicated service accounts and namespaces.
- Plan to bind any future privileged policies only to those service accounts/namespaces.
- Classify each privileged/high‑risk pod as:
-
Define or tighten restrictive security policies for normal workloads
- On any machine with kubectl access, create a baseline “restricted” policy object aligned with the remediation (adapted to your cluster’s API support; PodSecurityPolicy is deprecated in newer versions, so you may instead implement equivalent Pod Security Admission or OPA/Gatekeeper):
- Bind this policy only to non-privileged service accounts/namespaces via RBAC (cluster roles/rolebindings) after confirming PodSecurityPolicy is enabled in your cluster.
- On any machine with kubectl access, create a baseline “restricted” policy object aligned with the remediation (adapted to your cluster’s API support; PodSecurityPolicy is deprecated in newer versions, so you may instead implement equivalent Pod Security Admission or OPA/Gatekeeper):
-
Refactor pod specs for non-privileged workloads
- For each business/application workload identified in step 3, update the Deployment/DaemonSet/StatefulSet (not the live pod) to add safe security contexts, for example:
- Under
spec.template.spec.securityContextand each container’ssecurityContext, add fields such as: - Remove
privileged: true,hostPathvolumes,hostNetwork: true,hostPID: true,hostIPC: trueunless strictly required.
- Under
- Save to trigger a rolling restart.
- For each business/application workload identified in step 3, update the Deployment/DaemonSet/StatefulSet (not the live pod) to add safe security contexts, for example:
-
Verify improved posture and monitor regressions
- Re-run discovery to ensure no remaining obviously insecure pods:
- Optionally, enforce admission controls (Pod Security Admission “restricted” level or equivalent policy engine) to prevent future pods without appropriate security contexts from being admitted.
- Re-run discovery to ensure no remaining obviously insecure pods:
Using kubectl
Using kubectl
kube-system, kube-public, kube-node-lease).SC_POD=<none>andSC_CONT=<none>(no securityContext at all on pod or containers).- Service account is generic (e.g.,
default) and used by many pods that may need different privilege levels.
.spec.securityContext):- Missing entirely (no
securityContext:block). fsGroup/supplementalGroupswith values including0.runAsUser: 0orrunAsGroup: 0without strong need.
.spec.containers[] and .spec.initContainers[]):securityContextmissing completely.privileged: true.allowPrivilegeEscalation: trueor not set.runAsUser: 0orrunAsNonRoot: falseor not set.capabilities.addwith broad capabilities (or nocapabilities.drop).readOnlyRootFilesystem: falseor not set.
hostNetwork: true,hostPID: true, orhostIPC: true(these are at pod spec level).- Volumes with
hostPath:under.spec.volumes[]without strong justification.
truein theprivilegedposition.trueor<no value>in theallowPrivilegeEscalationposition for general application workloads.
0forrunAsUser.falseor<no value>forrunAsNonRooton general workloads.
- Any
hostPathobject (notnull) used by regular application pods, instead of more controlled volume types (configMap, secret, PVC, etc.), unless clearly justified (e.g., logging agents, node-level tooling).
- Service accounts outside tightly controlled namespaces (e.g., not
kube-system) bound to highly privileged roles. - Generic service accounts (
default) having elevated roles, which may be used by pods lacking restrictive security contexts.
- Workload namespaces without
pod-security.kubernetes.io/enforcelabels. - Enforce levels weaker than
restrictedfor general application namespaces (e.g.,enforce=privilegedor missing).
Automation
Automation
-
Section “Namespaces with pods missing ANY securityContext”:
- Any listed
<namespace> <pod>means that pod and all its containers lack explicitsecurityContext. These are candidates to harden by adding non-root, dropping capabilities, read-only root filesystem, etc.
- Any listed
-
Section “Pods/containers with risky securityContext fields”:
- Lines beginning with:
PRIVILEGED|...– containers running withsecurityContext.privileged: true(highest risk; should be tightly scoped to specific service accounts/namespaces likekube-systemif truly required).ALLOW_PRIV_ESC|...– containers that allow privilege escalation.ROOT_USER|...– containers explicitly running as root (runAsUser: 0orrunAsNonRoot: false).RW_ROOTFS|...– containers withreadOnlyRootFilesystem: false(less restrictive; often acceptable but should be intentional).
- Lines beginning with:
-
Section “Pods using host features or hostPath volumes”:
- Any line indicates a pod using
hostNetwork,hostIPC,hostPID, orhostPathvolumes, which breaks the isolation the benchmark’s example policy expects. These should be limited to well‑understood system workloads in tightly controlled namespaces.
- Any line indicates a pod using
-
Section “Per-namespace securityContext usage summary”:
- For each namespace:
podSC=false|containerSC=false– all pods in that namespace lack explicit securityContext; namespace is a prime target for enforcing more restrictive defaults.- Namespaces with many
falsevalues should be prioritized for adding restrictive policies and explicit pod/container securityContext.
- For each namespace:

