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.
%%{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.
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.
| Scope | Terraform resource | Owns on apply | Can delete | Can subtract an inherited grant |
|---|---|---|---|---|
| Project allow policy | google_project_iam_policy | the entire document | any binding the document omits | no |
| One role | google_project_iam_binding | that role's full member list | members the list omits | no |
| One pairing | google_project_iam_member | one principal in one role | that pairing only | no |
| One conditional pairing | member resource with a condition block | role plus expression | that conditional binding only | no, unless the expression matches |
| Deny policy | google_iam_deny_policy | the rule set under one policy | a rule the set omits | yes, 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.
%%{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.
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.
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.
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.
- 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.
- 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.
- 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.
- 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.
- 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.
- 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.
- 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.
- 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.
- 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.
| Check | Evidence | Pass looks like | Failure signal |
|---|---|---|---|
| Stable | two consecutive plans | no changes in either | a diff that returns after every apply |
| Complete | baseline export against final export | only lab bindings removed | a partner binding missing from both |
| Adopted | plan after the import block | no changes, no replacement | a diff against the imported object |
| Denied | call as the service account | 403 naming the permission | 401, so the credential is wrong |
| Recovered | call after the break-glass restore | success and a named binding | success before the restore |
| Narrow | member count before and after step 6 | exactly one member fewer | a 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.