Skip to the content
Fabian Lee : Software EngineerFabian Lee : Software Engineer
Cloud Operations and Development
  • Monitoring
  • Logging
  • Containers
  • Python

GCP: VM instances running as the Compute Engine default service account

March 31, 2022
Categories: Hyperscaler, Scripting

The Compute Engine default service account is automatically generated for your project with the Editor role, and by default is attached to all VM instances created in the project.

You can pull the exact id using gcloud.

gcloud iam service-accounts list --filter="displayName:'Compute Engine default service account'" --format='value(email)'

The syntax will be ${project_id}-compute@developer.gserviceaccount.com.  If you want to check your list of VM instances to see what service account they are running under (if any at all), then run the command below.

gcloud compute instances list --format="value(name,zone,status,serviceAccounts.email)"

# filter by name containing
search_string=apache1
gcloud compute instances list --format="value(name,zone,status,serviceAccounts.email)" --filter=name~${search_string}

If you need to change the service account the VM is running under, it requires that you stop the instance first.

gcloud compute instances stop $name --zone=zone

gcloud compute instances set-service-account $name --zone=$zone --service-account=$new_service_account

gcloud compute instances start $name --zone=zone

REFERENCES

garapost.com, getting compute engine service account with gcloud

gcloud ref, instances stop

gcloud ref, set-service-account

 

Categories: Hyperscaler, Scripting Tags: account, compute, default, engine, gcloud, instances, service, vm

Post navigation

← GCP: global external HTTPS LB for securely exposing insecure VM services
GCP: Deploying a 2nd gen Python Cloud Function and exposing from an HTTPS LB →
© 2025 Fabian Lee : Software Engineer