Associate Cloud Engineer ยท Service accounts fundamentals
Attaching a service account to a resource
Attaching to VMs, Cloud Run, functions and GKE nodes, access scopes vs IAM, changing a VM's service account, ADC on the resource.
Key points
- A VM (also Cloud Run, GKE nodes) can run as a service account; code gets credentials automatically through Application Default Credentials, no key file.
- Access scopes (Compute Engine): cap which APIs can be called.
- IAM roles: decide what is allowed.
- Common pattern: cloud-platform scope plus narrow roles.
- Change a VM's account: stop it, run gcloud compute instances set-service-account, start it.
Source: https://docs.cloud.google.com/compute/docs/instances/change-service-account
Practice questions
Which access scope does Google recommend setting on a VM, relying on IAM roles to restrict access?
- https://www.googleapis.com/auth/cloud-platform
- https://www.googleapis.com/auth/devstorage.read_only
- https://www.googleapis.com/auth/logging.write
- No scope, because scopes are always ignored
Show answer
Answer: A. https://www.googleapis.com/auth/cloud-platform
cloud-platform lets the account call any API it has IAM permission for, so IAM becomes the control. Narrow scopes can silently block calls IAM would allow.
Which resources can run as an attached user-managed service account?
- A Compute Engine VM
- A Cloud Run service
- A VPC firewall rule
- A GKE node pool
- A VPC network
Show answer
Answer: A. A Compute Engine VM, B. A Cloud Run service, D. A GKE node pool
VMs, Cloud Run services and GKE node pools can all be assigned a service account identity. Firewall rules and VPC networks are not workloads and have no runtime identity.
You can change the service account of a Compute Engine VM while it is running.
Show answer
Answer: False
False. The VM must be stopped first, then you change the account and start it again.
Practice 8 questions on this topic in Bitzu
Short lessons, instant explanations and spaced review of what you get wrong. Free on iOS and Android.
