Bitzu

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

Single choice

Which access scope does Google recommend setting on a VM, relying on IAM roles to restrict access?

  1. https://www.googleapis.com/auth/cloud-platform
  2. https://www.googleapis.com/auth/devstorage.read_only
  3. https://www.googleapis.com/auth/logging.write
  4. 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.

Select all that apply

Which resources can run as an attached user-managed service account?

  1. A Compute Engine VM
  2. A Cloud Run service
  3. A VPC firewall rule
  4. A GKE node pool
  5. 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.

True or false

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.

Download on the App StoreGet it on Google Play

More Associate Cloud Engineer topics in this module