Skip to content

feat(cloudformation): authorize a stack's resource calls and model its service role (#411, #562) - #574

Merged
scttfrdmn merged 1 commit into
mainfrom
feat/562-stack-service-role
Aug 5, 2026
Merged

scttfrdmn merged 1 commit into
mainfrom
feat/562-stack-service-role

Conversation

@scttfrdmn

Copy link
Copy Markdown
Owner

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 GetQueueUrl returned NonExistentQueue and the pool never
drained. 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, so
authorizing 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, DescribeStackResources
renders it as CREATE_FAILED with the denial as ResourceStatusReason, and the
stack rolls back through cfn_rollback.go untouched. The refusal is recorded in
the event log beside the calls that succeeded, so a replay shows where the
deployment stopped and why.

It is not yet a StackEvent. DescribeStackEvents is still refused with
UnsupportedOperation, and deriving events from the event store — with its
ordering, 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 StackEvent criterion stays open against #501.

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, omitempty so a stack without one reports nothing, and length-validated as the
model specifies.

The documented lifetime rules, which are not the convenient ones:

Operation Behaviour Source
CreateStack sets the role —
UpdateStack omitting RoleARN keeps the stored role "CloudFormation uses the role that was previously associated with the stack"
UpdateStack supplying one replaces it for this and every later operation "always uses this role for all future operations on the stack"
DeleteStack supplying one applies to that operation only, not persisted the phrase is absent from DeleteStack

The 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, 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.
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 RoleARN is used directly as a role principal — the evaluator's role path
resolves it — rather than run through AssumeRole, keeping this inside the scope
boundary: 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_COMPLETE where it previously reached CREATE_COMPLETE. That is the
point of the release.

A stack with no service role and no resolvable creating principal deploys exactly
as before — every existing test, every in-process Client caller,
AKIAIOSFODNN7EXAMPLE. State encoding gains CFNStackState.RoleARN and
CreatorPrincipalARN, both omitempty, 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 over RoleARN)
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 whose
own 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's CheckAccess removed while the principal is still
carried; DeleteStack's RoleARN persisted; UpdateStack's omitted RoleARN
cleared; the delete sweep not attributed to the stack; the rollback's attribution
not persisted; the creating principal not carried; and resolveOperationName moved
after authorization (the new coupling with #572 — without it the action evaluated
for a stack's bucket is s3:PUT again).

gofmt -l ., go build ./..., go vet ./..., golangci-lint run ./... → 0
issues
, 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 :4655

# the non-breaking gate first, with the credential everything documents
AWS_ACCESS_KEY_ID=AKIAIOSFODNN7EXAMPLE aws s3 mb s3://plain
  → make_bucket: plain

# a role that cannot create the bucket
aws cloudformation create-stack --stack-name narrowstack --role-arn .../role/narrow
aws cloudformation describe-stacks  --query 'Stacks[0].[StackStatus,RoleARN]'
  → ROLLBACK_COMPLETE   arn:aws:iam::123456789012:role/narrow
aws cloudformation describe-stack-resources --query 'StackResources[0].ResourceStatusReason'
  → AccessDeniedException: User: arn:aws:iam::123456789012:role/narrow is not
    authorized to perform: s3:CreateBucket on resource: arn:aws:s3:::e2e-role-bucket

# a role that can
  → CREATE_COMPLETE   arn:aws:iam::123456789012:role/wide     (bucket present in s3 ls)

# UpdateStack omitting RoleARN keeps it
  → arn:aws:iam::123456789012:role/wide

# DeleteStack --role-arn narrow: refused, and the stack's own role is untouched
  → DELETE_FAILED   arn:aws:iam::123456789012:role/wide
# retried with the stack's own role: gone
  → ValidationError: Stack with id widestack does not exist

# no service role: the creator's own policy governs (cloudformation:* + s3:ListBucket)
  → ROLLBACK_COMPLETE   None
  → AccessDeniedException: User: arn:aws:iam::123456789012:user/alice is not
    authorized to perform: s3:CreateBucket ...

# #411's acceptance, same credential
aws sqs list-queues        → AccessDeniedException ... sqs:ListQueues on resource: *
aws s3api list-objects --bucket plain  → 0        (allowed: s3:ListBucket)

That last pair also exercises #572's action renames — a list-objects authorizing
against s3:ListBucket.

Provenance

That RouteRequest never authorizes, and that a stack's dispatch carried no
principal, were measured with throwaway in-package probes rather than read off
a reference. The RoleARN shapes and lifetime semantics are from the
CloudFormation botocore model (CreateStack/UpdateStack/DeleteStack inputs and
the Stack output shape) and the CloudFormation API reference.

Closes #411

…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

codecov Bot commented Aug 5, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 81.00000% with 19 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
emulator/cfn_deployer.go 73.68% 9 Missing and 1 partial ⚠️
emulator/cloudformation_plugin.go 88.88% 2 Missing and 3 partials ⚠️
cmd/substrate/main.go 0.00% 3 Missing ⚠️
emulator/testing.go 80.00% 0 Missing and 1 partial ⚠️

📢 Thoughts on this report? Let us know!

@scttfrdmn
scttfrdmn merged commit ddfc0c1 into main Aug 5, 2026
13 checks passed
@scttfrdmn
scttfrdmn deleted the feat/562-stack-service-role branch August 9, 2026 17:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Principal-aware test mode: enforce IAM authorization in composition tests

1 participant