Skip to main content

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

Medium

Address

Security

Compliance Standards

  • CIS GKE

Triage and Remediation

Remediation

Manual Steps

  1. 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).
  2. 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 weak securityContext settings:
    In the YAML, look for:
    • Pod-level: .spec.securityContext
    • Container-level for each container and initContainer: .spec.containers[].securityContext and .spec.initContainers[].securityContext
      Note pods/containers where securityContext is absent or obviously over-privileged (e.g. privileged: true, runAsUser: 0, allowPrivilegeEscalation: true, readOnlyRootFilesystem: false, capabilities.add with broad capabilities).
  3. 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).
  4. 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: true
      • runAsUser: <non-root UID>
      • allowPrivilegeEscalation: false
      • readOnlyRootFilesystem: true (if writable paths can move to volumes)
      • capabilities.drop: ["ALL"] and only minimal capabilities.add if needed
      • seccompProfile: 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.
  5. 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 securityContext at 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.
  6. 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.
Interpretation / what indicates a problem (requires human judgement):
  • 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=true almost always needs strong justification; likely non-compliant.
  • Entries from command 6: allowPrivilegeEscalation!=false means privilege escalation is allowed; typically should be set to false unless there is a clear need.
  • Entries from command 7: runAsUser=0 means explicitly running as root; generally undesirable except for carefully reviewed system workloads.
  • Entries from command 8: readOnlyRootFilesystem!=true means the root filesystem is writable; for many workloads CIS-like guidance prefers readOnlyRootFilesystem: true unless write access is required.
Use the detailed 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.