Overview
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
The default Compute Engine service account has the Editor role on the project, which allows read and write access to most Google Cloud Services. To defend against privilege escalations if your VM is compromised and prevent an attacker from gaining access to all of your project, it is recommended to not use the default Compute Engine service account. Instead, you should create a new service account and assigning only the permissions needed by your instance.
The default Compute Engine service account is named <projectNumber>[email protected].
Remediation guidance
From Google Cloud Console
- Go to the
VM instancespage by visiting: https://console.cloud.google.com/compute/instances - Click on each VM instance name to go to its details page
- Click
STOPand then clickEDIT - Under the section
Identity and API access, select a service account other than the default Compute Engine service account. You may first need to create a new service account. - Click
Saveand then clickSTART
Using Google Cloud CLI
- Stop the instance:
gcloud compute instances stop <instanceName>
- Update the instance:
gcloud compute instances set-service-account <instanceName> --serviceaccount=<serviceAccount>
- Restart the instance:
gcloud compute instances start <instanceName>
Default Value
By default, Compute instances are configured to use the default Compute Engine service account.
References
- https://cloud.google.com/compute/docs/access/service-accounts
- https://cloud.google.com/compute/docs/access/create-enable-service-accounts-for-instances
- https://cloud.google.com/sdk/gcloud/reference/compute/instances/set-service-account
Service-wide remediation
Recommended when many resources are affected: fix the platform baseline first so new resources inherit the secure setting, then remediate the existing flagged resources in batches.
Google Cloud
Use organization or folder policies where available, shared project templates, logs and alerting baselines, and IaC modules so new resources inherit the secure setting.
Operational rollout
- Fix the baseline first at the account, subscription, project, cluster, or tenant scope that owns this control.
- Remediate the currently affected resources in batches, starting with internet-exposed and production assets.
- Re-scan and track approved exceptions with an owner and expiry date.
Query logic
These are the stored checks tied to this control.
Instances are not configured to use the default service account
Connectors
Covered asset types
Expected check: eq []
vms(where: {serviceAccountEmail_CONTAINS: "[email protected]"}) {...AssetFragment}
Google Cloud