Description
It is recommended to configure your instance to not use the default Compute Engine service account because it has the Editor role on the project.
Rationaleβ
When a default Compute Engine service account is created, it is automatically granted the Editor role (roles/editor) on your project which allows read and write access to most Google Cloud Services. This role includes a very large number of permissions. To defend against privilege escalations if your VM is compromised and prevent an attacker from gaining access to all of your project, you should either revoke the Editor role from the default Compute Engine service account or create a new service account and assign only the permissions needed by your instance. To mitigate this at scale, we strongly recommend that you disable the automatic role grant by adding a constraint to your organization policy.
The default Compute Engine service account is named [PROJECT_NUMBER]-compute@developer.gserviceaccount.com
.
Auditβ
From Google Cloud Consoleβ
- Go to the
VM instances
page by visiting: https://console.cloud.google.com/compute/instances. - Click on each instance name to go to its
VM instance details
page. - Under the section
API and identity management
, ensure that the default Compute Engine service account is not used. This account is named[PROJECT_NUMBER]-compute@developer.gserviceaccount.com
.
From Google Cloud CLIβ
-
List the instances in your project and get details on each instance:
gcloud compute instances list --format=json | jq -r '. | "SA: \(.[].serviceAccounts[].email) Name: \(.[].name)"'
-
Ensure that the service account section has an email that does not match the pattern
[PROJECT_NUMBER]-compute@developer.gserviceaccount.com
.
Exceptionβ
VMs created by GKE should be excluded. These VMs have names that start with gke-
and are labeled goog-gke-node
.
Default Valueβ
By default, Compute instances are configured to use the default Compute Engine service account.