More Info:
Advisory: avoid long-lived ServiceAccount token Secrets; use projected (TokenRequest) tokens with an audience and expiry instead.Risk Level
InformationalAddress
SecurityCompliance Standards
- Cloudanix Best Practice
Triage and Remediation
- Remediation
Remediation
Manual Steps
Manual Steps
-
Identify ServiceAccounts using legacy Secret tokens
- On any machine with kubectl access:
For each ServiceAccount, list referenced Secrets:Note ServiceAccounts that have
.secretspopulated, especially outsidekube-systemanddefaultbootstrap usage.
- On any machine with kubectl access:
-
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.
- On any machine with kubectl access, inspect suspected Secrets:
-
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
kubectlor the API. Determine which integrations can be updated to use projected TokenRequest tokens instead of static Secrets.
- On any machine with kubectl access, find Pods mounting or env‑referencing these Secrets:
-
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.
- 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:
-
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 anysecrets:list entries that correspond to long‑lived token Secrets. - Optionally delete unused legacy token Secrets (only after confirming nothing consumes them):
- Update ServiceAccount manifests to omit explicit
- After verifying that workloads/external systems function correctly with projected tokens, remove their dependency on the old Secrets:
-
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.
- On any machine with kubectl access, re‑list ServiceAccounts and Secrets:
Using kubectl
Using kubectl
secretscolumn 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.
secrets:list contains items named likeNAME-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.
- Large numbers of
kubernetes.io/service-account-tokenSecrets 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.
- Volumes of
type: secretwith asecretNamematching a*-token-xxxxxSecret show pods mounting long‑lived token Secrets. - Very few or no
type: projectedvolumes configured for tokens suggests the cluster is not using projected ServiceAccount tokens.
.spec.volumesforsecret:entries with names like*-token-xxxxx..spec.serviceAccountNameand.spec.automountServiceAccountToken.
- 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.
- ServiceAccounts with a high pod count are high‑value targets; if they rely on long‑lived token Secrets, the risk is elevated.
- Under
.spec.volumes, aprojected:volume with aserviceAccountToken: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-tokenSecrets mounted into pods assecretvolumes, 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
serviceAccountTokenvolumes 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.
Automation
Automation

