lacework-global-264
Ensure That Instances Are Not Configured To Use the Default Service Account (Automated)
Profile Applicability
• Level 1
Description
Best practices recommend configuring 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 [PROJECT_NUMBER]-compute@developer.gserviceaccount.com
.
Audit
From 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 Command Line:
- 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
.
Remediation
From Console:
- Go to the
VM instances
page by visiting: https://console.cloud.google.com/compute/instances. - Click 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> --service-account=<SERVICE_ACCOUNT>
- Restart the instance:
gcloud compute instances start <instance_name>
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