When a Kubernetes service account token leaks, the attacker inherits everything that account's RBAC bindings allow, plus any cloud identity federated to it, until the token expires or is invalidated. Tokens leak from container images, debug output, pod filesystems reached through a vulnerable application, CI logs and copied kubeconfig files. This guide is an ordered investigation for one suspected token: scope the token, measure its RBAC reach, establish which secrets it read, follow any pivot into AWS, Azure or Google Cloud, then revoke in a way that actually ends access. It is for platform security engineers and incident responders. It assumes audit logging is on; the Reading Service Account Activity in Kubernetes Audit Logs guide explains the audit fields used here, and this page does not repeat them.
Key takeaways
- Decode the token before anything else. Its claims tell you the namespace, service account, bound pod, expiry and token ID, which decide both how dangerous it is and how you can revoke it.
- Reach is RBAC plus cloud. Effective permissions come from every RoleBinding and ClusterRoleBinding naming the account or its groups, and from any IAM role, Entra app or Google principal federated to it.
- Secrets read means more credentials to rotate. Any Secret the token could get or list should be treated as exposed unless the audit log shows it was not read.
- Short-lived tokens cannot be revoked one by one. Kubernetes documentation states there is no central record of issued tokens; you end access by deleting the bound object or recreating the service account.
- Revoke the cloud side too. Cloud credentials minted from the token before revocation stay valid for their own lifetime, so contain them in the cloud provider as well.
Step 1: decode and classify the token
A service account token is a signed JSON Web Token (JWT). Decode the payload offline, without sending it anywhere, and record its claims in the case file. Do not paste it into public decoding websites, which would be another disclosure.
| Claim or property | What it tells you | Why it matters for the investigation |
|---|---|---|
sub (system:serviceaccount:<namespace>:<name>) | The service account | The identity to search for in audit logs and RBAC bindings |
kubernetes.io private claims for pod or secret (name and uid) | The object the token is bound to | Bound tokens stop authenticating once that object is deleted; this is your fastest revocation path |
| Node name and uid in the pod claims | Where the bound pod was scheduled | Context only: the Kubernetes docs state that kube-apiserver does not verify this node information |
jti | Unique token ID, shown in audit events as authentication.kubernetes.io/credential-id | Lets you find every request made with this exact token |
iat, exp | Issue time and expiry | Defines the earliest and latest possible use |
aud | Intended audience | An audience such as sts.amazonaws.com or pods.eks.amazonaws.com signals a token meant for a cloud exchange |
No exp and no binding | A legacy Secret-based token | Valid from anywhere until the Secret is deleted; highest urgency |
Then check whether the bound object still exists. If the token is bound to a pod that has already been deleted, or whose uid no longer matches, the API server will not authenticate it, and your work becomes reconstructing what happened while it was valid. If the bound pod is still running, the token is live.
Before you change anything, preserve the pod: capture its spec, logs, image digest and, if your tooling supports it, a filesystem snapshot. The pod is both the likely leak point and the object whose deletion revokes the token. The Container and Kubernetes Forensics Guide covers evidence capture for running containers.
Step 2: decide how fast you must act
Most investigations run evidence collection and containment in parallel. Use the token class to decide which comes first.
| Token class | Typical lifetime | Revocation path | Priority |
|---|---|---|---|
| Projected token bound to a running pod | Short-lived; kubelet refreshes it before expiry | Delete the pod after evidence capture | Contain within the hour once the pod is preserved |
Token from kubectl create token or TokenRequest, no binding | Set at creation, can be long | No per-token revocation; recreate the service account or wait for expiry | High: plan the recreate immediately |
| Token bound to a Secret | Until the Secret is deleted | Delete the Secret | High, and a quick action |
Legacy kubernetes.io/service-account-token Secret | Does not expire | Delete the Secret | Critical: act first, investigate second |
| Token with a cloud audience (IRSA, Pod Identity, workload identity) | Kubernetes token short; minted cloud credentials have their own lifetime | Revoke the Kubernetes side and contain the cloud role or principal | High, and needs the cloud team in the same call |
Step 3: measure the RBAC reach
The service account's effective permissions are what the attacker could do. Measure them as they stand now, and as they stood during the exposure window if bindings changed.
- Ask the API server directly. Kubernetes documents
kubectl auth can-iwith impersonation for checking what another identity can do, for examplekubectl auth can-i list secrets --namespace target --as system:serviceaccount:dev:dev-sa. Adding--listgives the full rule set in a namespace. Run it for the account's own namespace and for every namespace it has bindings in. - Enumerate bindings, including group bindings. List every RoleBinding and ClusterRoleBinding whose subjects include the service account, the group
system:serviceaccounts:<namespace>or the groupsystem:serviceaccounts. A binding to a group grants the account rights you will not see by searching for its name. - Flag the dangerous verbs. Any of these turns a workload token into a cluster compromise:
getorlistonsecrets;createonpodsor workload controllers (which can mount other service accounts);createonserviceaccounts/token;impersonate;escalateorbindon roles;patchon nodes;execinto pods. The Kubernetes escalate and bind Verbs and Kubernetes impersonate Verb guides explain why. - Check for cluster-admin. If any binding gives the account
cluster-adminor an equivalent wildcard role, stop scoping and escalate to the Kubernetes Cluster Compromise Playbook.
Record the result as a short reach statement for the incident record, for example: "Read and list Secrets in namespace payments; create pods in payments; no cluster-scoped rights; federated to IAM role payments-app."
Step 4: reconstruct what the token did
Search the audit log for the exposure window, first by the token's credential-id (JTI), then by the service account username for anything without a credential ID (legacy tokens). Work through these questions:
- Where did requests come from? Compare
sourceIPsanduserAgentwith the workload's normal pattern. A workload token used from an address outside the pod and node ranges, or with akubectluser agent the application never uses, is the clearest sign of theft. - Did it look around? A burst of
listcalls across resource types,selfsubjectaccessreviewsorselfsubjectrulesreviewscreation, and discovery endpoint reads soon after first external use suggest an attacker checking what the token can do. - Did it read secrets? Filter for
objectRef.resource=secretswith verbsget,listandwatch, andresponseStatus.code200. A successfullistreturns every Secret in the namespace in one response. Write down each Secret name and its namespace: this is the rotation list for Step 6. - Did it create anything? Look for
createorpatchon pods, deployments, daemonsets, cronjobs, roles, rolebindings, serviceaccounts andserviceaccounts/token. A new pod running as a more privileged service account, or a new token minted for another account, is lateral movement. - Did it reach the nodes? Pods created with
hostPathmounts,privileged: trueor host namespaces point to an attempt to escape to the node. Request bodies are needed to see these fields, so check whether your audit policy records them for pod creation.
Requests rejected with 403 are evidence too: they show what the attacker tried and was denied, which helps scope intent and confirms the token was in hostile hands.
Step 5: follow the cloud identity pivot
Many workloads exchange their service account token for cloud credentials. If the service account is federated, a stolen token may have been used outside the cluster to obtain those credentials, and that activity appears only in the cloud provider's logs. Platforms are listed alphabetically.
| Platform | How to tell the account is federated | Where the exchange shows up | What to search next |
|---|---|---|---|
| Amazon EKS (IAM roles for service accounts) | Service account annotation with an IAM role ARN; an IAM OIDC provider for the cluster | AWS STS AssumeRoleWithWebIdentity in CloudTrail | Actions by the resulting role session; see How to Investigate CloudTrail for a Compromised Access Key |
| Amazon EKS Pod Identity | An EKS Pod Identity association mapping a role to the service account and namespace | The Pod Identity Agent calls AssumeRoleForPodIdentity on the EKS Auth API; AWS states CloudTrail logging is available | Actions by the role session in the exposure window |
| Azure Kubernetes Service (workload identity) | Annotation azure.workload.identity/client-id on the service account; a federated identity credential on the Entra app or managed identity | Microsoft Entra service principal sign-in logs for that client ID | Azure Activity log and Microsoft Graph activity; see How to audit Entra workload identity federated credentials |
| Google Kubernetes Engine (Workload Identity Federation) | IAM bindings for the principal principal://iam.googleapis.com/projects/PROJECT_NUMBER/locations/global/workloadIdentityPools/PROJECT_ID.svc.id.goog/subject/ns/NAMESPACE/sa/SERVICEACCOUNT, or an IAM service account it may impersonate | Cloud Audit Logs entries for that principal or impersonated service account | Data access and admin activity in the window; see the Google Cloud service account key investigation guide |
The key question is where the exchange happened. Exchanges from the cluster's own egress addresses at the workload's usual rate are expected; exchanges from an unknown network, or a sudden increase in frequency, mean the token was used outside the cluster. Note the lifetime of what was minted: Microsoft states that Entra tokens issued through AKS workload identity expire 24 hours after issue, and Google states GKE metadata server access tokens have a default lifetime of one hour. Those credentials outlive a Kubernetes-side revocation, so Step 6 must cover them.
Step 6: contain and revoke
Containment has to end access on both sides and replace anything the token read. In order:
- Cut RBAC first if the token is long-lived. Removing or narrowing the bindings found in Step 3 takes effect on the next request and does not destroy evidence. It is the fastest control when the token cannot be revoked directly.
- Invalidate the token by its binding. For a pod-bound token, delete the pod; Kubernetes documentation states that deleting a pod expires its bound service account tokens, and authentication fails 60 seconds after the deletion timestamp for objects pending deletion. For a Secret-bound or legacy token, delete the Secret.
- Recreate the service account for unbound tokens. The documentation states there is no specific mechanism to invalidate a token issued via TokenRequest, and that deleting and recreating the service account changes its UID and invalidates all tokens created for it. This also invalidates tokens held by healthy pods, so restart the workload afterwards.
- Contain the cloud identity. Revoke active sessions for the IAM role (for example with a deny policy conditioned on token issue time), revoke or disable the Entra app's credentials or federated credential, or remove the Google IAM binding, according to your provider's procedure. Then restore least-privilege access once the workload is clean.
- Rotate every Secret the token read. Database passwords, API keys and TLS keys stored in those Secrets must be rotated at their source, not just updated in Kubernetes. If you use an external secrets manager, rotate there and let the sync update the cluster.
- Remove persistence. Delete pods, workloads, roles, bindings, service accounts and tokens created during the window, after recording them.
- Consider the signing key for cluster-wide compromise. If the attacker reached control plane hosts or the signing key itself, every token in the cluster is suspect. Rotating the service account signing key (
--service-account-private-key-fileon kube-controller-manager and--service-account-key-fileon kube-apiserver, or the managed provider's equivalent) is a cluster-wide change, handled under the cluster compromise playbook.
Roll back by restoring bindings and workloads from version control, not from the compromised cluster's live state, which may contain the attacker's changes.
Step 7: recover and prevent the repeat
- Close the leak path: if the token came from a pod filesystem through an application flaw, patch the application. If it came from a log or image, remove it and fix the build step.
- Stop mounting tokens that are not needed: set
automountServiceAccountToken: falsewhere the workload never calls the API. See How to find pods that automount service account tokens. - Retire legacy Secret tokens: the legacy token cleaner labels unused auto-generated Secrets with
kubernetes.io/legacy-token-invalid-since; its default period is one year, set by--legacy-service-account-token-clean-up-period. Do not wait for it on accounts you know are exposed. - Narrow RBAC permanently: replace the bindings you cut in containment with namespace-scoped roles that name resources, and remove group bindings to
system:serviceaccounts. - Tighten federation: trust only the exact namespace and service account in each cloud trust policy or federated credential, never a wildcard. The Workload Identity Federation Guide covers this.
Detection and measurement
- Time from detection to invalidation: from first alert to the moment the token stops authenticating, confirmed by 401 responses in the audit log.
- Secrets rotated versus Secrets read: every Secret on the Step 4 list should have a completed rotation; anything less leaves exposed credentials.
- Service account requests from outside pod and node ranges: should be zero in normal operation; alert on any.
- Legacy Secret tokens remaining: a count of
kubernetes.io/service-account-tokenSecrets per cluster, trending to zero. - Service accounts with Secret read or pod create rights: track the number, because each is a high-value token if stolen.
Framework mapping
| Framework | Reference | How it applies |
|---|---|---|
| MITRE ATT&CK | T1528 Steal Application Access Token | Taking the token from a pod, image or log |
| MITRE ATT&CK | T1552.007 Container API | Using the Kubernetes API to read Secrets and other credentials |
| MITRE ATT&CK | T1613 Container and Resource Discovery | Enumerating resources and permissions with the token |
| MITRE ATT&CK | T1611 Escape to Host | Creating privileged or hostPath pods to reach the node |
| MITRE ATT&CK | T1078.004 Cloud Accounts | Using the federated cloud identity obtained from the token |
| NIST CSF 2.0 | DE.AE-02, RS.AN-03, RS.MI-01 | Analysing events, establishing what happened, containing the incident |
| NIST SP 800-53 Rev 5 | IR-4, AC-6, IA-5 | Incident handling, least privilege for the account, authenticator revocation and reissue |
Common failure patterns
- Deleting the pod before capturing it: this revokes the token and destroys the best evidence of how it leaked in the same action.
- Waiting for a short-lived token to expire: an attacker who could create pods or mint tokens during that window may have created their own longer-lived access.
- Searching bindings by name only: group bindings to
system:serviceaccountsor a namespace group give rights that a name search misses. - Revoking the Kubernetes side only: cloud credentials minted earlier remain valid, and the cloud logs are never checked.
- Updating Secrets without rotating the source: changing the Kubernetes Secret object while the database password stays the same leaves the stolen value working.
- Restoring from the live cluster: exporting manifests from a compromised namespace can carry the attacker's added bindings back in.
Practitioner checklist
- Decode the token offline and record subject, binding, JTI, issue time, expiry and audience.
- Preserve the bound pod's spec, logs, image digest and filesystem before deleting anything.
- Classify the token and decide whether containment or evidence comes first.
- Measure RBAC reach with
kubectl auth can-iand a full binding search including groups. - Search audit logs by JTI and username for source, discovery, Secret reads and creations.
- Check cloud logs for token exchanges and actions by the federated identity.
- Invalidate by deleting the bound pod or Secret, or recreate the service account for unbound tokens.
- Contain the cloud role or principal and rotate every Secret the token read at its source.
- Remove created persistence and restore configuration from version control.
- Disable unneeded token automounting and narrow RBAC and federation trust.
Standards and references
- Kubernetes: Managing Service Accounts
- Kubernetes: Authorization
- AWS: IAM roles for service accounts
- AWS: Understand how EKS Pod Identity works
- Microsoft Learn: Use Microsoft Entra Workload ID with Azure Kubernetes Service
- Google Cloud: About Workload Identity Federation for GKE
- NIST: SP 800-61 Rev. 3, Incident Response Recommendations and Considerations for Cybersecurity Risk Management
Related NHI Mgmt Group resources: Reading Service Account Activity in Kubernetes Audit Logs · Kubernetes Service Account Token Guide · How to rotate a Kubernetes service account token and detect old token use · Kubernetes Cluster Compromise Playbook