Skip to main content

More Info:

Verifies automountServiceAccountToken is false for pods that do not call the Kubernetes API. A mounted token is a ready-made credential for an attacker who lands in the pod.

Risk Level

Medium

Address

Security

Compliance Standards

  • Cloudanix Best Practice

Triage and Remediation

Remediation

Manual Steps

  1. Identify noncompliant pods
    • Run on: any machine with kubectl access
  2. For a standalone Pod: capture the manifest
    • Run on: any machine with kubectl access
      Replace NAMESPACE and POD_NAME with values from step 1:
  3. Edit the pod manifest to disable token automount
    • Run on: any machine with kubectl access
    • Open the file and add or update the field under spec:
    • If automountServiceAccountToken already exists under spec:, edit it so it reads:
  4. Recreate the pod with the updated manifest
    • Run on: any machine with kubectl access
  5. For controller-managed workloads (e.g., Deployment, DaemonSet, Job): patch the controller instead of the pod
    • Run on: any machine with kubectl access
    • Example for a Deployment; adjust KIND, NAME, and NAMESPACE based on the owner= from step 1:
    • The controller will automatically recreate pods with the new setting.
  6. Verify compliance
    • Run on: any machine with kubectl access
On any machine with kubectl access to the OKE cluster:
  1. Identify a non‑compliant pod and its owner (from the audit output), for example:
    • Namespace: app-namespace
    • Pod name: web-7c8b4f9d9b-xj9lt
    • Owner: Deployment/app-namespace/web
  2. Export the owning workload manifest, edit it locally, and re‑apply (pod spec fields like automountServiceAccountToken must be set on the controller, not on the individual pod):
Edit web-deploy.yaml and in spec.template.spec add (or change) this field:
Apply the updated manifest:
Kubernetes will recreate the pods managed by this Deployment with automountServiceAccountToken: false. Repeat this pattern for other controller types (StatefulSet, DaemonSet, Job, CronJob) by adjusting the kind in the kubectl get command and editing the same spec.template.spec section.
  1. If the pod is created directly (no controller ownerReference), edit the pod spec and re‑create it:
Edit web-standalone-pod.yaml:
Delete and recreate the pod:
  1. Optional: set this at the ServiceAccount level instead of each pod, if all pods using it do not need API access:
Edit web-sa.yaml:
Apply:
  1. Verification (rerun the audit command):