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. Identify ServiceAccounts using legacy Secret tokens
    • On any machine with kubectl access:
      For each ServiceAccount, list referenced Secrets:
      Note ServiceAccounts that have .secrets populated, especially outside kube-system and default bootstrap usage.
  2. Identify long‑lived ServiceAccount token Secrets
    • On any machine with kubectl access, inspect suspected Secrets:
    • Flag tokens that are:
      • Used by applications (non‑system namespaces), and
      • Old (e.g., created weeks/months ago), indicating long‑lived credentials.
  3. Review workloads and external systems that consume these Secrets
    • On any machine with kubectl access, find Pods mounting or env‑referencing these Secrets:
    • Separately review CI/CD pipelines, external services, or scripts that may read these Secrets via kubectl or the API. Determine which integrations can be updated to use projected TokenRequest tokens instead of static Secrets.
  4. Plan and configure use of projected ServiceAccount tokens
    • For each workload that currently mounts a ServiceAccount token Secret and can be changed, update its Pod spec (Deployment/StatefulSet/Job, etc.) to use a projected ServiceAccount token volume with audience and expiry, for example:
    • Apply the updated manifest from any machine with kubectl access:
    • Ensure the consuming application or external system is updated to read the token from the projected volume path and validate the audience and expiry.
  5. Decommission unnecessary long‑lived ServiceAccount token Secrets
    • After verifying that workloads/external systems function correctly with projected tokens, remove their dependency on the old Secrets:
      • Update ServiceAccount manifests to omit explicit secrets: entries unless strictly required.
        Remove any secrets: list entries that correspond to long‑lived token Secrets.
      • Optionally delete unused legacy token Secrets (only after confirming nothing consumes them):
  6. Verify reduced reliance on long‑lived ServiceAccount token Secrets
    • On any machine with kubectl access, re‑list ServiceAccounts and Secrets:
    • Confirm that:
      • Only strictly necessary ServiceAccounts still reference token Secrets.
      • Most application workloads have moved to using projected ServiceAccount tokens with bounded audience and expiry.
Problem indication:
  • secrets column populated for many ServiceAccounts (older clusters) suggests token Secrets may exist.
  • Widespread use of default ServiceAccounts (no custom SAs) often means many pods share the same long‑lived token.

Problem indication:
  • secrets: list contains items named like NAME-token-xxxxx.
  • automountServiceAccountToken: true (or missing and cluster default is true) means all pods using this SA will receive a token volume by default.
  • No explicit design about which workloads should receive a token.

Problem indication:
  • Large numbers of kubernetes.io/service-account-token Secrets indicate long‑lived tokens are broadly available.
  • If these Secrets are mounted into pods (see next step), they are likely being used instead of short‑lived projected tokens.

Problem indication:
  • Volumes of type: secret with a secretName matching a *-token-xxxxx Secret show pods mounting long‑lived token Secrets.
  • Very few or no type: projected volumes configured for tokens suggests the cluster is not using projected ServiceAccount tokens.
(For a focused check on a single pod:)
Look under:
  • .spec.volumes for secret: entries with names like *-token-xxxxx.
  • .spec.serviceAccountName and .spec.automountServiceAccountToken.

Problem indication:
  • Many pods with automountServiceAccountToken:true (or null while the SA/namespace/cluster default is true) but without any explicit projected token volume configuration indicate reliance on legacy auto‑mounted tokens.

Problem indication:
  • ServiceAccounts with a high pod count are high‑value targets; if they rely on long‑lived token Secrets, the risk is elevated.

Positive indication (for reference):
  • Under .spec.volumes, a projected: volume with a serviceAccountToken: source that specifies:
    • audience: ...
    • expirationSeconds: ...
  • This shows use of bounded, short‑lived tokens rather than legacy Secrets.

Human review guidance (what to decide from this data):
  • If you see many kubernetes.io/service-account-token Secrets mounted into pods as secret volumes, you likely rely on long‑lived tokens and should plan to:
    • Disable automatic token Secret creation (cluster/SA level) going forward.
    • Stop mounting legacy token Secrets into workloads and instead configure projected serviceAccountToken volumes with appropriate audiences and short expiries.
  • If most workloads rely only on default auto‑mounted tokens and no projected token volumes are defined, review which workloads truly need a ServiceAccount token and which can have automountServiceAccountToken: false.