Google Cloud IAM: Roles, Bindings and Deny
Google Cloud IAM attaches permissions to resources, not to identities. Every resource that supports IAM (organization, folder, project, bucket, service account, secret…) has an allow policy: a list of bindings, each saying "these members have this role", optionally with a condition. What a principal can do is the union of every binding that names it, on the resource and all its ancestors, minus anything an IAM deny policy blocks.
On AWS this is… resource-based policies (bucket policies) and identity-based policies combined, plus the evaluation rules of IAM Policies. The
Principalelement of a bucket policy is the closest shape to a GCP binding.
Roles and permissions
A permission looks like service.resource.verb: storage.objects.get, compute.instances.start, run.services.update. You never grant permissions directly; you grant roles, which are sets of permissions:
| Kind | Examples | Use |
|---|---|---|
| Basic roles | roles/owner, roles/editor, roles/viewer |
avoid in production: very broad, cover almost every service |
| Predefined roles | roles/storage.objectViewer, roles/run.developer, roles/cloudsql.client |
the normal choice |
| Custom roles | projects/shop/roles/vmOperator |
when no predefined role fits; you maintain them |
roles/editor is the classic trap: it reads like "can edit things" but grants create/delete on nearly every service in the project.
An allow policy
This is the policy on a project, as gcloud projects get-iam-policy shows it (sample):
bindings:
- members:
- group:shop-devs@example.com
role: roles/run.developer
- members:
- serviceAccount:shop-api@shop-api-prod-4821.iam.gserviceaccount.com
role: roles/cloudsql.client
- condition:
expression: request.time < timestamp("2026-12-01T00:00:00Z")
title: temporary-contractor-access
members:
- user:contractor@example.net
role: roles/viewer
etag: BwYq3kL9xQo=
version: 3Note the etag: a whole-policy update (set-iam-policy) must send back the etag it read, so two people editing at once can't silently overwrite each other. The add-iam-policy-binding and remove-iam-policy-binding commands do the read-modify-write for you:
gcloud projects add-iam-policy-binding shop-api-prod-4821 \
--member="group:shop-devs@example.com" --role="roles/run.developer"
# grant on a single bucket instead of the whole project
gcloud storage buckets add-iam-policy-binding gs://shop-prod-invoices \
--member="serviceAccount:billing@shop-api-prod-4821.iam.gserviceaccount.com" \
--role="roles/storage.objectViewer"
# which roles contain a permission? what's in a role?
gcloud iam roles describe roles/run.developer --format="value(includedPermissions)"Warning:
gcloud projects set-iam-policyreplaces the whole policy with the file you give it. A file that's missing a binding removes that access. Prefer the add/remove commands, or manage the policy fully in Terraform withgoogle_project_iam_member(additive) rather thangoogle_project_iam_policy(authoritative for the whole project).
Deny policies
Since allow policies only add, Google Cloud added IAM deny policies: attached to an organization, folder or project, they name denied permissions, the principals they apply to and optional exceptions. Deny is checked first and wins over any allow. Use them for the AWS-style "nobody except the security team may delete keys" rule.
{
"displayName": "Only secops can delete service account keys",
"rules": [{
"denyRule": {
"deniedPrincipals": ["principalSet://goog/public:all"],
"exceptionPrincipals": ["principalSet://goog/group/secops@example.com"],
"deniedPermissions": ["iam.googleapis.com/serviceAccountKeys.delete"]
}
}]
}Deny policies write permissions in the service.googleapis.com/resource.verb form, unlike allow policies. A third layer, principal access boundary policies, limits which resources a principal can ever access, similar in spirit to an AWS permissions boundary.
Model: evaluating a request
from datetime import datetime, timezone
ROLES = {
"roles/viewer": {"storage.objects.get", "storage.objects.list", "compute.instances.get"},
"roles/storage.objectAdmin": {"storage.objects.get", "storage.objects.list",
"storage.objects.create", "storage.objects.delete"},
"roles/compute.admin": {"compute.instances.get", "compute.instances.delete", "compute.instances.start"},
}
parent = {"projects/shop": "folders/prod", "folders/prod": "organizations/example"}
allow = {
"organizations/example": [("group:secops", "roles/viewer", None)],
"folders/prod": [("group:sre", "roles/compute.admin", None)],
"projects/shop": [("user:temp", "roles/storage.objectAdmin",
lambda now: now < datetime(2026, 12, 1, tzinfo=timezone.utc))],
}
deny = { # on the org: nobody but secops may delete instances in prod
"organizations/example": [({"compute.instances.delete"}, {"*"}, {"group:secops"})],
}
def chain(node):
out = [node]
while out[-1] in parent:
out.append(parent[out[-1]])
return out
def check(who, groups, perm, resource, now):
ids = {who, *groups}
for node in chain(resource):
for perms, principals, exceptions in deny.get(node, []):
if perm in perms and ("*" in principals or ids & principals) and not ids & exceptions:
return f"DENY (deny policy on {node})"
for node in chain(resource):
for member, role, cond in allow.get(node, []):
if member in ids and perm in ROLES[role] and (cond is None or cond(now)):
return f"ALLOW ({role} on {node})"
return "DENY (no binding)"
nov = datetime(2026, 11, 15, tzinfo=timezone.utc)
dec = datetime(2026, 12, 15, tzinfo=timezone.utc)
cases = [
("user:bo", ["group:sre"], "compute.instances.start", "projects/shop", nov),
("user:bo", ["group:sre"], "compute.instances.delete", "projects/shop", nov),
("user:cy", ["group:secops"], "storage.objects.get", "projects/shop", nov),
("user:temp", [], "storage.objects.delete", "projects/shop", nov),
("user:temp", [], "storage.objects.delete", "projects/shop", dec),
]
for who, groups, perm, res, now in cases:
print(f"{who:<10} {perm:<26} {now:%Y-%m-%d} {check(who, groups, perm, res, now)}")user:bo compute.instances.start 2026-11-15 ALLOW (roles/compute.admin on folders/prod)
user:bo compute.instances.delete 2026-11-15 DENY (deny policy on organizations/example)
user:cy storage.objects.get 2026-11-15 ALLOW (roles/viewer on organizations/example)
user:temp storage.objects.delete 2026-11-15 ALLOW (roles/storage.objectAdmin on projects/shop)
user:temp storage.objects.delete 2026-12-15 DENY (no binding)
The SRE group's compute.admin from the folder lets Bo start an instance, but the organization's deny policy stops the delete. The contractor's binding simply stops matching after its condition expires; nobody has to remember to remove it.
Comparing the three permission systems
| Question | AWS IAM | Azure RBAC | Google Cloud IAM |
|---|---|---|---|
| Where are grants stored? | on identities (and resources) | role assignments at scopes | allow policies on resources |
| Inherited down a hierarchy? | no | yes | yes |
| Explicit deny | Deny statements, SCPs |
deny assignments (system-created) | IAM deny policies |
| Conditions | Condition block |
ABAC conditions on assignments | CEL conditions on bindings |
| "What can X do?" | IAM policy simulator, Access Analyzer | az role assignment list --assignee X --all --include-inherited |
Policy Analyzer, gcloud asset analyze-iam-policy |
Test yourself
Why should you avoid roles/editor in production projects?
- It is read-only
- It grants broad create/modify/delete on almost every service in the project
- It is deprecated
- It only works in the console
Why is gcloud projects set-iam-policy risky?
- It needs an etag
- It replaces the entire policy, so missing bindings are removed
- It only adds bindings
- It works only on folders
Which Google Cloud feature can block a permission even when an allow policy grants it?
- IAM conditions
- IAM deny policies
- Labels
- Custom roles