← back to the blog

GCP permissions: IAM, roles and permissions demystified

The mental model behind IAM in Google Cloud: who can do what on which resource. Principals, permissions, the three kinds of role, inheritance through the hierarchy and service accounts.

IAM is one of those things that looks tangled until you see the mental model behind it. In GCP, all access control boils down to one sentence:

A principal has a role on a resource.

Or, spelled out: who can do what on which resource. Once that structure is clear, the rest is detail. Let’s take it piece by piece.

Principal who has a ROLE (bundle of permissions) Resource what / where

The three ingredients

1. The principal (who)

This is the identity asking to do something. It can be:

  • A person (user:[email protected])
  • A Google group (group:[email protected])
  • A service account (serviceAccount:[email protected])
  • A Workspace/Cloud Identity domain
  • Or the special allAuthenticatedUsers and allUsers (watch out for these two: they are close to public access, so use them very carefully)

2. The permission (what)

A permission is an atomic action. It always follows the format service.resource.verb:

compute.instances.start
storage.objects.get
iam.serviceAccounts.actAs

The key detail: you never grant individual permissions to a principal. Permissions come bundled into roles.

3. The role (the bundle of permissions)

A role is a collection of permissions. There are three kinds, and choosing well among them is half the job:

Kind What it is When to use it
Basic Owner, Editor, Viewer. Inherited from the pre-IAM days, they span thousands of permissions. Almost never in production. They are a bucket when you need a spoon.
Predefined Granular and maintained by Google (roles/storage.objectViewer, roles/compute.admin). Your default choice. They cover almost every real case.
Custom You define them, picking permission by permission. When no predefined role fits and you need fine-grained least privilege.

The rule of thumb: predefined before basic, custom only when you really need it.

The IAM policy: where it all comes together

Access doesn’t live in the principal or in the role: it lives on the resource, in an object called an allow policy. That policy is a list of bindings, and each binding ties together:

role  +  one or more principals  (+ an optional condition)

Granting access means adding a binding. With gcloud:

gcloud projects add-iam-policy-binding my-project \
  --member="user:[email protected]" \
  --role="roles/storage.objectViewer"

And to see who has what on a project:

gcloud projects get-iam-policy my-project

That is, literally, the whole mechanism. What makes it look complex is what comes next: the hierarchy.

Hierarchy and inheritance

GCP resources aren’t loose, they hang from a tree:

Organization Folder Project Resources the policy is inherited and adds up

And here is the important part: policies are inherited downwards and they add up. A role granted at the organization or folder level applies to every project and resource hanging below it.

A principal’s effective access is the union of everything granted at its own level and at every level above. Two consequences worth keeping in mind at all times:

  • A binding at a high level is very powerful: roles/editor at the organization level means editor on absolutely everything.
  • An allow policy on a child cannot remove what a parent granted. It is additive. To subtract permissions you have IAM Deny policies and Organization Policies, which are a different tool.

That is why least privilege in GCP is mostly decided by where you place the binding, not only by which role you grant.

Service accounts: identity and resource at once

Service accounts are confusing because they are two things at the same time:

  1. A principal → you grant it roles to define what that account can do (e.g. letting your app read a bucket).
  2. A resource → other principals can hold roles on it, to define who can use or impersonate it.
Other principals Service Account Resources roles ON it who impersonates it roles IT holds what it can do

That second part is the one people forget most often, and the one behind most security incidents. Two critical roles on a service account:

  • roles/iam.serviceAccountUser → lets someone attach that SA to a resource (a VM, a job) and act as it.
  • roles/iam.serviceAccountTokenCreator → lets someone mint tokens for that SA, in other words impersonate it.

If a user with few permissions can impersonate an SA with many, they effectively inherit those permissions. It is the most common privilege escalation path in GCP. Always review who holds those two roles.

And one recommendation that applies across the board: avoid service account keys (the downloadable JSON files). Prefer impersonation or Workload Identity; a leaked key is a long-lived credential handed out for free.

Allow, Deny and conditions

To complete the picture:

  • Allow policies: they grant. Across several of them, the most permissive wins (it is a union).
  • Deny policies: they deny, and they take precedence over any allow. They are for hard guardrails that no binding further down can bypass.
  • IAM Conditions: they add a when/where to the binding. For example, granting a role only on buckets whose name starts with prod-, or only until a certain date.
gcloud projects add-iam-policy-binding my-project \
  --member="group:[email protected]" \
  --role="roles/compute.instanceAdmin.v1" \
  --condition='expression=resource.name.startsWith("projects/my-project/zones/us-central1-a"),title=only-us-central1-a'

Best practices that actually matter

  • Least privilege. Start from zero and add what is needed, not the other way around.
  • Grant to groups, not to people. Access is managed in the group; people joining and leaving stops being a patch in IAM.
  • Predefined over basic. Owner/Editor for a person is almost always more than they need.
  • Place the binding at the lowest possible level. If the access is to a bucket, grant it on the bucket, not on the project.
  • Use the IAM Recommender. GCP analyzes real usage and suggests trimming oversized roles. It is risk reduction at no cost.
  • When something fails, use the Policy Troubleshooter. It tells you exactly why a principal does or doesn’t have a permission on a resource, following the whole inheritance chain.

The summary

If you keep a single picture, make it this one: a principal has a role on a resource, and that access is inherited downwards and adds up. Everything else (predefined vs. custom, deny, conditions, service account impersonation) is nuance on top of that same sentence.

Mastering IAM is not about memorizing permissions, it is about having the tree clear in your head and resisting the temptation to grant Editor “just to get it working”. That temptation is, almost always, the first step of an incident.