Back to Terraform

Google IAM Deep Dive: Authority, Conditions and Lockout Recovery

November 6, 2026 Wasil Zafar 29 min read

Compare full policy, role binding and individual member authority through a controlled provider-specific rehearsal

Table of Contents

  1. Scope Policy Authority Before Choosing a Resource
  2. Preserve Conditional Bindings and Inherited Access
  3. Distinguish Impersonation from Target Resource Permission
  4. Rehearse a Narrow Import and a Safe Denial
  5. Prove the Final Policy Did Not Drop Unowned Grants

Scope Policy Authority Before Choosing a Resource

An allow policy is a document, and every grant is a line in it. Google Cloud stores access as role bindings, each naming one role and one member list. Terraform can write that document at three sizes, and the size — not the style — decides what the next apply is allowed to delete.

Policy authority owns the whole document. google_project_iam_policy publishes exactly the bindings it was given and drops everything else. The provider ships an explicit warning with the resource: deleting it removes access from anyone without organization-level access. It is the only shape that can lock a project out of itself in a single apply.

The whole document is a loaded gun

An authoritative policy publishes exactly the bindings it was given and drops everything else. One apply can remove every grant another team owns, including the one that lets you repair it, so reserve that shape for a project no one else writes.

Binding authority owns one role. google_project_iam_binding replaces the complete member list for a single role and leaves other roles untouched. It is authoritative at role scope, so a principal another team added disappears without an error, a warning, or a delete line that names the principal.

Member authority owns one pairing. google_project_iam_member adds a single principal to a single role and leaves every neighbour in place. That is why it is the default anywhere more than one team writes to the same project.

Authority at a scope is not authority over inheritance. A project policy governs the project layer only. An Owner grant made at the folder or the organization is evaluated before the project document and survives every apply in your root, because no project-level resource can subtract it.

The last shape declares an absence. google_project_iam_member_remove asserts that a pairing must not exist. It revokes a grant that arrived from outside Terraform, and it is not a backup: destroying it restores nothing it removed.

Concurrency is the wrapper around all of it. Every write is a read-modify-write of one document, and the API accepts an etag with it. A racing writer surfaces as a conflict or as a disappeared binding on the next refresh, never as a merge.

Figure 1 turns the choice into a gate instead of a preference.

