Repository navigation
fix(cloudformation): deploy a stack into the calling account and region (#517) - #524
Merged
Merged
Conversation
…on (#517) The deployer synthesized its own request context from substrate's package defaults (123456789012 / us-east-1) regardless of who created the stack. Most plugins embed the account, and some the region, in their state keys, so a caller in any other partition got a stack ARN naming their own account whose resources were written where they could not read them: an unsigned client created a stack reporting CREATE_COMPLETE with a PhysicalResourceId of i-…, and DescribeInstances then correctly returned nothing. Identity now rides on the deployer as an explicit account and region defaulting to today's constants, and the plugin builds a deployer carrying the requesting caller's identity for every path that deploys or reads a resource. Two strings rather than a whole *RequestContext: one would carry a single request's ID and timestamp across every resource, and would invite propagating Principal, which is #411's decision. Six sites read that identity. Threading dispatch alone would have left a half fix: both buildCFNContext calls resolve AWS::AccountId and AWS::Region, and three drift comparators (DynamoDB, SQS, SNS) read partitioned state keys directly — a wrong-partition existence check reports DELETED for a resource that is fine, and a wrong-partition comparator finds nothing to compare and reports no difference at all, which no IN_SYNC assertion can distinguish from drift working. BettyClient keeps the defaults deliberately: it is the in-process validation client and its callers never sign a request, so there is no caller identity to take. Its deployer is now built through the constructor rather than as a struct literal, which had left both fields empty — harmless only for as long as nothing read them. The #483 comment on cfnStackID described this as a pseudo-parameter discrepancy. That understated it and has been rewritten. The new tests use only partitioned services, because #483's shared-state test asserted a bucket through S3 and a role through IAM — the two unpartitioned plugins, and the reason this survived review. Closes #517
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
This was referenced Aug 3, 2026
Merged
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.
The defect
StackDeployer.dispatchsynthesized its ownRequestContextfrom substrate'spackage defaults —
testAccountID(123456789012) anddefaultRegion(us-east-1) — regardless of who created the stack. Most plugins embed the
account, and some the region, in their state keys:
instance:<account>/<region>/<id>table:<account>/<name>queue:<account>/<name>topic:<account>/<region>/<name>bucket:<name>— unpartitionedrole:<name>— unpartitionedSo a caller in any other partition got a stack ARN naming their own account
whose resources were written where they could not read them. #517's
reproduction: an unsigned client (which resolves to
000000000000) created astack reporting
CREATE_COMPLETEwith aPhysicalResourceIdofi-…, andDescribeInstancesthen returned nothing. Every read scoped to the caller wasright; the write was in the wrong place.
The reporter read that as
AWS::EC2::*being stubbed whileAWS::IAM::*worked. The asymmetry is real but the diagnosis was not — the two families that
appeared to work are exactly the two whose keys carry no account. That is also
why this survived #483's review: its shared-state test asserted a bucket
through S3 and a role through IAM.
The fix
Identity rides on the deployer as an explicit account and region, defaulting to
today's constants, set through
WithDeployerIdentity.Deployhas 145 testcall sites; an option touches none of them, and because the default is unchanged
no existing caller behaves differently.
Two strings rather than a whole
*RequestContext: a deployer holding one wouldcarry a single request's ID and timestamp across every resource it deploys, and
would invite a future reader to propagate
Principal, which is #411's decision.CloudFormationPlugin.deployerFor(reqCtx)builds a deployer per deployingrequest — six pointer copies with no I/O, cheaper than making one deployer's
identity mutable and therefore racy.
p.deployerstays for the paths that touchno resource (the stack and change-set records, which are unpartitioned;
CreateChangeSetis among them since it only parses and diffs two templates).Six sites read that identity, and threading
dispatchalone would have left ahalf-fix:
dispatch— the write path.buildCFNContextcalls —AWS::AccountIdandAWS::Region. Before this,a bucket named
{"Fn::Sub": "b-${AWS::AccountId}"}got substrate's accountrather than the caller's: a wrong physical name, not a misplaced resource.
Neither the issue nor the reporter named this.
own state reads. A wrong-partition existence check reports
DELETEDfor aresource that is fine; a wrong-partition comparator finds nothing to compare
and reports no difference at all — drift silently blind, which no
IN_SYNCassertion can distinguish from drift working.
BettyClientkeeps the defaults deliberately — it is the in-process validationclient and its callers never sign a request, so there is no caller identity to
take. Its deployer now goes through the constructor rather than a struct
literal, which had left both fields empty; harmless only for as long as nothing
read them.
The comment #483 left on
cfnStackIDcalled this a pseudo-parameterdiscrepancy. That understated it and has been rewritten.
Tests
emulator/cloudformation_identity_test.go, 11 tests using only partitionedservices — the test-design lesson from #483:
DescribeInstancesand by ID.ECS::Cluster,Logs::LogGroup,EC2::LaunchTemplate.eu-west-1, absent fromus-east-1.CreateStack,UpdateStack,ExecuteChangeSet.UpdateStackgets its own case because the change-settest reaches it indirectly and would pass with it left unthreaded.
eu-west-1, assertingIN_SYNCand thenMODIFIEDafter a mutation —both reads are separately hardcoded. Both
DescribeStackResourceDriftsandthe
DetectStackDrift/DescribeStackDriftDetectionStatuspair. The SNScase's
DisplayNameis{"Fn::Sub": "${AWS::AccountId} in ${AWS::Region}"},which is the only place either pseudo-parameter is resolved twice.
BettyClientdeploys into the default partition; the option overrides it.Mutation testing: 18 mutants, 18 CAUGHT, no survivors. Three of them were
survivors first and drove test changes: the SQS and SNS comparators (fixed by
tabling drift over all three types),
updateStack(its own test), andcfnDriftResourceProps's context — which needed both pseudo-parameters in adrift-compared property, since a comparator resolving the expected value
against the wrong identity reports
MODIFIEDon a resource nobody touched.StartStackDriftDetectionalso survived untilDetectStackDriftwas assertedover the wire. Mutating the constants default fails 23 pre-existing tests,
confirming it is load-bearing.
Verified over the wire
Against
substrate server, two callers inus-west-2:Pseudo-parameters in
eu-west-1producedq-000000000000-eu-west-1, andsqs get-queue-urlfound that queue. Drift reportedIN_SYNC/DETECTION_COMPLETE/ 0 drifted.gofmt,go build,go vet,golangci-lint(0 issues),make test(race),the docs targets, the VitePress build and the
test/e2emodule all pass.Closes #517