Review default ServiceAccount permissions and token automounting

Separate workload permissions and avoid automounting API tokens where they are not needed.

Description

Pods using the default ServiceAccount in one namespace authenticate as the same account. Their Pod-bound tokens can differ, but the account’s RBAC permissions apply to each.

Potential impact

A token exposed by one Pod can exercise any permissions granted to the default account. Audit records can make it difficult to identify the originating workload.

Remediation

  • Give workloads that call the API a dedicated account with only the permissions they need. Remove unnecessary grants from the default account.
  • Disable automounting on the default account. For Pods that need no API token, set automount_service_account_token = false on the Pod too. The Pod setting takes precedence, so check the mounts in a newly created Pod.

Examples

Import the existing default ServiceAccount before managing it with Terraform. These examples change only the account’s automount setting.

Before

hcl
resource "kubernetes_service_account" "example" {
  metadata {
    name = "default"
  }

  automount_service_account_token = true
}

After

hcl
resource "kubernetes_service_account" "example" {
  metadata {
    name = "default"
  }

  automount_service_account_token = false
}

Explanation:

  • Before: The default account allows token mounting unless the Pod disables it.
  • After: New Pods do not automatically mount the token unless they opt in. Manage existing tokens and RBAC bindings separately.

References