Repository navigation
feat(cloudformation): authorize a stack's resource calls and model its service role (#411, #562) - #574
Merged
Conversation
…s service role (#411, #562) A stack's resource calls were dispatched with no principal at all, and PluginRegistry.RouteRequest — the path every in-process deploy routes through — never authorizes. So a template asking for a permission the deploying identity did not have deployed cleanly, which is the failure class #411 exists to catch: in spore-host/spawn#70 a worker launched with an instance profile granting no SQS permissions passed every composition test and then never drained a queue on real AWS. Authorize in the deployer, which every create, update, rollback and delete sweep reaches a resource through, so there is no second path to keep in step. A denial is returned as the dispatch error — what a refused call from the resource's own service would have produced — and the existing machinery reports it with no new model: the resource records the error, DescribeStackResources renders it as CREATE_FAILED with the denial as ResourceStatusReason, and the stack rolls back. It is not yet a StackEvent; DescribeStackEvents is still refused with UnsupportedOperation, and deriving events from the event store is #501's question. Model the service role (#562). RoleARN is accepted on CreateStack, UpdateStack and DeleteStack, stored on the stack, and reported by DescribeStacks — the four places the API model carries it. The documented lifetime rules rather than the convenient ones: a service role governs "all future operations on the stack", so an update omitting RoleARN keeps the stored one, while a DeleteStack's applies to that operation only and is not persisted. Otherwise a delete refused by its override would silently re-attribute the stack, and a retried delete would run as a different identity than the first attempt. Absent a service role CloudFormation uses "a temporary session that's generated from your user credentials", so the creating principal is recorded on the stack and its resource calls are attributed to it — without that, CreateStack would be a way to launder a permission the caller does not have. Resolution is service role → creating principal → nil, in one place (cfnAttribution.resolve), so create, update, rollback and delete cannot disagree: a resource created by a role is deleted by that role, and a rollback's sweep runs as the identity that created what it is tearing down. Both new state fields are omitempty, so recorded runs replay. A stack with no role and no resolvable creating principal deploys exactly as before, which is every existing test and every in-process Client caller. dispatch resolves the operation name before authorizing, not after: the action a policy is evaluated against is derived from req.Operation, so authorizing first would ask whether the stack's role may perform "s3:PUT" (#572). Closes #411
Codecov Report❌ Patch coverage is 📢 Thoughts on this report? Let us know! |
This was referenced Aug 5, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
A stack's resource calls were dispatched with no principal at all, and
PluginRegistry.RouteRequest— the path every in-process deploy routes through —never authorizes. So a template asking for a permission the deploying identity did
not have deployed cleanly.
This is the failure class #411 exists to catch, and it has a concrete consumer
story: in spore-host/spawn#70 a worker instance was launched with an instance
profile granting no SQS permissions. Every substrate-backed composition test was
green; on real AWS its
GetQueueUrlreturnedNonExistentQueueand the pool neverdrained. A paid real-AWS smoke found it.
This is the half of #411 that no amount of principal resolution reaches (#570,
#571 did that half), plus #562.
Authorization happens in the deployer
Not in
RouteRequest, which authorizes nothing for anyone. Every create, update,rollback and delete sweep reaches a resource through
StackDeployer.dispatch, soauthorizing there covers all four at once and there is no second path to keep in
step.
A denial is returned as the dispatch error — exactly what a refused call from the
resource's own service would have produced — so the existing machinery reports it
with no new model: the resource records the error,
DescribeStackResourcesrenders it as
CREATE_FAILEDwith the denial asResourceStatusReason, and thestack rolls back through
cfn_rollback.gountouched. The refusal is recorded inthe event log beside the calls that succeeded, so a replay shows where the
deployment stopped and why.
It is not yet a
StackEvent.DescribeStackEventsis still refused withUnsupportedOperation, and deriving events from the event store — with itsordering, pagination and clock decisions — is #501's own design question. This is
why #562 is not closed by this PR: four of its five criteria ship here, and
the
StackEventcriterion stays open against #501.The service role (#562)
RoleARNis accepted onCreateStack,UpdateStackandDeleteStack, stored onthe stack, and reported by
DescribeStacks— the four places the API model carriesit,
omitemptyso a stack without one reports nothing, and length-validated as themodel specifies.
The documented lifetime rules, which are not the convenient ones:
CreateStackUpdateStackomittingRoleARNUpdateStacksupplying oneDeleteStacksupplying oneDeleteStackThe delete asymmetry is worth the care: a delete refused by its override must leave
the stack's own role intact, or a retried delete silently runs as a different
identity than the first attempt. Verified live below.
Which principal, and why
Absent a service role, CloudFormation uses "a temporary session that's generated
from your user credentials", so the creating principal is recorded on the stack
and its resource calls are attributed to it. Without that,
CreateStackwould be away to launder a permission the caller does not have.
Resolution is service role → creating principal → nil, in one place
(
cfnAttribution.resolve), so create, update, rollback and delete cannot disagree.Two consequences that follow from putting it in one place rather than restating it:
a resource created by a role is deleted by that role, not by whoever asks for
the delete (otherwise the permissions that gated creation would not gate teardown,
making enforcement decorative); and a rollback's sweep runs as the identity
that created what it is tearing down. An exempt service principal would have
reintroduced exactly the blind spot #411 exists to remove.
A
RoleARNis used directly as a role principal — the evaluator's role pathresolves it — rather than run through
AssumeRole, keeping this inside the scopeboundary: the observation being modelled is that a call was denied, not
role-assumption machinery.
Compatibility
A stack deployed under a service role, or by a caller whose access key resolves to
an IAM user or role that exists in state, is now authorized and can reach
ROLLBACK_COMPLETEwhere it previously reachedCREATE_COMPLETE. That is thepoint of the release.
A stack with no service role and no resolvable creating principal deploys exactly
as before — every existing test, every in-process
Clientcaller,AKIAIOSFODNN7EXAMPLE. State encoding gainsCFNStackState.RoleARNandCreatorPrincipalARN, bothomitempty, so recorded runs replay.Verification
Mutation testing — 8 mutants, each reversing one load-bearing decision:
8 CAUGHT, 0 survivors, 0 broken. Two rounds. The first found a real gap that
the plan had predicted:
attribution-order-inverted(creator wins overRoleARN)SURVIVED, because every existing test had either a role or a creator, never
both disagreeing — so nothing measured the order, only that something was
consulted. Added
TestCFN_ServiceRoleWinsOverTheCreatingPrincipal: a caller whoseown policy allows the bucket deploying under a role that refuses it (must roll
back), and the converse (must succeed). Both directions are needed; either alone is
satisfiable by the wrong order.
The other seven:
dispatch'sCheckAccessremoved while the principal is stillcarried;
DeleteStack'sRoleARNpersisted;UpdateStack's omittedRoleARNcleared; the delete sweep not attributed to the stack; the rollback's attribution
not persisted; the creating principal not carried; and
resolveOperationNamemovedafter authorization (the new coupling with #572 — without it the action evaluated
for a stack's bucket is
s3:PUTagain).gofmt -l .,go build ./...,go vet ./...,golangci-lint run ./...→ 0issues,
make test(race),make docs-reference docs-reference-check docs-versions(65 plugins, no change),go vet -C test/e2e ./...,go test -C test/e2e ./...— all green.Live end to end,
substrate server --address :4655That last pair also exercises #572's action renames — a
list-objectsauthorizingagainst
s3:ListBucket.Provenance
That
RouteRequestnever authorizes, and that a stack'sdispatchcarried noprincipal, were measured with throwaway in-package probes rather than read off
a reference. The
RoleARNshapes and lifetime semantics are from theCloudFormation botocore model (
CreateStack/UpdateStack/DeleteStackinputs andthe
Stackoutput shape) and the CloudFormation API reference.Closes #411