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 and their owners (run on any machine with kubectl access):
  2. For each listed workload, decide if it legitimately calls the Kubernetes API (run on any machine with kubectl access):
    • Inspect container images, args, and env for in-cluster API use:
    • If the app needs to talk to the API (client libraries, KUBERNETES_SERVICE_HOST, in-cluster config, or curl to https://kubernetes.default.svc), do not disable the token; instead, review RBAC separately.
    • Only proceed to the next step for workloads that do not need API access.
  3. Disable token automount at the Pod spec level for controller-managed workloads (recommended) (run on any machine with kubectl access, adjust kind as appropriate: Deployment, DaemonSet, StatefulSet, Job, etc.):
    Example for a StatefulSet:
  4. For standalone Pods not managed by a controller, recreate them with token automount disabled (run on any machine with kubectl access):
  5. Optionally, disable token automount on the ServiceAccount used by multiple non-API workloads (use only if all pods using it do not need the API) (run on any machine with kubectl access):
  6. Verify compliance (run on any machine with kubectl access):
    Ensure the output is is_compliant=true or that no remaining noncompliant Pods correspond to workloads that can safely disable token automount.
On any machine with kubectl access to the cluster:
  1. Identify a noncompliant pod and its owner (from the audit output), for example:
    • Namespace: prod
    • Pod name: web-abc123
    • Owner: Deployment/prod/web
  2. Export the owning workload manifest and edit it locally (example for a Deployment):
  1. In /tmp/deployment-web.yaml, under spec.template.spec, set automountServiceAccountToken: false. For example:
  1. Apply the updated manifest:
  1. If the pod is created directly (no controller), patch it in place (note: this recreates the pod, not the spec from a controller):
  1. If you choose to set this at the ServiceAccount instead (applies to all pods using it):
Edit /tmp/sa-web-sa.yaml:
Apply:
  1. Verification (rerun the audit on any machine with kubectl access):