Kubernetes Service Account Token Theft and API Abuse
Adversaries are targeting Kubernetes pods to steal service account tokens and certificates, subsequently using them for cluster-wide reconnaissance and lateral movement.
Adversaries are actively targeting Kubernetes environments by exploiting interactive container sessions to harvest sensitive service account credentials. Attackers gain initial access to a pod (e.g., via kubectl exec) and proceed to read the service account token (/var/run/secrets/kubernetes.io/serviceaccount/token) and the CA certificate (ca.crt). These artifacts provide the necessary credentials to authenticate to the Kubernetes API server as the pod's service account. Once authenticated, the attacker performs unauthorized API requests to conduct cluster reconnaissance, exfiltrate secrets, or attempt lateral movement by escalating privileges or pivoting to other nodes. This activity is notable because it leverages native, legitimate application paths to bypass traditional perimeter security, making correlation between container-level file access and cluster-level audit logs essential for detection.
Attack Chain
- An attacker gains initial interactive access to a container, often through a compromised application or misconfigured pod (
kubectl exec). - The attacker performs a file read operation on the service account token located at
/var/run/secrets/kubernetes.io/serviceaccount/token. - The attacker reads the associated CA certificate at
/var/run/secrets/kubernetes.io/serviceaccount/ca.crtto facilitate TLS communication. - Using the harvested token, the attacker interacts with the Kubernetes API server, typically via
curl,kubectl, or custom scripts. - The API server processes the request, authenticating the attacker as the pod's service account.
- The attacker performs reconnaissance, such as listing pods, secrets, or nodes within the cluster.
- If the service account possesses excessive RBAC permissions, the attacker pivots to other namespaces, modifies RoleBindings, or creates privileged pods to compromise the wider cluster.
Impact
Successful exploitation allows an adversary to impersonate a service account, potentially leading to full cluster compromise. Depending on the service account's RBAC scope, this can result in the exfiltration of sensitive configuration secrets, unauthorized deployment of malicious containers, or total administrative takeover of the Kubernetes environment.
Recommendation
- Deploy the provided detection logic to correlate container file access events with Kubernetes audit logs.
- Implement a policy of least privilege by scoping service account RBAC bindings strictly to the resources required by the application.
- Disable
automountServiceAccountTokenon all pods that do not require interaction with the Kubernetes API. - Enforce Pod Security Admission policies to restrict or eliminate the use of interactive shells (
exec/attach) within production containers. - Monitor Kubernetes audit logs specifically for anomalous verbs or user-agents associated with service accounts, especially those requesting secrets or creating pods in foreign namespaces.
Immediate actions
Review and deploy the provided EQL rule to correlate container and audit logs.
Threat Hunt
Identify pods that recently performed both shell execution and subsequent API requests.
Data: Audit logs, Defend for Containers file access events
Mitigations
Set automountServiceAccountToken: false on all service accounts that do not require API access.
General credential theft risk
Detection coverage 1
Detect Service Account Token or Certificate Access Followed by Kubernetes API Request
mediumDetects interactive access to service account secrets followed by a Kubernetes API request from the same pod, indicating potential credential harvesting and lateral movement.
Detection queries are available on the platform. Get full rules →