Repository navigation
Description
Summary
Substrate already has a real IAM policy evaluator (emulator/iam_eval.go: Deny → Allow → ImplicitDeny) and an enforcing AuthController.CheckAccess that returns AccessDeniedException (403). But CheckAccess short-circuits when reqCtx.Principal == nil, and the common test-harness path (SDK client pointed at the server with no principal wired) never sets one — so in practice every authorization check is skipped in composition tests.
Net effect: a caller that is missing a required permission passes cleanly against Substrate and only fails on real AWS. This is the "request/response error-code fidelity" part of the charter (scope.md: make every API observation accurate including error codes) — not workload execution — so it's in scope.
Why this matters (concrete, from a real consumer)
In spore-host/spawn's pooled-execution work (spawn#70), a worker instance was launched with an IAM instance profile that granted no SQS permissions. On real AWS its GetQueueUrl returned NonExistentQueue (SQS masks access-denied as not-found) and the worker died — the pool never drained. The Substrate-backed composition tests were fully green because no principal was set, so the missing permission was invisible. It took a paid real-AWS smoke to find it. A whole class of "forgot a permission / policy too narrow" bugs is exactly what an enforced-IAM test mode would catch in CI.
Proposed capability
A way for a test to execute API calls as a specific IAM principal/role, so AuthController evaluates the principal's actual policies against the (already-built) action + resource ARN:
- A test helper / request option to set
RequestContext.Principalto a role or user the test created via the IAM plugin (e.g. an instance profile with a scoped inline policy), so subsequent calls on that client are authorized against it. - Opt-in: the nil-Principal "always pass" default stays for the many tests that don't care about authz, so this is non-breaking. A test that wants enforcement sets the principal explicitly.
- Bonus: honor an EC2 instance's attached
IamInstanceProfileas the principal for calls that a test attributes to that instance, so "does this instance's role actually allow what its bootstrap does?" becomes testable end-to-end.
Acceptance
- A test can create a role with a scoped policy, make an SQS/S3/etc. call as that role, and get
AccessDeniedExceptionwhen the policy doesn't allow it — and success when it does. - Existing tests (nil principal) are unaffected.
Scope note
This is higher-fidelity emulation of an existing observable (the authz decision + error code), consistent with scope.md — it does not execute any workload. Substrate already has the evaluator; this exposes it to tests.
Reported from spore-host/spawn#70 pooled-execution validation.
Activity
scttfrdmn commentedon Aug 1, 2026
Triaged to v0.82.0, separately from its three siblings (#406, #412, #413 → v0.81.0).
Those three are self-contained fidelity fixes in one plugin each. This one is architectural: it needs
RequestContext.Principalpopulated along the SDK-client path, a supported way for a test to say "run as this role", and a decision about attributing calls to an EC2 instance's attached profile. Bundling it would hold up three small fixes behind a much larger change.Confirming the premise holds on
main:CheckAccessdoes short-circuit on a nil principal, and the test-server path never sets one — so the evaluator exists and is simply unreachable from composition tests. Your framing matches the scope boundary in CLAUDE.md: the authorization decision and its error code are observable through an API call, so raising fidelity there is in scope, and no workload gets executed.Two things worth settling before implementation, both from the acceptance criteria:
NonExistentQueuerather thanAccessDeniedfor an unauthorizedGetQueueUrl— which is what made the original bug hard to spot. If substrate returnsAccessDeniedExceptionthere, a consumer's error branch still won't match what AWS sends. The per-service masking probably belongs in this issue rather than a follow-up, or the fix reproduces the original problem under a different code.No work started; this is triage only.
scttfrdmn commentedon Aug 2, 2026
Moved from the v0.85.0 milestone to v0.86.0. v0.85.0 is cut and closed.
Still deferred as feature-scale: plumbing a caller principal through
RequestContextand enforcing IAM authorization against it touches every plugin'srequest path, which is not a change to make alongside unrelated defect fixes.
One correction to note, since it narrows this issue's remaining scope. The
issue's framing implies substrate refuses nothing on authorization grounds.
As of v0.85.0 that is no longer strictly true: #458 landed enforcement of S3
Block Public Access, so
PutBucketAcl,PutObjectAclandPutBucketPolicynowreturn
403 AccessDeniedfor a public ACL or a public bucket policy on a blockedbucket.
That is not principal-aware authorization, and it does not overlap with what
this issue asks for — BPA is evaluated from the request content and the bucket's
own configuration, with no notion of who is calling. It is worth flagging because
it means substrate now has one 403-producing path, and whatever this issue builds
should sit beside it rather than duplicate or subsume it. The relevant
distinction, from that work: substrate has no unauthenticated or cross-account
request path at all, which is exactly why
IgnorePublicAclsandRestrictPublicBucketsstayed recorded-only — they govern who a request comesfrom, which is precisely the gap this issue exists to close.
No work has started here.
8 remaining items
scttfrdmn commentedon Aug 4, 2026
Moved to v0.91.0. This is the fifth deferral, and saying so plainly is more
useful than another quiet milestone bump: v0.90.0 is a bug-fix release closing six
silent-wrong-observable defects, and this is a feature with real design decisions in
it. It keeps losing to defects that came from live consumers, which is the right
priority ordering but a bad pattern to leave unremarked.
Nothing in v0.89.0 or v0.90.0 changes this issue's analysis, but v0.89.0 sharpened
its central open question.
StackDeployer.dispatchstill builds aRequestContextwith no
Principal, and #520 added a rollback path that dispatches resourcedeletes through that same identity-less context. So enforcement now has to answer
one more question than when this was filed: what principal does a rollback's deletes
run as?
The plausible answers all have consequences worth choosing deliberately rather than
discovering:
operates with the caller's permissions unless a service role is set), but means a
rollback can fail on authorization, which needs a status (
ROLLBACK_FAILEDalreadyexists for it) and makes a partial rollback reachable.
enforcing IAM on creates and exempting the deletes that undo them, which is exactly
the kind of asymmetry that lets a missing permission stay invisible — the thing this
issue exists to stop.
RoleARN— the faithful answer, and the one that requires modellingservice roles first.
Recording it here so the design pass in v0.91.0 starts from it rather than rediscovering
it mid-implementation.
scttfrdmn commentedon Aug 4, 2026
Moved to v0.92.0 — the sixth deferral. Saying so plainly again, but this
comment is only worth more than the previous five if it stops restating the blocker
and answers it. So: the answer first, then the two findings that change this issue's
shape.
The blocking question, answered
The question holding this up has been what principal a CloudFormation rollback's
deletes run as. A rollback's deletes run as the principal that created the
stack. Reasons, in order of weight:
the calling principal's permissions, and nothing about a rollback re-derives an
identity.
ROLLBACK_FAILEDalready exists in substrate, so the awkward case (the principalcould create a resource but cannot delete it) has a faithful terminal state to
land in rather than needing one invented.
reintroduces exactly the blind spot this issue exists to remove. Enforcing on
creates while exempting the deletes that undo them is the asymmetry, not a way
around it.
Modelling a stack
RoleARN(an explicit service role the deploy assumes, which therollback then also uses) is the faithful long-term answer and is strictly larger than
this issue. Filed as #562 rather than folded in here, and it depends on this one.
Two findings that change the shape of the work
Measured on
main(31cff92) while scoping v0.91.0. This issue has been describedmore than once as "wire a principal into a test". It is not — it is three coupled
decisions.
1. The CLI server can never enforce, whatever a test does.
RequestContext.Principalis set in exactly one place,emulator/server.go:536-546,and only when
opts.Credentials != nil:cmd/substrate/main.go:173wiresAuth: authCtrlbut neverCredentials, andno config section exists for it. So
substrate servercannot enforce authorizationat all, independent of anything a test harness does. Delivering this issue therefore
means adding that config section — a new public surface, which is a large part of why
it is not a one-liner.
2. A principal with no policies is denied, not allowed.
loadPoliciesForPrincipalreturns an empty slice for a principal with no attached orinline policies, and
Evaluate(emulator/iam_eval.go:54) returns implicit denyfor an empty policy set. So enabling enforcement server-wide without first giving
every existing test's principal a policy would deny everything at once. The opt-in
has to be per-principal, not per-server — a decision about the public API, not a
wiring detail. This issue's "existing tests (nil principal) are unaffected" criterion
survives, but only under a per-principal opt-in.
3. The IaC path bypasses enforcement entirely — unchanged from the previous
comment, restated because it interacts with the answer above.
StackDeployer.dispatch(emulator/cfn_deployer.go:3925) builds aRequestContextwith no
Principal, andRouteRequestnever callsCheckAccess; enforcement livesonly in the HTTP path. So resources created through CloudFormation bypass
authorization, and #520's rollback dispatches its deletes through that same path.
cfnIdentity(:807) already carries account and region, and its doc commentalready says propagating
Principalis "a separate decision". That is the decisionanswered at the top of this comment.
Why it defers rather than ships now
v0.91.0 is a three-plugin wire-format rewrite (#529, plus the routing fixes #561 and
the API Gateway v2 prerequisite tracked on #529). Landing a new public config surface
and a change to when authorization is enforced beside it would put two large
behaviour changes in one release, and the second can break a consumer's tests in a
way that is hard to attribute when it arrives alongside the first.
v0.92.0 now starts from a decision rather than a question.
scttfrdmn commentedon Aug 5, 2026
Four measurements taken while planning v0.92.0, each of which changes this issue's shape. All were probed against
main(a533ced), not inferred from reading.1. An
assumed-roleprincipal already fails OPEN. This issue says "the nil-Principal 'always pass' default stays for the many tests that don't care about authz, so this is non-breaking". That understates it:loadPoliciesForPrincipal(emulator/authz.go:101) returns an error for any entity type outsideuser/role, andCheckAccess(:38-42) fails open on that error. Probe result: a request asarn:aws:sts::123456789012:assumed-role/worker/sess1is allowed with no policies attached at all, while the same call asuser/…orrole/…is correctly denied. That is the exact shape STS itself mints (emulator/sts_plugin.go:189), so the principals a consumer would most want to test are the ones enforcement silently skips.IAMPlugin.authorize(emulator/iam_plugin.go:1348) has the same switch and denies in that case. Two policy loaders, two opposite answers for one ARN.2. The server's principal ARN names the access key, not the IAM user.
buildCallerARN(emulator/credentials.go:88) producesarn:aws:iam::<acct>:user/AKIATEST12345678901. Probe: an IAM useralicewith an inlinesqs:*Allow is ALLOWED asuser/aliceand DENIED asuser/AKIATEST…. So even withServerOptions.Credentialswired, enforcement can never resolve a real principal's policies — the "wire a principal into a test" framing cannot work as written.3. The IaC path is not authorized at all.
CheckAccesshas exactly one non-test call site (emulator/server.go:564).PluginRegistry.RouteRequestnever calls it, andStackDeployer.dispatch(emulator/cfn_deployer.go:3920-3931) builds aRequestContextwith noPrincipal. Every resource a CloudFormation stack creates, updates, rolls back or deletes bypasses authorization entirely.4. Wiring
Credentialsinto the CLI server would be breaking.cmd/substrate/main.go:173wiresAuthbut neverCredentials, so the long-running server cannot enforce whatever a test does. But the obvious fix — wire the registry — also switches onVerifySigV4(emulator/server.go:548), and a key absent from the registry isInvalidClientTokenId(403).AKIAIOSFODNN7EXAMPLE, the credential every e2e check and the README use, is not registered. It would 403 the documented quickstart.Consequences for the design
Principal resolution is therefore being decoupled from the credential registry: the server resolves the caller from state (
iam:accesskey:<id>→IAMAccessKey.UserName, andsts:session:<id>→ the assumed-role ARN — a keyAssumeRolewrites today and nothing has ever read), independent of whetherCredentialsis wired. That costs onestate.Getper request carrying an Authorization header and breaks nothing.Opt-in decision: existence in state is the opt-in — no config flag. Enforcement runs when the caller resolves to an IAM user or role that exists; an unknown key, the built-in test key and
AKIAIOSFODNN7EXAMPLEcontinue to pass unenforced. This matches this issue's own acceptance wording ("a test can create a role with a scoped policy, make a call as that role…"), keeps every existing test green (only 3 test files set aPrincipaland only 1 wiresCredentials), and avoids a global switch that would deny a policy-less-but-existing principal in tests that never asked for authz. A state read that genuinely fails (I/O) still fails open, because that is a broken backend rather than an unknown caller.Taken in v0.92.0 alongside #562.
fix(iam): resolve a signed request to the principal it actually is (#411
fix(iam): evaluate the principals that exist, and stop guessing at th…
fix(authz): name a REST request by its operation, not its HTTP method (…
feat(cloudformation): authorize a stack's resource calls and model it…
docs: document testing IAM permissions and a stack's service role (#411…
feat(iam): groups have an observable effect (#579) (#641)
feat(iam): service-linked roles, and a producer for iam:AWSServiceName (