More Info:
Security contexts constrain the privileges and access of pods and containers at runtime. Apply appropriate security contexts to all pods and containers.Risk Level
MediumAddress
SecurityCompliance Standards
- CIS AKS
Triage and Remediation
- Remediation
Remediation
Manual Steps
Manual Steps
-
List pods missing or with weak securityContext
- Run on: any machine with kubectl access
- Command:
-
Gather full specs for candidate pods
- Run on: any machine with kubectl access
- For each
<namespace> <pod>from step 1:
-
Review current securityContext settings
- Open each
pod-*.yamland check at both pod and container levels for (examples of what to look for; you must decide what is appropriate for your workloads):- Missing
securityContext:blocks - Privilege-related fields:
privileged,allowPrivilegeEscalation,capabilities.add/drop,runAsUser,runAsGroup,runAsNonRoot,readOnlyRootFilesystem,seLinuxOptions,seccompProfile,procMount,hostPID,hostIPC,hostNetwork,hostPorts.
- Missing
- Identify pods/containers that run with unnecessary or overly broad privileges relative to their function.
- Open each
-
Decide appropriate securityContext per workload
- For each pod/container, decide:
- The minimal user/group IDs (
runAsUser,runAsGroup,runAsNonRoot: true) - Whether
privilegedis truly needed; if not, setprivileged: false - Whether
allowPrivilegeEscalationcan be disabled:allowPrivilegeEscalation: false - Required and removable Linux capabilities (
capabilities.dropandcapabilities.add) - Whether the root filesystem can be read-only:
readOnlyRootFilesystem: true - Whether host namespaces/ports are truly required (avoid
hostPID,hostIPC,hostNetwork, host ports where possible).
- The minimal user/group IDs (
- Use your application and Docker image requirements plus the CIS Docker Benchmark as guidance.
- For each pod/container, decide:
-
Implement securityContext via manifests (preferred) or live edit
- If workloads are managed by manifests/Helm/Kustomize:
- Edit the deployment/statefulset/daemonset/job manifests (not the pods directly) to add/adjust
securityContextat pod spec and container spec levels according to step 4. Example pattern (adapt as needed for each workload): - Apply changes:
- Edit the deployment/statefulset/daemonset/job manifests (not the pods directly) to add/adjust
- If a pod is not managed by higher-level controllers (e.g., a standalone pod for debugging):
- Edit directly:
- Add/adjust the
securityContextblocks as decided in step 4; save to recreate the pod.
- Edit directly:
- If workloads are managed by manifests/Helm/Kustomize:
-
Verify that security contexts are now applied
- Re-run the evidence command and confirm no workload you intend to secure is listed:
- Spot-check a few pods:
- Confirm that the configured
securityContextvalues match your decisions from step 4 and that applications still function as expected.
- Re-run the evidence command and confirm no workload you intend to secure is listed:
Using kubectl
Using kubectl
POD_SCcolumn is empty (<none>or{}) for pods that should have restricted settings.- You see no common baseline (some pods with strict settings, others with none, without a clear reason).
securityContextis missing (null/[]) or{}for workloads that handle sensitive data or run user code.- Known risky patterns, for example:
"privileged": true"runAsUser": 0or"runAsNonRoot": falsewithout a strong justification"allowPrivilegeEscalation": true- Broad capabilities like
"capAdd": ["ALL"]or many capabilities with no clear need - Host access options such as
"hostNetwork": true,"hostPID": true,"hostIPC": trueat pod spec level.
- Missing
securityContextat both.spec.securityContextand.spec.containers[].securityContext. - Any of:
privileged: truerunAsNonRoot: falseor absent, combined withrunAsUser: 0allowPrivilegeEscalation: trueor absent when the container has extra capabilitiescapabilities.addincluding unnecessary or broad capabilities (e.g.,SYS_ADMIN,NET_ADMIN,ALL)hostNetwork: true,hostPID: true,hostIPC: truewithout a strict operational reasonreadOnlyRootFilesystem: falseor absent when the container does not need to write to the root FS.
- Any application pod (not a low-level node/cluster agent) appearing in this list without a clear operational need.
- Cluster-wide patterns where many pods use privileged mode or host namespace access.
- Business‑critical or multi‑tenant workloads listed here; they likely need explicit securityContext settings instead of inheriting defaults.
Automation
Automation
- In the first table, any row with
SECURITY_CONTEXT=MISSING_SCindicates a pod container with nosecurityContextdefined at the container level. These need manual review and likely a securityContext added. - In the second and third sections:
- Lines listed indicate containers of interest.
- Fields with
unsetmean that aspect is not configured and should be reviewed (for example, consider settingrunAsNonRoot: true,readOnlyRootFilesystem: true,allowPrivilegeEscalation: false, and dropping capabilities where possible).
- Absence of rows in these sections means all containers have a
securityContextand the inspected fields are set, but you still must review whether the chosen values are appropriate and restrictive enough.

