Description
The cloud-platform scope lets a VM use an OAuth token with many Google Cloud APIs. IAM roles determine what its service account can do on each resource.
Potential impact
An overprivileged service account gives the workload access beyond what it needs.
Remediation
Identify the operations and resources the workload needs. Grant those IAM roles to a dedicated account. Google recommends keeping cloud-platform and controlling access with IAM.
Examples
Both examples keep the same scope. Check the roles granted to dedicated_service_account_email. On an existing VM, stop it, attach the replacement account and restart it before testing the required API calls. For a new VM, also supply the machine type and boot disk.
Before
- name: Create the VM
google.cloud.gcp_compute_instance:
name: test-object
zone: us-central1-a
project: "{{ gcp_project_id }}"
auth_kind: serviceaccount
service_accounts:
- email: "{{ vm_service_account_email }}"
scopes:
- https://www.googleapis.com/auth/cloud-platform
state: present
After
- name: Create the VM
google.cloud.gcp_compute_instance:
name: test-object
zone: us-central1-a
project: "{{ gcp_project_id }}"
auth_kind: serviceaccount
service_accounts:
- email: "{{ dedicated_service_account_email }}"
scopes:
- https://www.googleapis.com/auth/cloud-platform
state: present