ServiceAccount name is not specified

Specify the account a pod should use and verify its actual permissions.

Description

If service_account_name is empty or omitted, the Pod uses the namespace’s default ServiceAccount. Its RBAC bindings determine what that account can do.

Potential impact

Any extra permission granted to the default account is available to other workloads using it. A shared identity also makes requests harder to attribute.

Remediation

  • Create a dedicated account in the workload’s namespace and grant only the permissions it needs. Disable token automounting if the workload needs no API token.
  • Set the account on the Pod or Pod template. If a variable supplies the name, verify the resolved value. Check the name and permissions on a newly created Pod.

Examples

Create service-name first. Choose a maintained deployment image in place of nginx:1.7.9.

Before

hcl
resource "kubernetes_pod" "pod" {
  metadata {
    name = "terraform-example"
  }

  spec {
    service_account_name = ""

    container {
      image = "nginx:1.7.9"
      name  = "example"
    }
  }
}

After

hcl
resource "kubernetes_pod" "pod" {
  metadata {
    name = "terraform-example"
  }

  spec {
    service_account_name = "service-name"

    container {
      image = "nginx:1.7.9"
      name  = "example"
    }
  }
}

Explanation:

  • Before: The terraform-example Pod uses the default account.
  • After: The same Pod configuration specifies service-name. Its bindings determine the allowed operations.

References