Skip to main content

More Info:

Advisory: avoid long-lived ServiceAccount token Secrets; use projected (TokenRequest) tokens with an audience and expiry instead.

Risk Level

Informational

Address

Security

Compliance Standards

  • Cloudanix Best Practice

Triage and Remediation

Remediation

Manual Steps

  1. List all ServiceAccount token Secrets and map them to identities
    • On any machine with kubectl access:
    • Record which applications (Deployments/Pods) use each ServiceAccount.
  2. Identify workloads actually mounting these token Secrets
    • On any machine with kubectl access:
    • Flag Pods where a secret volume mounts a ServiceAccount token Secret.
  3. Decide whether each workload actually needs a Kubernetes API token
    • For each flagged Pod/Deployment, review its code/configuration to see if it calls the Kubernetes API.
    • If it does not need API access, plan to:
      • Remove the ServiceAccount reference (fall back to default only if default SA is locked down), and
      • Ensure no secret volume or env var uses a ServiceAccount token Secret.
  4. Migrate workloads that do need API access to use projected tokens
    • For each workload that truly needs a token, update the Pod spec (Deployment/StatefulSet/Job, etc.) to use a projected ServiceAccount token volume with audience and expiry, instead of a secret volume. Example pattern (adapt to your manifest):
    • Apply the change on any machine with kubectl access:
  5. Clean up legacy ServiceAccount token Secrets once unused
    • After updating workloads and confirming they run correctly, check whether a token Secret is still referenced:
    • For any ServiceAccount token Secret no longer referenced by Pods and not needed for external systems, delete it:
  6. Re-verify and document exceptions
    • On any machine with kubectl access, re-run:
    • For any remaining ServiceAccount token Secrets, document:
      • Which workload or external system uses them,
      • Why projected tokens cannot be used yet, and
      • A plan or decision to accept the residual risk.
A large number of kubernetes.io/service-account-token Secrets, especially in application namespaces, indicates widespread use of long‑lived SA token Secrets and is a concern.
Concerning signs in the output:
  • type: kubernetes.io/service-account-token
  • Mounted in Pods as a volume (see step 3)
  • No process in place to rotate or prune these Secrets.
Lines where secretName matches names from step 1 show Pods mounting SA token Secrets explicitly. These Pods should be reviewed to migrate to projected tokens (TokenRequest) via projected volumes.
Concerning patterns:
  • automountServiceAccountToken is empty (inherits true from the ServiceAccount) or explicitly true for Pods in application namespaces, meaning they get a long‑lived token mounted unless the SA is configured otherwise.
Concerning patterns:
  • ServiceAccounts in application namespaces with automountServiceAccountToken: true or unset (defaults to true), combined with use in Pods from step 4.
Concerning signs:
  • Token Secrets with very old CREATED timestamps that are still referenced by running Pods or external systems.
Use these outputs to decide, per application:
  • Which Pods/Workloads still depend on classic SA token Secrets.
  • Where you can disable automatic SA token mounting and refactor to projected tokens with explicit audiences and expiries.