More Info:
Security contexts constrain the privileges and access of pods and containers at runtime. They should be applied following the CIS Google Container-Optimized OS Benchmark guidance.Risk Level
MediumAddress
SecurityCompliance Standards
- CIS GKE
Triage and Remediation
- Remediation
Remediation
Manual Steps
Manual Steps
-
List pods and identify targets (any machine with kubectl access)
Decide which namespaces/pods are in scope (exclude managed system namespaces only if your policy allows, e.g.
kube-system,gke-system, etc., after confirming provider ownership). -
Review pod- and container-level securityContext usage (any machine with kubectl access)
For each in-scope namespace, export full specs and check for missing or weaksecurityContextsettings:In the YAML, look for:- Pod-level:
.spec.securityContext - Container-level for each container and initContainer:
.spec.containers[].securityContextand.spec.initContainers[].securityContext
Note pods/containers wheresecurityContextis absent or obviously over-privileged (e.g.privileged: true,runAsUser: 0,allowPrivilegeEscalation: true,readOnlyRootFilesystem: false,capabilities.addwith broad capabilities).
- Pod-level:
-
Classify pods by required privilege (manual decision)
For each application/team:- Determine if it truly needs root, host access, or additional Linux capabilities (e.g. CNI, CSI, monitoring agents may require more privileges; most apps do not).
- Group pods into: (A) can run as non-root, (B) need limited extra privileges, (C) must remain highly privileged (with explicit business/technical justification).
-
Design appropriate securityContext settings per group (manual decision, guided by CIS GKE / COS)
For each group, decide the target baseline, for example:- Common baseline for A/B (tightest feasible):
runAsNonRoot: truerunAsUser: <non-root UID>allowPrivilegeEscalation: falsereadOnlyRootFilesystem: true(if writable paths can move to volumes)capabilities.drop: ["ALL"]and only minimalcapabilities.addif neededseccompProfile: type: RuntimeDefault(or Localhost profile if you maintain one)
- For group B/C, document each exception (e.g.
privileged: true, hostPath mounts, NET_ADMIN, SYS_ADMIN, etc.) with rationale and compensating controls.
- Common baseline for A/B (tightest feasible):
-
Update owning manifests and re-apply (any machine with kubectl access)
- Locate the source manifests/Helm charts/Kustomize for the identified pods (Git repo, CI pipeline, or local files).
- Edit them to add or refine
securityContextat pod and/or container level, following the design in step 4. Example fragment for a container securityContext: - Re-deploy via your normal workflow, e.g.:
- Coordinate with app owners to run smoke tests; watch for failures due to tightened permissions and adjust only where strictly necessary.
-
Verify and document residual risk (any machine with kubectl access)
Re-run the inspection and confirm security contexts are present and aligned with your decisions:For any remaining highly privileged pods in group C, record:- Namespace, pod name, containers
- Required elevated settings
- Business justification and review/expiry date
Keep this as part of your exception register and periodically repeat steps 2–6.
Using kubectl
Using kubectl
- Pods/containers listed by commands 3 and 4: no securityContext at pod or container level; review against your policy and the CIS guidance to decide if this is acceptable.
- Entries from command 5:
privileged=truealmost always needs strong justification; likely non-compliant. - Entries from command 6:
allowPrivilegeEscalation!=falsemeans privilege escalation is allowed; typically should be set tofalseunless there is a clear need. - Entries from command 7:
runAsUser=0means explicitly running as root; generally undesirable except for carefully reviewed system workloads. - Entries from command 8:
readOnlyRootFilesystem!=truemeans the root filesystem is writable; for many workloads CIS-like guidance prefersreadOnlyRootFilesystem: trueunless write access is required.
kubectl get pod ... -o yaml (command 2) for any flagged pod to review all securityContext fields in context (capabilities, seccompProfile, runAsNonRoot, fsGroup, etc.) and then decide specific changes in your manifests.Automation
Automation

