Cloud IAM on Google Cloud: Principals, Roles, Policies, Service Accounts and Least Privilege

Google Cloud Platform Architect 55 min min read Updated: Nov 17, 2026 Beginner
Cloud IAM on Google Cloud: Principals, Roles, Policies, Service Accounts and Least Privilege
Beginner Topic 1 of 3

The IAM Question

IAM answers: who (principal) can do what (role) on which resource. In Google Cloud this is written as a binding in an allow policy.

text Principal + Role on Resource user:asha@example.com roles/storage.objectViewer on bucket "reports"

Principals (Who)

TypeExampleUse
Google account / useruser:asha@example.comA person
Groupgroup:devs@example.comBest way to give access to teams
Service accountserviceAccount:app@proj.iam.gserviceaccount.comAn identity for an application or VM
Domaindomain:example.comEveryone in a domain
Workforce / workload identity poolFederated identitiesExternal IdP users or other clouds

Roles (What)

Role typeDescriptionAdvice
BasicOwner, Editor, Viewer. Very broadAvoid in production
PredefinedCreated by Google per product, for example roles/storage.objectViewerPrefer these
CustomYou pick exact permissionsUse when predefined is too wide
  • A permission is one action, for example storage.objects.get
  • A role is a bundle of permissions
  • Use the IAM Recommender to find unused permissions and shrink roles
bash gcloud iam roles describe roles/storage.objectViewer gcloud projects add-iam-policy-binding my-proj --member="group:devs@example.com" --role="roles/viewer" gcloud storage buckets add-iam-policy-binding gs://reports --member="user:asha@example.com" --role="roles/storage.objectViewer" gcloud projects get-iam-policy my-proj --format=jso

Inheritance

Policies set at the organization or folder flow down to projects and resources. Give access at the lowest level that works.

Service Accounts

  • A service account is an identity for code, not a person
  • Attach it to a VM, Cloud Run service or GKE workload so apps get temporary credentials automatically
  • Create one service account per application with only the roles it needs
  • A service account is also a resource: people need roles/iam.serviceAccountUser to attach it, and roles/iam.serviceAccountTokenCreator to impersonate it
bash gcloud iam service-accounts create report-app --display-name="Report app" gcloud projects add-iam-policy-binding my-proj --member="serviceAccount:report-app@my-proj.iam.gserviceaccount.com" --role="roles/bigquery.dataViewer" gcloud compute instances create app-vm --zone=asia-south1-a --service-account=report-app@my-proj.iam.gserviceaccount.com --scopes=cloud-platform
Avoid service account keys A downloaded JSON key is a long-lived password. Prefer attached service accounts, impersonation, or Workload Identity Federation for outside systems. Block key creation with an organization policy.

Workload Identity Federation

Lets GitHub Actions, AWS, Azure or any OIDC/SAML provider call Google Cloud with a short-lived token without a key file. On GKE, Workload Identity links a Kubernetes service account to a Google service account.

Conditions and Deny

  • IAM Conditions: grant a role only when a rule is true, for example before an expiry time or on resources with a tag
  • Deny policies: block selected permissions even if a role grants them (guardrails)
  • Privileged Access Manager: just-in-time elevated access with approvals

Best Practices

  1. Use groups, not individuals
  2. Use predefined roles, avoid Owner and Editor
  3. Grant at the lowest level possible
  4. One service account per workload, no keys
  5. Turn on audit logs and review with Recommender
  6. Separate duties: the person who deploys is not the person who approves

Practice

  1. Give a group Storage Object Viewer on one bucket only
  2. Create a service account and attach it to a VM
  3. Use gcloud projects get-iam-policy to list who has Owner
  4. Write a custom role with only three permissions

Conclusion

IAM binds principals to roles on resources and policies inherit down the hierarchy. Prefer groups, predefined roles, attached service accounts and Workload Identity Federation, and avoid basic roles and key files.

Quick Summary: question; principals; roles; inheritance; service accounts; federation; conditions; practices.

Get Newsletter

Subscibe to our newsletter and we will notify you about the newest updates on Edugators