Join our Newsletter — 33% off our NHI Course
Home› Guides› How to investigate a compromised Kubernetes service account…
Guide Incident Response & Forensics

How to investigate a compromised Kubernetes service account token: scope, trace and revoke in order

PDF for newsletter subscribers · free to read online

← All guides
By NHI Mgmt Group, under the editorial direction of Lalit Choda Updated 28 November 2026 14 min read
On this page

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 propertyWhat it tells youWhy it matters for the investigation
sub (system:serviceaccount:<namespace>:<name>)The service accountThe 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 toBound tokens stop authenticating once that object is deleted; this is your fastest revocation path
Node name and uid in the pod claimsWhere the bound pod was scheduledContext only: the Kubernetes docs state that kube-apiserver does not verify this node information
jtiUnique token ID, shown in audit events as authentication.kubernetes.io/credential-idLets you find every request made with this exact token
iat, expIssue time and expiryDefines the earliest and latest possible use
audIntended audienceAn audience such as sts.amazonaws.com or pods.eks.amazonaws.com signals a token meant for a cloud exchange
No exp and no bindingA legacy Secret-based tokenValid 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 classTypical lifetimeRevocation pathPriority
Projected token bound to a running podShort-lived; kubelet refreshes it before expiryDelete the pod after evidence captureContain within the hour once the pod is preserved
Token from kubectl create token or TokenRequest, no bindingSet at creation, can be longNo per-token revocation; recreate the service account or wait for expiryHigh: plan the recreate immediately
Token bound to a SecretUntil the Secret is deletedDelete the SecretHigh, and a quick action
Legacy kubernetes.io/service-account-token SecretDoes not expireDelete the SecretCritical: act first, investigate second
Token with a cloud audience (IRSA, Pod Identity, workload identity)Kubernetes token short; minted cloud credentials have their own lifetimeRevoke the Kubernetes side and contain the cloud role or principalHigh, 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.

  1. Ask the API server directly. Kubernetes documents kubectl auth can-i with impersonation for checking what another identity can do, for example kubectl auth can-i list secrets --namespace target --as system:serviceaccount:dev:dev-sa. Adding --list gives the full rule set in a namespace. Run it for the account's own namespace and for every namespace it has bindings in.
  2. Enumerate bindings, including group bindings. List every RoleBinding and ClusterRoleBinding whose subjects include the service account, the group system:serviceaccounts:<namespace> or the group system:serviceaccounts. A binding to a group grants the account rights you will not see by searching for its name.
  3. Flag the dangerous verbs. Any of these turns a workload token into a cluster compromise: get or list on secrets; create on pods or workload controllers (which can mount other service accounts); create on serviceaccounts/token; impersonate; escalate or bind on roles; patch on nodes; exec into pods. The Kubernetes escalate and bind Verbs and Kubernetes impersonate Verb guides explain why.
  4. Check for cluster-admin. If any binding gives the account cluster-admin or 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 sourceIPs and userAgent with the workload's normal pattern. A workload token used from an address outside the pod and node ranges, or with a kubectl user agent the application never uses, is the clearest sign of theft.
  • Did it look around? A burst of list calls across resource types, selfsubjectaccessreviews or selfsubjectrulesreviews creation, 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=secrets with verbs get, list and watch, and responseStatus.code 200. A successful list returns 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 create or patch on pods, deployments, daemonsets, cronjobs, roles, rolebindings, serviceaccounts and serviceaccounts/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 hostPath mounts, privileged: true or 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.

PlatformHow to tell the account is federatedWhere the exchange shows upWhat to search next
Amazon EKS (IAM roles for service accounts)Service account annotation with an IAM role ARN; an IAM OIDC provider for the clusterAWS STS AssumeRoleWithWebIdentity in CloudTrailActions by the resulting role session; see How to Investigate CloudTrail for a Compromised Access Key
Amazon EKS Pod IdentityAn EKS Pod Identity association mapping a role to the service account and namespaceThe Pod Identity Agent calls AssumeRoleForPodIdentity on the EKS Auth API; AWS states CloudTrail logging is availableActions 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 identityMicrosoft Entra service principal sign-in logs for that client IDAzure 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 impersonateCloud Audit Logs entries for that principal or impersonated service accountData 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:

  1. 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.
  2. 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.
  3. 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.
  4. 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.
  5. 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.
  6. Remove persistence. Delete pods, workloads, roles, bindings, service accounts and tokens created during the window, after recording them.
  7. 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-file on kube-controller-manager and --service-account-key-file on 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: false where 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-token Secrets 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

FrameworkReferenceHow it applies
MITRE ATT&CKT1528 Steal Application Access TokenTaking the token from a pod, image or log
MITRE ATT&CKT1552.007 Container APIUsing the Kubernetes API to read Secrets and other credentials
MITRE ATT&CKT1613 Container and Resource DiscoveryEnumerating resources and permissions with the token
MITRE ATT&CKT1611 Escape to HostCreating privileged or hostPath pods to reach the node
MITRE ATT&CKT1078.004 Cloud AccountsUsing the federated cloud identity obtained from the token
NIST CSF 2.0DE.AE-02, RS.AN-03, RS.MI-01Analysing events, establishing what happened, containing the incident
NIST SP 800-53 Rev 5IR-4, AC-6, IA-5Incident 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:serviceaccounts or 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-i and 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

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

PDF for subscribers

Take this guide with you

Every section, table and checklist in one PDF, with links to the sources and related guides. Subscribe to our weekly NHI & AI Identity Journal and we’ll email you a download link.

Free weekly newsletter

Subscribe to the NHI & AI Identity Journal

The latest on NHI and Agentic AI security – articles, research, breaches, news and events every week.

Bonus 33% off our NHI Course when you subscribe.

PDF Downloads for Newsletter Subscribers

Get the guide

Enter your details and we’ll email you a download link.

The full guide is free to read online. The PDF is a thank you for subscribing.

Fill in all fields marked * and tick both boxes to continue.