Scope Policy Authority Before Choosing a Resource
%%{init: {'theme':'base','themeCSS':'.edgeLabel .label text, .edgeLabel text, .edgeLabel span { fill:#132440 !important; color:#132440 !important; }','themeVariables': {'primaryColor':'#16476A','primaryTextColor':'#ffffff','primaryBorderColor':'#132440','secondaryColor':'#3B9797','secondaryTextColor':'#ffffff','secondaryBorderColor':'#132440','tertiaryColor':'#c4873b','tertiaryTextColor':'#132440','tertiaryBorderColor':'#132440','lineColor':'#5a6e82','textColor':'#132440','titleColor':'#132440','mainBkg':'#16476A','nodeBorder':'#132440','clusterBkg':'#eef3f7','clusterBorder':'#132440','edgeLabelBackground':'#ffffff','actorBkg':'#16476A','actorTextColor':'#ffffff','actorBorder':'#132440','activationBkgColor':'#3B9797','signalColor':'#5a6e82','noteBkgColor':'#c4873b','noteTextColor':'#132440','fontFamily':'DM Sans, sans-serif'}}}%%
flowchart TD
    D["Project allow policy
one document, many bindings"] --> Q1{"Does one root own
the whole document?"} Q1 -- "yes, imported first,
named approver" --> P["google_project_iam_policy
publishes every binding"] Q1 -- "no single owner" --> Q2{"Does one team own
every member of a role?"} Q2 -- "yes" --> B["google_project_iam_binding
replaces one role member list"] Q2 -- "no" --> M["google_project_iam_member
adds one pairing"] P --> F1["one apply can remove
every grant it omits"] B --> F2["a neighbour member vanishes
with no delete line"] M --> OK["additive and reversible
the shared-project default"] F1 --> G["break-glass owner
granted outside this root"] F2 --> G OK --> G classDef primary fill:#132440,color:#ffffff,stroke:#0b172b; classDef secondary fill:#16476A,color:#ffffff,stroke:#0f314a; classDef ok fill:#3B9797,color:#ffffff,stroke:#2a6f6f; classDef danger fill:#BF092F,color:#ffffff,stroke:#7a0420; classDef warn fill:#c4873b,color:#132440,stroke:#8a5a1f; class D,Q1,Q2 primary; class P,B secondary; class M,OK ok; class F1,F2 danger; class G warn;

The gate asks about authorship, not about hierarchy. A platform team that genuinely owns every member of a role can use the binding shape safely. The moment a second team adds a principal to that role, the binding has become a deleter of other people's work.

Figure 2 shows where that authority stops. The dashed outline is the layer a project root rewrites. Everything above it is inherited, and inheritance runs one way: downward, additively, and without a project-level opt-out.

Where a project root authority stops in the Google Cloud IAM hierarchy A ladder of organization, folder, project and resource shows that a project allow policy can rewrite only the project and resource layers. Bindings granted at the folder or organization survive any project apply. A deny policy attached above the project is evaluated before every allow policy, and only a deny below an inherited grant can subtract it. Where a project policy stops Write authority is a layer, not a level of seniority. Dashed outline: the layers this root can rewrite Organization org-level Owner Folder inherited downward Project the layer your root writes Resource bucket, topic, secret ALLOW: nearest binding wins resource a binding here is checked first project where an authoritative apply lands folder read only if nothing matched below organization the grant a project cannot remove No match walks up. A match stops the walk. An allow never removes another allow. DENY: runs before any allow organization one matching rule denies the call folder inherited by every project below project the only subtractive control here An allow cannot override a deny. Deny conditions read resource tags only. Only supported permissions can be denied. Several policies are evaluated independently. The project root can rewrite the project layer and nothing above it. Inherited grants survive that apply. A deny policy below them is the only way to take one back. Grant the break-glass owner above the project, or the project cannot recover itself.

The two right-hand columns are not symmetric. Allow is a walk upward that stops at the first match. Deny is a set of independent rules that any one of which can end the request. That asymmetry is why a deny policy is the only safe guardrail against an inherited grant.

Deny is also the weaker promise. Conditional deny rules read resource tags and nothing else, so a time-bounded guardrail has to be an allow condition instead. A deny the language cannot express is a comment.

ScopeTerraform resourceOwns on applyCan deleteCan subtract an inherited grant
Project allow policygoogle_project_iam_policythe entire documentany binding the document omitsno
One rolegoogle_project_iam_bindingthat role's full member listmembers the list omitsno
One pairinggoogle_project_iam_memberone principal in one rolethat pairing onlyno
One conditional pairingmember resource with a condition blockrole plus expressionthat conditional binding onlyno, unless the expression matches
Deny policygoogle_iam_deny_policythe rule set under one policya rule the set omitsyes, before any allow

Table 1 is a review artifact, not a menu. The last column is the one that matters: it says whether a scope can shrink what somebody else granted. Only the deny row can, and it pays for that with a second document and its own propagation delay.

Preserve Conditional Bindings and Inherited Access

A condition is a predicate, never a replacement for a policy. It narrows one binding to the requests where a CEL expression is true. Everything the role grants is still granted, only conditionally, so a condition placed on a broad role is a time bomb rather than a least-privilege fix.

The expression sees the request, not your intent. Typical clauses read the clock, the resource name, or an attribute the call carries. A timestamp comparison is the expiry pattern and a name prefix is the scoping pattern. Anything the request does not carry cannot appear in the expression, which rules out most of the reasons people want conditions.

An unconditional grant defeats the condition silently. Conditional bindings do not override an unconditional binding for the same principal and role. If the pairing also exists without a condition, the condition is decoration, and the reviewer who trusts it is the one who gets surprised.

Some bindings reject conditions at the API. Basic roles including Owner, Editor, and Viewer cannot carry one, and the API answers with a 400 instead of ignoring the block. A successful plan is not proof that a condition was accepted, because the plan never asks the IAM API.

Changing a condition is a replacement. Terraform treats the role plus the condition as the binding's identity, so editing the expression destroys the old binding and creates a new one. Between those two calls the principal holds nothing, and propagation stretches the window well past the length of the apply.

Propagation is measured in minutes, and groups in hours. Policy changes typically land in about two minutes and can take longer; group membership changes can take hours, and nested groups are slower again. A verification run that starts immediately after apply can prove the state you just replaced.

Inheritance is additive, which is the whole problem. A role granted on the organization applies to every descendant, and a project policy cannot take it back. The remedies are narrow: remove the high-level grant, or attach a deny policy below it. Adding a more specific allow changes nothing at all.

A group member string is a pointer, not a person. The binding stores a group address, and the group's membership is expanded when a request is evaluated. Remove someone from the group and effective access changed without one byte of Terraform state moving.

Nested groups multiply that gap. A group inside a group inside a binding is three separate edits away from a silent revocation, and none of them appears in a plan or a refresh. This is the most common "Terraform removed my access" report that Terraform did not cause.

Principal sets behave the same way with a wider blast radius. A member that names all service accounts in a project or folder is resolved at request time, so moving a project into a folder changes who is inside the set. The binding is identical, and every review that recorded the old membership is now stale.

Deny policies have their own, smaller condition language. Deny conditions recognise resource tag functions only, so a deny can be scoped to an environment tag but not to a caller or a clock. Check the supported permission list before promising a guardrail.

Figure 3 traces a request to a decision, including the branches that produce a denial nobody expected.

Preserve Conditional Bindings and Inherited Access
%%{init: {'theme':'base','themeCSS':'.edgeLabel .label text, .edgeLabel text, .edgeLabel span { fill:#132440 !important; color:#132440 !important; }','themeVariables': {'primaryColor':'#16476A','primaryTextColor':'#ffffff','primaryBorderColor':'#132440','secondaryColor':'#3B9797','secondaryTextColor':'#ffffff','secondaryBorderColor':'#132440','tertiaryColor':'#c4873b','tertiaryTextColor':'#132440','tertiaryBorderColor':'#132440','lineColor':'#5a6e82','textColor':'#132440','titleColor':'#132440','mainBkg':'#16476A','nodeBorder':'#132440','clusterBkg':'#eef3f7','clusterBorder':'#132440','edgeLabelBackground':'#ffffff','actorBkg':'#16476A','actorTextColor':'#ffffff','actorBorder':'#132440','activationBkgColor':'#3B9797','signalColor':'#5a6e82','noteBkgColor':'#c4873b','noteTextColor':'#132440','fontFamily':'DM Sans, sans-serif'}}}%%
flowchart TD
    R["Request
principal, permission, resource"] --> E["Expand members
user, group, principalSet"] E --> DN{"Deny policy
matches?"} DN -- "yes" --> X1["DENY
no allow overrides it"] DN -- "no" --> A1{"Allow policy
on this resource?"} A1 -- "yes" --> CD{"Binding carries
a condition?"} A1 -- "no" --> UP["Walk to folder,
then organization"] UP --> A2{"Allow at an
ancestor?"} A2 -- "no" --> X2["DENY
permission never granted"] A2 -- "yes" --> CD CD -- "no" --> OK["ALLOW
unconditional binding"] CD -- "yes" --> CE{"Expression true
for this request?"} CE -- "yes" --> OK CE -- "no" --> X3["NOT GRANTED by this binding"] X3 --> UN{"Same role granted
without a condition?"} UN -- "yes" --> OK2["ALLOW
the condition was decoration"] UN -- "no" --> X2 classDef primary fill:#132440,color:#ffffff,stroke:#0b172b; classDef secondary fill:#16476A,color:#ffffff,stroke:#0f314a; classDef ok fill:#3B9797,color:#ffffff,stroke:#2a6f6f; classDef danger fill:#BF092F,color:#ffffff,stroke:#7a0420; classDef warn fill:#c4873b,color:#132440,stroke:#8a5a1f; class R,DN,A1,A2,CD,CE,UN primary; class E,UP secondary; class X3 warn; class OK,OK2 ok; class X1,X2 danger;

The three red leaves return the same error to the caller. An expired condition, a deny rule, and a missing ancestor grant all arrive as a 403, and only the troubleshooter tells them apart. All three are also invisible in a plan, because the configuration is exactly what its author intended.

Prefer the earliest condition you can defend. A time-bounded grant with a reviewed expiry is honest about being temporary. A name prefix that the API does not evaluate the way you assumed is a permanent grant wearing a disguise.

Distinguish Impersonation from Target Resource Permission

Becoming an identity and using an identity are two authorizations. A caller first needs permission on the service account resource to obtain a credential, then permission on the target resource to do anything with it. Either gate can fail, and each one fails with a different error on a different API.

Acting as an account is a grant on the account. Attaching a service account to a Compute instance, a Cloud Run revision, or a GKE workload needs iam.serviceAccounts.actAs, normally through roles/iam.serviceAccountUser. Granting that role at project level covers every service account in the project, which is far broader than the sentence "let this job use its account" suggests.

Minting a token is a sharper grant. The Token Creator role allows OAuth tokens, ID tokens, and signed assertions, and it enables the impersonation flag. It does not attach the account to anything, so treat it as equivalent to handing over every permission the account holds.

Signing is a third permission with its own risk. Signed blob and signed JWT permissions let a caller produce assertions the account would produce without ever receiving an access token. That is enough to authenticate to some backends, and it is easy to grant while reviewing only the token path.

The account's own policy is a separate document. google_service_account_iam_member writes to the service account's allow policy, not to the project's. The same three authority shapes exist there with the same semantics, so a service account policy resource can lock out every impersonator in one apply.

The target grant lives on the target. What the account may do is decided by allow policies on the project, bucket, topic, or secret it calls. A role on the service account widens nothing, and a target grant does not let a human use the account. Both halves are required and neither implies the other.

A principal set can be the impersonator. Workload and workforce identity pools bind external identities as principalSet members, and that set is resolved at request time from the pool's attribute mappings. A mapping change is an access change that no Terraform plan will show, exactly like a group edit.

A deleted account breaks the first gate and leaves the second intact. Existing bindings keep the principal as a deleted: member string, and a replacement account with the same email has a different unique ID that inherits none of them. Tokens already minted keep working until they expire, which hides the breakage for up to an hour.

Recreating the account is not a restore. Terraform can create a new service account with the same name, and every resource attached to the old one stays attached to an identity that no longer exists. Undelete, while the window allows it, is the only path that brings back the original ID.

Figure 4 separates the two gates and keeps each failure with the layer that produces it.

Two authorization gates: obtaining a credential and reaching the target resource Step one asks the service account own allow policy for actAs, token creation or signing, and issues a credential on success. Step two asks the target resource allow and deny policies whether that identity may perform the permission. A valid token with no target grant returns a 403 that looks like an authentication error but is a policy decision. Two gates, not one A credential proves who is calling. It never proves what the caller may do. GATE 1: the service account policy the caller names the account, not the target no role on the account means no credential actAs attach or run tokenCreator mint a token signBlob sign an assertion Any one of the three satisfies gate 1. The token carries the account identity until expiry. a valid credential is issued GATE 2: the target resource policy the request carries the account token the target evaluates the identity, not the caller deny policy at org, folder or project runs first allow policy on the resource or its ancestors principalSet members resolved at request time allow: the call proceeds deny: 403 PERMISSION_DENIED A valid token with no target grant is still a 403. The caller reads it as an authentication failure and widens the wrong role. Read the error status before changing a role: 401 is the credential, 403 is the policy. Audit who can impersonate the account, not only what the account can reach.

The left gate can succeed while the right gate denies. That combination returns a 403 from the target after a perfectly valid credential was issued, and it is routinely misread as a broken key or a stale token. The credential was fine; the policy was never there.

The reverse combination is rarer and more dangerous. A target grant plus an open token path lets the account reach a resource the caller was never meant to touch directly. Auditing the account's target roles without auditing who can impersonate it audits exactly half the path.

Check the attached identity, not just the grant. An instance or revision keeps the account name it was created with, and deleting that account does not detach it. The resource still names an identity that cannot obtain a token, which looks like a policy problem at the target and is really a lifecycle problem at the source.

Rehearse a Narrow Import and a Safe Denial

Four paths produce a lockout, and only one of them is visible in a plan. The others are an out-of-band policy write, a group edit, a service disable, and a deleted identity. Rehearsing a lockout therefore means rehearsing the recovery, because the failure itself will not announce which path it took.

Path one is policy overwrite. An authoritative apply publishes a document that omits bindings written elsewhere, and the plan shows a shorter policy rather than a lost permission. The recovery is a principal granted above the project, because nothing inside the project can restore what the document no longer contains.

Path two is a removed group. The binding is unchanged, the plan is clean, and access is gone because the group no longer contains the caller. The recovery is a direct grant on a separate identity, decided in advance rather than improvised during the incident.

Path three is a disabled API. A workload root that owns a shared activation can disable a service on destroy, and dependent resources are deleted or suspended with it. The recovery is to re-enable the service and then wait, in order, for the long-running operation, the IAM propagation, and the service agents.

Path four is a deleted service account. Bindings survive as deleted: members and the workload fails at its first token request. The recovery is a new identity with its own grants, plus re-attaching it wherever the old one was attached, which for most resource types means replacing the resource.

The rehearsal needs an identity the rehearsal cannot delete. Create a second owner, give it its own credentials, and keep it out of every Terraform root. If it appears in state it is not break-glass, it is a resource that a destroy plan will remove with everything else.

Import before you write, every time. Adopting an existing pairing with an empty plan proves that your configuration matches reality. A non-empty plan after an import is a finding about your file, not a reason to apply without reading it.

Prove the denial before you prove the grant. A denial that names the missing permission is evidence that the identity resolved and the policy was evaluated. A grant that succeeds may only prove the principal inherited something broader, which is the exact failure this article is about.

Export the policy before the lab, not after. The export is the only record of unowned grants, and once an authoritative apply has run the information is gone from the API as well as from state. Take the copy first and store it where the lab root has no write access.

Figure 5 lays the four paths out with the symptom each one produces.

Four lockout paths with their symptom and the layer that recovers them Policy overwrite removes bindings an authoritative apply omitted and is recovered by an owner granted above the project. A removed group leaves a clean plan and is recovered by a direct principal grant. A disabled API deletes or suspends dependent resources and is recovered by re-enabling the service and waiting for propagation. A deleted service account leaves deleted member strings and is recovered by granting the roles to a new unique identity. Four ways in, one shape of recovery Control-plane change, runtime symptom, recovery from outside the failing layer. 1 - policy overwrite an authoritative apply publishes a shorter document symptom: every project role the document omits is gone recover: an owner granted above the project the plan showed a shorter policy, not a lost permission 2 - group removed one member string expands to a group that lost the caller symptom: nothing changes, the plan stays clean recover: a direct principal grant, not a group group edits live outside Terraform and outside the plan 3 - API disabled a workload root destroys a shared service activation symptom: dependent resources deleted or suspended recover: re-enable, then wait for agents and propagation the destroy looked like cleanup of the workload only 4 - service account deleted the identity is gone, its bindings remain as deleted members symptom: a same-name replacement inherits nothing recover: grant the roles to the new unique ID tokens already minted keep working until they expire None of these is a permission diff, and apply again is never the recovery. Apply is what wrote the state that no longer grants access. Rehearse each path once, in a disposable project, with the separate owner doing the restore. Record the wall-clock time from restore to a successful call, because that is the real outage length.

Then rehearse the break-glass path itself. Use the separate owner to restore one removed binding in a disposable project, confirm the restored access with the troubleshooter, and record how long propagation took. An untested break-glass identity is a hope with an email address.

Keep the recovery narrow enough to be reviewable. The separate owner needs permission to set IAM policy on the projects it protects, not organization-wide Owner. Write that boundary down, because the temptation during an incident is to widen it permanently.

Prove the Final Policy Did Not Drop Unowned Grants

Two properties, and either one alone is misleading. The policy must be stable, meaning two consecutive plans report no changes. It must also be complete, meaning the bindings nobody in your root wrote are still present and still effective.

Stability is a Terraform question; completeness is an IAM question. A root can be perfectly stable while publishing a document that quietly omits a partner's grant, because Terraform only compares against the bindings it already knows about.

Export the document before and after. A policy read is cheap, and a textual diff of bindings is the only artifact that shows a removal that never appeared as a delete line. Store both exports beside the plan output.

Ask the evaluator, not the console. Policy Troubleshooter takes a principal, a resource, and a permission and reports which allow, deny, and boundary policies decided. It reads the live policy, so it also catches a grant that Terraform never managed.

Test the permission, not the role name. A role can be granted and still not contain the permission you assumed, especially for custom roles and preview permissions. One call that checks a specific permission is worth more than a screenshot of a role list.

Treat a clean plan as a hypothesis. The plan says your configuration matches state. Only the evaluator says the state grants what you think it grants, and only the audit log says a real call used it.

Lab

Prove the Final Policy Did Not Drop Unowned Grants

Execution status: design-only. This sequence was not run against a live project. It is written to be executed and recorded, not quoted as a transcript.

Prerequisites. A disposable project, one bucket holding one small object, one service account, and a second owner identity created outside the lab root with its own credentials. Terraform 1.17.1 with hashicorp/google 8.10.0, and a policy export saved where the lab root cannot write.

  1. Record the baseline document. Read the project allow policy and save it. Count the bindings and the members inside each one. This file is the only record of what "unowned" means for the rest of the lab.
  2. Prove the root is stable. Plan twice with no edits and expect an empty plan both times. A root that is not stable cannot prove anything about the next change, because every diff will be ambiguous.
  3. Add a grant outside Terraform. Use the console or the CLI to add one principal to one role the root does not manage. Save the document again and note the new binding and its member count.
  4. Apply the root unchanged. Expect an empty plan and no policy movement, because a member resource for a different role cannot touch the new binding. If the plan removes it, an authoritative resource is already present, and that is the finding.
  5. Import, do not recreate. Adopt one existing pairing with an import block and confirm the plan is empty. An import that shows a diff is a configuration mismatch, not a provider bug.
  6. Remove the grant the narrow way. Delete the member resource for the imported pairing, apply, and confirm the policy lost exactly one member and no role. A role that vanishes means the wrong shape was used.
  7. Prove the effective denial. As the service account, attempt the action the removed pairing allowed. Expect a 403 that names the permission, and expect the troubleshooter to report no matching allow.
  8. Prove the break-glass recovery. As the separate owner, restore the binding from the baseline export, then repeat step 7 after propagation. Expect success, and record the wall-clock delay rather than estimating it.
  9. Destroy and re-read. Destroy the lab root and read the project policy again. Compare it to the baseline export line by line, and confirm that only lab-owned bindings disappeared.
CheckEvidencePass looks likeFailure signal
Stabletwo consecutive plansno changes in eithera diff that returns after every apply
Completebaseline export against final exportonly lab bindings removeda partner binding missing from both
Adoptedplan after the import blockno changes, no replacementa diff against the imported object
Deniedcall as the service account403 naming the permission401, so the credential is wrong
Recoveredcall after the break-glass restoresuccess and a named bindingsuccess before the restore
Narrowmember count before and after step 6exactly one member fewera role or a whole policy replaced

Expected observation. Steps 3 and 4 produce no plan diff, which is the completeness property: an out-of-band binding survives an apply that never claimed it. Step 6 removes exactly one pairing. Step 7 returns a 403 that names the permission rather than the resource, and step 8 returns the same call successfully once propagation finishes.

Failure checks. If step 4 removes the out-of-band binding, an authoritative resource is in the root. If step 7 succeeds before the break-glass restore, the identity inherits a broader role and the denial proves nothing. If step 8 succeeds immediately, the removed grant never propagated away and the earlier 403 was a stale token.

Cost dimensions. The lab is close to free: one bucket, one small object, a handful of IAM writes, and a few storage requests. The only real cost is a versioned bucket left behind.

Cleanup. Delete the object and the bucket, remove the member resources, and destroy the root. Then confirm the separate owner still holds its grant, because that grant is the one thing the lab must not clean up.

The proof is a pair of documents and a pair of decisions. The exports show what the policy contained and the troubleshooter decisions show what it meant. A configuration that produces both has authority; one that produces only a green plan has a story about authority.