Service Account Tokens Mounted Unnecessarily

Pods receive a Kubernetes service account token they do not need, which an attacker who compromises the pod can use to call the Kubernetes API.

SeverityLow
CVSS 3.13.3 CVSS:3.1/AV:L/AC:L/PR:L/UI:N/S:U/C:L/I:N/A:N Open in the calculator
CVSS 4.04.8 CVSS:4.0/AV:L/AC:L/AT:N/PR:L/UI:N/VC:L/VI:N/VA:N/SC:N/SI:N/SA:N Open in the calculator
CWECWE-1188: Initialization of a Resource with an Insecure Default
MITRE ATT&CKT1528 Steal Application Access Token
CategorySecurity Misconfiguration

Description

By default, Kubernetes mounts a token for the pod's service account into every container, at /var/run/secrets/kubernetes.io/serviceaccount/token, so that the workload can call the Kubernetes API. Most application workloads never call the API, yet still receive the token because automountServiceAccountToken is not set to false on the pod or its service account. An attacker who gains code execution in the pod can read the token and act on the Kubernetes API as the service account, from inside the cluster or from anywhere the API server is reachable, and removing unneeded tokens takes away a step that many container compromises rely on.

In current Kubernetes versions the mounted token is time-limited and bound to the pod, and the default service account has no permissions beyond basic discovery unless they have been granted, so with default permissions the token gives little more than information about the API. The weakness matters most where workloads share the default service account and someone has granted it permissions, or where a workload's own service account holds rights that the workload rarely uses: there the token can allow reading Secrets, changing workloads or escalating further.

The weakness can be identified by reviewing pod and service account specifications, or from inside a container by checking for the token file and testing what it allows with kubectl auth can-i --list or direct API requests.

Remediation

  • Set automountServiceAccountToken: false on service accounts, including the default service account of each namespace, and on pods that do not call the Kubernetes API. A value set on the pod takes precedence over the service account's.
  • Give each workload that does need the API its own service account with a minimal Role, rather than using or granting rights to default.
  • Where a workload needs a token for another audience, such as a secrets manager or cloud identity federation, use a projected service account token volume with that audience and a short expiry.
  • Remove long-lived service account token Secrets that are no longer needed.
apiVersion: v1 kind: ServiceAccount metadata: name: default namespace: app automountServiceAccountToken: false

Confirm the fix by checking that the token file is absent from the affected containers.

References


Add This Finding to Your Library

In Pental this write-up is in Settings, Library. Add to my library copies it into your own, rated in your firm's CVSS version, ready to put in your own words.

Free trial  ·  No card required

Only need the reporting? Our reporting tool is free and open source, with the same library.


More Containers and Kubernetes Findings

Every Containers and Kubernetes finding