Control: 4.1 Ensure That Instances Are Not Configured To Use the Default Service Account
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.
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 [PROJECT_NUMBER]- compute@developer.gserviceaccount.com
.
Remediation
From Console
- Go to the
VM instances
page by visiting: https://console.cloud.google.com/compute/instances. - Click on the instance name to go to its
VM instance details
page. - Click
STOP
and then clickEDIT
. - Under the section
API and identity management
, select a service account other than the default Compute Engine service account. You may first need to create a new service account. - Click
Save
and then clickSTART
.
From Command Line
- Stop the instance:
gcloud compute instances stop <INSTANCE_NAME>
- Update the instance:
gcloud compute instances set-service-account <INSTANCE_NAME> --serviceaccount=<SERVICE_ACCOUNT>
- Restart the instance:
gcloud compute instances start <INSTANCE_NAME>
Default Value
By default, Compute instances are configured to use the default Compute Engine service account.
Usage
Run the control in your terminal:
powerpipe control run gcp_compliance.control.cis_v300_4_1
Snapshot and share results via Turbot Pipes:
powerpipe loginpowerpipe control run gcp_compliance.control.cis_v300_4_1 --share
SQL
This control uses a named query:
compute_instance_with_no_default_service_account