Description
Set node_config.service_account on each GKE node pool that will run workloads.
Potential impact
If a shared account has broad IAM roles, exposed node credentials can affect other resources. Check the roles actually granted to the default account.
Remediation
Give a dedicated account the roles needed for node operations. To change an existing pool’s account, create a replacement pool with the new account. Move the workloads and verify they run before retiring the old pool. Grant applications their own access with Workload Identity Federation for GKE.
Examples
Both examples set remove_default_node_pool = true, so GKE removes the pool configured here. Create google_service_account.myserviceaccount and also set the account on each production google_container_node_pool. Both examples keep the cloud-platform scope.
Before
resource "google_container_cluster" "example" {
name = "my-gke-cluster"
location = "us-central1"
remove_default_node_pool = true
initial_node_count = 1
node_config {
oauth_scopes = [
"https://www.googleapis.com/auth/cloud-platform"
]
}
}
After
resource "google_container_cluster" "example" {
name = "my-gke-cluster"
location = "us-central1"
remove_default_node_pool = true
initial_node_count = 1
node_config {
service_account = google_service_account.myserviceaccount.email
oauth_scopes = [
"https://www.googleapis.com/auth/cloud-platform"
]
}
}