Bitzu

Associate Cloud Engineer ยท Service accounts fundamentals

Least privilege for service accounts

Granting roles to a service account on resources, avoiding Editor on default accounts, who can act as the account (iam.serviceAccountUser), managing the IAM policy on the account itself.

Key points

  • Two separate questions: what the account can do (roles granted TO it on projects or resources, keep them narrow, avoid Editor) and who can use it (roles granted ON it, mainly roles/iam.serviceAccountUser, which includes iam.serviceAccounts.actAs).
  • Grant serviceAccountUser on the single account rather than the whole project when you can.

Source: https://docs.cloud.google.com/iam/docs/service-accounts-actas

Practice questions

Single choice

Which predefined role lets a user attach a service account to a resource because it includes iam.serviceAccounts.actAs?

  1. roles/iam.serviceAccountUser
  2. roles/iam.serviceAccountViewer
  3. roles/viewer
  4. roles/iam.serviceAccountKeyAdmin
Show answer

Answer: A. roles/iam.serviceAccountUser

Service Account User carries actAs. Token Creator is about creating tokens for impersonation, and Viewer roles only read.

Select all that apply

Which practices follow least privilege for service accounts?

  1. Grant the service account a read-only role on the one bucket it needs
  2. Grant serviceAccountUser on individual accounts, not the project
  3. Keep Editor on the default account so new features just work
  4. Give each pipeline Owner to avoid permission errors
  5. Use a separate account per workload with only its required roles
Show answer

Answer: A. Grant the service account a read-only role on the one bucket it needs, B. Grant serviceAccountUser on individual accounts, not the project, E. Use a separate account per workload with only its required roles

Narrow roles on the specific resource and narrow actAs grants limit exposure. Owner or project-wide serviceAccountUser for convenience does the opposite.

True or false

Granting a user roles/iam.serviceAccountUser at the project level lets them impersonate only one specific service account.

Show answer

Answer: False

False. At project level it covers every service account in the project. To limit it to one account, grant the role on that account.

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