More Info:
Apply Security Context to Your Pods and ContainersRisk Level
MediumAddress
SecurityCompliance Standards
- APRA CPS 234 (Australia)
- BSI C5 (Germany)
- Brazil LGPD
- CCPA / CPRA (California)
- CIS Critical Security Controls v8
- CIS EKS
- CMMC 2.0
- CSA Cloud Controls Matrix v4
- DPDPA
- Digital Operational Resilience Act (EU)
- Essential 8
- ISO/IEC 27017
- ISO/IEC 27018
- ISO/IEC 27701
- KSA PDPL
- MAS Technology Risk Management (Singapore)
- MITRE ATT&CK (Cloud)
- NIS2 Directive
- NIST SP 800-171
- NYDFS 23 NYCRR 500
- SWIFT Customer Security Controls Framework
- Sarbanes-Oxley IT General Controls
- UK NCSC Cyber Assessment Framework
Triage and Remediation
- Remediation
Remediation
Manual Steps
Manual Steps
-
Identify pods and namespaces lacking securityContext
- On any machine with kubectl access:
- Flag pods/containers where
.spec.securityContextis<nil>and any container.securityContextis missing or empty for review.
- On any machine with kubectl access:
-
Review current privilege-related settings on suspect workloads
- For each flagged pod, inspect full spec:
- Look for:
securityContext.privileged,allowPrivilegeEscalation,runAsUser,runAsNonRoot,capabilities,hostNetwork,hostPID,hostIPC,hostPath/other volume types,fsGroup,supplementalGroups. - Decide, with the application owner, whether the workload truly requires any privileged or host-level access.
- For each flagged pod, inspect full spec:
-
Define or update a restrictive baseline policy per namespace
- For namespaces that should be locked down (everything except core infra like
kube-system), create or adjust a baseline manifest reflecting the benchmark’s restrictive intent, for example (edit names/labels/namespaces as needed): - For existing namespaces, apply labels directly:
- For namespaces that should be locked down (everything except core infra like
-
Harden pod specs to meet the restrictive intent
- For each non-privileged workload, update its Deployment/StatefulSet/Job manifest (never edit bare pods that are not managed by a controller) to add container-level securityContext such as:
- Apply updated manifests from your IaC/manifest repo using kubectl from any machine with access:
- For each non-privileged workload, update its Deployment/StatefulSet/Job manifest (never edit bare pods that are not managed by a controller) to add container-level securityContext such as:
-
Handle necessary exceptions in tightly scoped namespaces
- For workloads that require broader access (e.g., logging agents, CNI, storage drivers), ensure they are:
- Deployed into dedicated namespaces (e.g.,
kube-systemor a specificinfra-loggingnamespace). - Bound to specific service accounts with RBAC tailored to their needs:
- Deployed into dedicated namespaces (e.g.,
- Loosen securityContext only for these pods and document the justification per workload.
- For workloads that require broader access (e.g., logging agents, CNI, storage drivers), ensure they are:
-
Re-verify posture after changes
- Confirm that most pods now carry non-empty securityContext fields and that no unexpected privileged/host-level settings exist:
- Spot-check a sample of critical namespaces (
default, app namespaces) withkubectl get pod <pod> -n <ns> -o yamlto ensure configurations align with your restrictive baseline and the benchmark’s intent.
- Confirm that most pods now carry non-empty securityContext fields and that no unexpected privileged/host-level settings exist:
Using kubectl
Using kubectl
Using kubectl
Run these from any machine withkubectl access.1. List pods that declare no securityContext at all
kube-system, kube-public, kube-node-lease) showing pods here means those pods have no explicit security context and should be reviewed and likely hardened.2. Find containers that can run as root or with no user restriction
runAsNonRoot: true or a non‑0 runAsUser.3. Find containers allowed to escalate privileges
allowPrivilegeEscalation: false as a default.4. Find privileged containers and host‑level access
5. Identify containers without restricted capabilities / read‑only root FS
drop: ["ALL"] and readOnlyRootFilesystem: true (or a conscious exception). Entries here are candidates for hardening.6. Review volume types that may bypass restrictions
hostPath or other direct node‑level mounts in application namespaces often signal pods that should be tightly reviewed and potentially restricted or moved under a privileged policy only where strictly necessary.7. Check for Pod-level securityContext defaults
securityContextat pod and container level missing or overly permissive.- Absence of fields that align with your restrictive baseline, such as:
runAsNonRoot: trueor non‑0runAsUserallowPrivilegeEscalation: falsereadOnlyRootFilesystem: truecapabilities: { drop: ["ALL"] }- No
privileged: true, no host namespaces unless strictly required.
kube-system components, logging agents) and where manifests or higher‑level policy (PSPs, Pod Security admission, or other policy engines) should be tightened.Automation
Automation

