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. On any machine with kubectl access, list the non-compliant pods and choose one to review (replace NAMESPACE and POD_NAME in the next steps accordingly):
  2. Still on any machine with kubectl access, inspect the chosen pod to determine whether it legitimately calls the Kubernetes API (look for in-cluster client libraries, API server URLs, or service account token usage in args/env/config):
    If the workload needs to call the Kubernetes API, document the exception and do not change automountServiceAccountToken for this pod.
  3. If the pod does not need Kubernetes API access and is controlled by a higher-level object (Deployment, StatefulSet, DaemonSet, Job, CronJob, etc.), identify that owner:
    Then edit the owner resource’s pod template to disable token automount:
    In the opened YAML, under spec.template.spec, add or set:
    Save and exit to trigger a rolling update of the pods.
  4. If the pod is not controlled by a higher-level object (no ownerReferences or kind is “Pod”), edit the pod spec directly (note this will not persist across re-creates from external systems):
    Under spec, add or set:
  5. As an alternative (and where appropriate), you may set this at the ServiceAccount level so all pods using it disable token automount by default. On any machine with kubectl access:
    Add or set:
    Then ensure pods that should not have tokens use this ServiceAccount in their pod templates.
  6. Verify compliance on any machine with kubectl access:
    Confirm that pods which do not need API access now show automountServiceAccountToken=false and is_compliant=true.
On any machine with kubectl access:
  1. Identify the noncompliant pod and its owner (from the audit output), for example:
    • Namespace: my-namespace
    • Pod name: my-app-6f7b9d8c7d-abcde
    • Owner: Deployment/my-app
  2. Export the owning workload manifest (example for a Deployment):
  1. Edit the manifest locally (my-app-deployment.yaml) and set automountServiceAccountToken: false in the pod spec. For example:
  1. Apply the updated manifest:
  1. (Optional) If the pod is created directly (no owner), patch it in place:
  1. Verification (same style as the audit, on any kubectl machine):