Description
If you omit the GKE node service account, nodes use the Compute Engine default service account. Check which IAM roles that account has.
Potential impact
A node using a shared account with broad permissions can affect other Google Cloud resources if the node is compromised.
Remediation
Prepare a dedicated account with the roles needed for node operations and set node_config.service_account to its email. An existing pool’s account is fixed. Create a pool with the dedicated account, move and test the workloads, then retire the old pool. Grant application access separately with Workload Identity Federation for GKE.
Examples
node_service_account_email is the node identity. gcp_service_account_file holds the credentials Ansible uses to create the cluster in gcp_project.
Before
- name: Create the cluster
google.cloud.gcp_container_cluster:
name: my-cluster
initial_node_count: 2
node_config:
machine_type: n1-standard-4
disk_size_gb: 500
location: us-central1-a
project: "{{ gcp_project }}"
auth_kind: serviceaccount
service_account_file: "{{ gcp_service_account_file }}"
state: present
After
- name: Create the cluster
google.cloud.gcp_container_cluster:
name: my-cluster
initial_node_count: 2
node_config:
machine_type: n1-standard-4
disk_size_gb: 500
service_account: "{{ node_service_account_email }}"
location: us-central1-a
project: "{{ gcp_project }}"
auth_kind: serviceaccount
service_account_file: "{{ gcp_service_account_file }}"
state: present