Skip to content

Lesson 1 of 14 · 15m

GCP IAM: The Policy Lives on the Resource

GCP binds principals to roles on the resource itself, and access is the union of every binding up the hierarchy.

Read the policy first

Run gcloud projects get-iam-policy my-project and look at what comes back. It is not a description of who belongs to the project. It is a YAML document attached to the project resource:

bindings:
- members:
  - user:contractor@example.com
  - serviceAccount:ci@my-project.iam.gserviceaccount.com
  role: roles/editor
- members:
  - group:sre@sudosecurity.org
  role: roles/viewer

That is the whole model. A binding maps a set of members to a role. The role is a named bag of permissions — roles/editor contains several thousand service.resource.verb permissions spanning most GCP services; roles/storage.objectViewer contains exactly storage.objects.get, storage.objects.list, and a couple of supporting reads. Members come in a small set of principal types: user:, serviceAccount:, group:, domain:, plus two literals that deserve their own lesson — allUsers and allAuthenticatedUsers.

The mental model people bring from AWS and LDAP is "give the user a role," as if the role were a property of the identity. It isn't. The binding is a property of the resource. The same contractor can be roles/owner on dev-project, roles/viewer on prod-project, and nothing at all on the folder containing them both. You never ask "what roles does this user have"; you ask "what bindings does this resource have, and what bindings exist above it." When an API call lands, GCP evaluates every policy along the path — org, folders, project, resource — and the call is allowed if any binding anywhere in that chain grants the permission.

The hierarchy is the grant

GCP resources sit in a tree: organization → folders → projects → resources. Buckets, VMs, secrets, and service accounts are all resources — yes, service accounts carry their own IAM policies, which matters later. Policies attach at every level, and access is the union of every binding on the path from the org root down to the resource. There is no closest-match wins, no child override. A roles/viewer binding on a folder applies to every project inside it and every bucket inside those projects — including projects created next year by a team that has never heard of the person in the binding.

This is why folder-level grants are how fleets get quietly owned: one binding on a folder of forty projects silently follows everything underneath it. Grant breadth is invisible at the resource level — gcloud projects get-iam-policy on a child won't show the folder binding. gcloud asset search-all-iam-policies or Policy Analyzer exists precisely because effective access can't be read off a single policy.

What you cannot do with allow policies

Allow policies only add. You cannot bind roles/editor at the project and subtract compute.instances.delete for one member. The tool for subtraction is IAM Deny, a separate policy type applied at organization, folder, or project level: deny rules name permissions and principals (principalSet members) and block them regardless of allow bindings — a deny beats roles/owner. The tool for "this role, but only under this constraint" is IAM Conditions, a CEL expression attached to the binding: request.time bounds deployment windows, resource.name.startsWith("projects/_/secrets/dev-") scopes a grant to a name prefix, resource.type limits the surface. Conditions can't be attached to the basic roles — Owner, Editor, Viewer are unconditional by design, which is one more reason to stop using them.

One practical note on groups: binding group: principals means group membership changes access without touching IAM. Whoever administers the Workspace group is quietly a GCP admin too.

Land it

Grant at the narrowest scope that works — the secret, the bucket, the project — never the folder "to keep it simple." Use predefined roles; the basic three are legacy blunderbusses. Set constraints/iam.allowedPolicyMemberDomains (domain-restricted sharing) at the org node so bindings can only name your domains. And learn Policy Analyzer — "who can access this resource and why" is gcloud policy-intelligence query-policy or the IAM → Policy Analyzer console page — because the answer lives on the resource, not on the principal.

Was this lesson helpful?

Sign in to rate

Keep reading

Related articles from the SudoSecurity blog.