Most Kubernetes API traffic comes from service accounts, yet most teams cannot say what a given service account actually did last week. The audit log already holds the answer: every request a workload or controller makes carries a service account username, a verb, an object and, for bound tokens, the pod and token ID it came from. This guide shows platform security and NHI teams how to read those events, which fields identify the workload behind a request, how to spot a token being used from outside the cluster, and where to find the same data on AKS, EKS and GKE. It assumes audit logging is already switched on; for audit policy design and general detections across all identities, see the Kubernetes Audit Log Detection Guide.
Key takeaways
- The username tells you who, the extra fields tell you where.
system:serviceaccount:<namespace>:<name>names the account, whileauthentication.kubernetes.io/pod-name,pod-uidandcredential-idtie a request to a specific pod and token. - Singular is a user, plural is a group.
system:serviceaccount:prefixes usernames andsystem:serviceaccounts:prefixes groups, and RBAC bindings to the plural group grant every service account in scope. - A missing pod name is a signal. A request authenticated as a service account with no pod binding comes from a manually issued or legacy Secret token, which can be used from anywhere the token has travelled.
- Source IP plus user agent catches stolen tokens. Workload tokens should arrive from pod or node addresses with the workload's own client string, not from an external address with a
kubectluser agent. - Baseline per service account, not per cluster. Each workload calls a small, stable set of verbs and resources, so deviations from that set are among the highest-fidelity alerts available.
Audit policy prerequisites
Service account analysis depends on what the audit policy keeps. The rules that matter for this page:
- Metadata level at minimum for everything a workload can touch: user, groups, extra, verb, objectRef, sourceIPs, userAgent and responseStatus are all present at
Metadata. Request bodies are only needed where the body is the signal (pod specs, RBAC objects). - Do not drop service accounts wholesale: a
level: Nonerule scoped tosystem:serviceaccountsto cut noise removes the very activity this guide reads. Scope noise rules to named controllers and resources, such as leader election leases. - Keep reads:
get,listandwatchon secrets, configmaps and the API discovery endpoints are how token theft and reconnaissance show up. On AKS, thekube-audit-admincategory excludesgetandlist, so it alone cannot answer "which service account read this Secret". - Keep token requests visible:
serviceaccounts/token(the TokenRequest subresource) atMetadata, so you can see who minted a token for which account without storing the token. - Retention long enough to baseline: 30 days of hot data is a practical minimum for building per-account baselines; see the CIS Control 8 Audit Log Management Guide for retention and integrity.
Identifying service account requests
Kubernetes documentation states that service accounts authenticate with the username system:serviceaccount:(NAMESPACE):(SERVICEACCOUNT) and are assigned to the groups system:serviceaccounts and system:serviceaccounts:(NAMESPACE). Every authenticated request also carries system:authenticated. Filtering on the username prefix gives you all workload and controller traffic; filtering on the namespace segment lets you hand each team the activity of its own accounts.
Which token type made the request
The extra fields in user.extra show how the token was issued. The documentation's TokenReview example for a pod-bound token shows these keys:
| Extra key | What it holds | How to use it |
|---|---|---|
authentication.kubernetes.io/credential-id | JTI=<uuid>, the token's unique ID | Group all requests made with one token; spot the same JTI from two different source IPs |
authentication.kubernetes.io/pod-name and pod-uid | The pod the token is bound to | Map activity to a workload; a token whose pod UID no longer exists is refused by the API server |
authentication.kubernetes.io/node-name and node-uid | The node the bound pod was scheduled to | Compare with the source IP; the docs note this node data is not verified by kube-apiserver, so treat it as context, not proof |
| No pod or node keys | A token not bound to a pod: kubectl create token without a bound object, or a legacy kubernetes.io/service-account-token Secret | Investigate: these tokens work from any network location until they expire or are deleted |
Projected tokens mounted by the kubelet are bound to the pod, so in a healthy cluster almost all workload traffic carries pod keys. The live Kubernetes Service Account Token Guide covers token types and lifetimes in depth.
Legacy token markers
In Kubernetes 1.30 and later (the cleaner is stable from 1.30), auto-generated legacy Secret tokens that stay unused are marked invalid (default one year) and later purged. If someone presents an invalidated token, the API server adds the audit annotation authentication.k8s.io/legacy-token-invalidated: <secret name>/<namespace>, increments invalid_legacy_auto_token_uses_total and updates the Secret label kubernetes.io/legacy-token-last-used. Any hit on that annotation means an old token is still circulating, often in a CI system or a laptop kubeconfig.
Key fields (user, verb, objectRef, sourceIPs)
The live audit detection guide lists every event field. The table below reads the same fields through a service account lens.
| Field | Normal for a workload service account | Worth a second look |
|---|---|---|
user.username | Matches the pod's spec.serviceAccountName | The default account of a namespace making write calls; an account from one namespace acting in another |
impersonatedUser | Absent | Present: a service account using impersonation headers to act as another identity |
verb | A short stable set, for example get and watch on configmaps | First-ever create, patch or delete; list across all namespaces |
objectRef (resource, subresource, namespace) | The resources in the workload's Role | secrets, pods/exec, serviceaccounts/token, clusterrolebindings, selfsubjectrulesreviews |
sourceIPs | Pod CIDR or node addresses | Addresses outside the cluster's pod and node ranges |
userAgent | The workload's client library string, stable across versions | kubectl/, curl/ or a scripting library when the workload normally uses something else |
responseStatus.code | Mostly 200 and 201 | Bursts of 403: the account is probing what it may do |
annotations["authorization.k8s.io/reason"] | The expected Role or ClusterRole binding | A binding to system:serviceaccounts or a wide ClusterRole that nobody intended for this workload |
Source IPs need care. Behind a load balancer or proxy the first address may be the intermediary, and on managed control planes traffic from nodes may be translated. Record what "normal" looks like for each cluster before you alert on it.
Suspicious patterns
Each pattern below is a reading of service account events, mapped to MITRE ATT&CK where the technique fits.
| Pattern | What you see in the events | ATT&CK |
|---|---|---|
| Token reuse from outside the cluster | Same credential-id or same pod-bound username from a non-cluster source IP, often with a different user agent | T1528 Steal Application Access Token; T1550.001 Application Access Token |
| Reconnaissance with a workload token | selfsubjectrulesreviews or selfsubjectaccessreviews creates, wide list calls, 403 bursts | T1613 Container and Resource Discovery |
| Secret harvesting | get or list on secrets by an account that never read them before, or across namespaces | T1552.007 Container API |
| Exec from a workload identity | create on pods/exec or pods/attach by a service account other than a known operator or CI account | T1609 Container Administration Command |
| Token minting for another account | create on serviceaccounts/token where the caller is not the kubelet or an approved controller | T1528 Steal Application Access Token |
| RBAC self-escalation | create or patch on rolebindings or clusterrolebindings naming the caller's own account | T1098.003 Additional Cloud Roles (closest fit) |
| Default account in use | system:serviceaccount:<ns>:default making write calls | T1078.001 Default Accounts |
The Kubeflow campaign shows the pattern in practice: attackers reached notebook servers through exposed dashboards and used the mounted service account to create workloads in the namespace. In audit terms that is a notebook account issuing first-ever create calls on deployments or pods. See the Kubeflow cryptomining attacks.
Managed cluster audit logs
The managed services hold the same Kubernetes audit events but expose them in their own logging products. Platforms are listed alphabetically; each is a customer-side setting.
| Platform | How to collect | Where service account events land | Field to filter on |
|---|---|---|---|
| Azure Kubernetes Service (AKS) | Diagnostic setting with kube-audit (all events) and optionally kube-audit-admin (excludes get and list); resource-specific mode recommended | Log Analytics tables AKSAudit and AKSAuditAdmin, or AzureDiagnostics in Azure diagnostics mode | The event's user.username, sourceIPs and verb |
| Amazon Elastic Kubernetes Service (EKS) | Enable the audit control plane log type, plus authenticator to see IAM to Kubernetes mappings; each type is enabled individually | CloudWatch Logs group /aws/eks/<cluster>/cluster, streams named kube-apiserver-audit-<id> | user.username, user.extra, sourceIPs in the JSON event |
| Google Kubernetes Engine (GKE) | Admin Activity audit logs are always on; Data Access logs (which include reads) must be enabled | Cloud Logging, resource type k8s_cluster, logs cloudaudit.googleapis.com%2Factivity and cloudaudit.googleapis.com%2Fdata_access | protoPayload.authenticationInfo.principalEmail, protoPayload.requestMetadata.callerIp, protoPayload.methodName (form io.k8s.<group>.<version>.<resource>) |
Availability notes: AKS documentation warns that kube-audit collection can be costly and suggests resource-specific tables configured as Basic logs. On EKS and GKE, check the provider's logging pricing before enabling read-inclusive streams. On every platform, service account secret reads appear only when the read-inclusive stream is collected. For platform hardening beyond logging, see the Azure Kubernetes Service Security Hardening Guide, the Amazon EKS Security Hardening Guide and the GKE Security Hardening Guide.
Building detections
- Inventory the accounts: list every service account and the pods that use it. Accounts with no pods are candidates for removal; see How to find unused Kubernetes service accounts.
- Record network ranges: pod CIDRs, node subnets, control plane and any NAT addresses per cluster. Store them as a lookup table in the SIEM.
- Build a per-account baseline: over 14 to 30 days, record for each username the set of (verb, resource, subresource, namespace) tuples and user agents. This is usually a few dozen rows per workload.
- Write the external-use rule first: alert when a
system:serviceaccount:username succeeds from an address outside the lookup table. This is the highest-value single rule and has few false positives once ranges are right. - Add the unbound-token rule: alert on service account requests with no
authentication.kubernetes.io/pod-namekey, excluding a short allowlist of CI accounts that legitimately use TokenRequest tokens. Also alert on anylegacy-token-invalidatedannotation. - Add deviation rules: new tuple for an account (start in report-only mode), sensitive-resource access (secrets, exec, token, RBAC) outside the baseline, and 403 bursts above a threshold.
- Correlate with JTI: the same
credential-idseen from two source IPs within a short window means one token, two holders. - Tune and promote: run new rules silently for two weeks, review every hit with the owning team, then promote to alerting. Roll back a rule by returning it to report-only rather than deleting it.
The broader method for writing and testing identity detections is in the Detection Engineering for Non-Human Identities Guide.
Measuring it
- Attribution rate: share of service account requests carrying pod keys (target: close to 100% outside named CI accounts).
- Baseline coverage: share of active service accounts with a baseline older than 14 days.
- External-use alerts: count per month and time to triage; each should end in a confirmed benign source or a revoked token.
- Legacy token hits:
legacy-token-invalidatedannotations and legacy Secret tokens in use, trending to zero. - Default account writes: number of write calls by
defaultaccounts, trending to zero.
Where identity fits
Audit analysis tells you what a service account did; RBAC decides what it could do. Use the observed tuple set to tighten each Role to the verbs and resources the workload really uses, turn off automountServiceAccountToken for pods that never call the API, and replace long-lived Secret tokens with bound tokens. The Kubernetes NHI Security Guide covers the identity model, and How to rotate a Kubernetes service account token and detect old token use covers cutover.
Framework mapping
| Framework | Reference | How this page applies |
|---|---|---|
| NIST SP 800-53 Rev. 5 | AU-2, AU-6, AU-12 | Log service account events and review them against baselines |
| NIST SP 800-53 Rev. 5 | AC-6(9), AC-2 | Log use of privileged functions; manage and remove unused accounts |
| NIST CSF 2.0 | DE.CM-03, DE.CM-09, DE.AE-02 | Monitor technology usage and runtime environments; analyse anomalies |
| CIS Controls v8.1 | Control 8 Audit Log Management | Collect, retain and review audit logs |
| MITRE ATT&CK v20 | T1528, T1550.001, T1552.007, T1609, T1613, T1078.001 | Techniques visible through service account audit events |
Practitioner checklist
- Confirm the audit policy logs service account reads,
serviceaccounts/tokenandpods/execat Metadata or higher. - On AKS collect
kube-audit, on EKS enableauditandauthenticator, on GKE enable Data Access logs where reads matter. - Keep a lookup of pod, node and NAT ranges per cluster in the SIEM.
- Alert on any service account request from outside those ranges.
- Alert on service account requests with no pod binding, outside a named allowlist.
- Alert on every
authentication.k8s.io/legacy-token-invalidatedannotation. - Baseline verb and resource tuples per account and review new tuples weekly.
- Correlate requests by
credential-idto catch one token used from two places. - Feed observed tuples back into Role reviews to shrink permissions.
Standards and references
- Kubernetes: Auditing
- Kubernetes: Managing Service Accounts
- Kubernetes: Authenticating
- Kubernetes: Audit Annotations
- Microsoft Learn: Monitor Azure Kubernetes Service
- AWS: Send control plane logs to CloudWatch Logs
- Google Cloud: GKE audit logging
- MITRE ATT&CK: T1528 Steal Application Access Token
Related NHI Mgmt Group resources: Kubernetes Audit Log Detection Guide · Kubernetes Service Account Token Guide · Kubernetes NHI Security Guide · Detection Engineering for Non-Human Identities Guide