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
Which predefined role lets a user attach a service account to a resource because it includes iam.serviceAccounts.actAs?
- roles/iam.serviceAccountUser
- roles/iam.serviceAccountViewer
- roles/viewer
- 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.
Which practices follow least privilege for service accounts?
- Grant the service account a read-only role on the one bucket it needs
- Grant serviceAccountUser on individual accounts, not the project
- Keep Editor on the default account so new features just work
- Give each pipeline Owner to avoid permission errors
- 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.
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.
