Repository navigation
fix(cfn): accept a stack ARN wherever StackName is taken (#544) - #554
Merged
Merged
Conversation
CreateStack answers with a StackId — the stack's ARN — and every stack-scoped operation documents that identifier as an alternative to the name: "The name or the unique stack ID that's associated with the stack". Substrate looked the caller's string up verbatim, so the identifier it had just minted resolved to no stack. DeleteStack is the case worth stating plainly, and it is why this is a silent-success bug rather than a lookup gap: DeleteStack documents no not-found error, so the deployer treats an unresolvable name as a stack already gone and succeeds. Handed an ARN it swept nothing, answered 200, and left the stack standing. v0.89.0's #518 sweep widened the gap — a by-name delete now really does tear resources down, so the two paths disagreed about what a successful delete means. One resolver, cfnStackName, at the plugin boundary, modelled on the cfnChangeSetName precedent, so the deployer's nine "stack:" lookups keep taking a name and stay as they are. Thirteen call sites resolve, not the two the report named; in DeleteStack it runs ahead of the absent-is-success tolerance, which is the whole fix for the silent 200. CreateStack is the deliberate exception: its StackName has no unique-stack-ID alternative, because the ID does not exist until that call mints it. The ARN is verified, not merely parsed. cfnStackARN builds it from the partition, Region, account and a cfnDeterministicUUID over those plus the name, so all of it is recomputable — and comparing the whole string against the one substrate would have minted for this caller checks every component at once, with no way for a later field to be forgotten. Lifting the name out unverified would let a caller reach, and DeleteStack tear down, a stack in another account or Region by hand-writing an ARN: a worse defect than the one being fixed. An out-of-scope ARN reports the same ValidationError an absent stack does, deliberately, since a distinct error would disclose whether another scope holds a stack by that name.
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
Resolving is only half of what each handler has to do — it also has to return the refusal rather than ignore it and carry on with an empty name, which in DeleteStack's case would land straight back in the absent-is-success tolerance. TestCFNStackARN_OutOfScopeARNIsRefused proves the resolver refuses; this proves all twelve call sites propagate, and closes the coverage gap codecov flagged on the arnErr blocks.
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.
Closes #544.
CreateStackanswers with aStackId— the stack's ARN — and every stack-scoped operation documents that identifier as an alternative to the name: "The name or the unique stack ID that's associated with the stack".CreateChangeSet,ExecuteChangeSet,ListChangeSets,DetectStackDriftandDescribeStackResourceDriftsspell the alternative out in the parameter's own pattern,([a-zA-Z][-a-zA-Z0-9]*)|(arn:\b(aws|aws-us-gov|aws-cn)\b:[-a-zA-Z0-9:/._+]*). Substrate looked the caller's string up verbatim, so the identifier it had just minted resolved to no stack.Why this is a silent-success bug, not a lookup gap
DeleteStackdocuments no not-found error, so the deployer deliberately treats an unresolvable name as a stack already gone and succeeds (cfn_deployer.go:1131) — right for a stack that is genuinely absent, wrong for an identifier the lookup merely failed to parse. Handed an ARN it swept nothing, answered200, and left the stack standing. A caller had no error to catch and no status to poll; the nextCreateStackansweringAlreadyExistswas the only symptom.Measured against v0.89.0 before planning, the gap had widened: v0.89.0 shipped #518's resource sweep, so a by-name delete now really does tear resources down while a by-ARN delete still answered
200and did nothing. The two paths disagreed about what a successful delete means.The change
cfnStackNameis modelled on the existingcfnChangeSetNameprecedent — find:stack/, take the segment before the next/— so normalisation happens once where the caller's string arrives and the deployer's nined.state.Get(ctx, cfnNamespace, "stack:"+stackName)sites keep taking a name and stay untouched. Normalising insideloadStackinstead would leaveListStacks's index-driven reads andpersistStackkeyed differently from the lookups.StackNameresolves:UpdateStack,DeleteStack,DescribeStacks,DescribeStackResources,GetTemplate,CreateChangeSet,DescribeChangeSet,ExecuteChangeSet,DeleteChangeSet,ListChangeSets,DetectStackDrift,DescribeStackResourceDrifts. Fixing describe and delete alone would leave the same trap in exactly the operations a caller reaches holding aStackId.DeleteStackthe resolver runs ahead of the absent-is-success tolerance. That ordering is the whole fix for the silent200.CreateStackis the deliberate exception, documented at the call site: itsStackNameis "the name that's associated with the stack" with no unique-stack-ID alternative, because the ID does not exist until that call mints it.The ARN is verified, not merely parsed
This is the one way the fix could have been worse than the bug.
cfnStackARNbuilds the ARN from the partition, Region, account and acfnDeterministicUUIDover those plus the name, so all of it is recomputable at request time — and comparing the whole string against the one substrate would have minted for this caller checks every component at once, with no way for a later field to be forgotten. Lifting the name out unverified would let a caller reach, andDeleteStacktear down, a stack in another account or Region by hand-writing an ARN.An out-of-scope ARN reports the same
ValidationErroran absent stack does, deliberately: a stack outside the caller's account and Region is a stack the caller cannot observe, so a distinct error would disclose whether some other scope holds a stack by that name. Real CloudFormation answers the same way, since credentials scope the request before the identifier is read.Tests
emulator/cfn_stack_arn_test.go, seven tests. Confirmed to fail before the fix: with the plugin change stashed and the tests kept,DescribeByReturnedID,DeleteByARNSweepsResources,StackScopedOperationsand all sevenOutOfScopeARNIsRefusedsubtests go red.DeleteAbsentByARNSucceedsandBareNamesUnchangedare the regression halves and pass either way, which is the point of them.AnotherCallersARNIsRefusedis the sharpest case and needs two callers to state: every case inOutOfScopeARNIsRefusededits one field of a real ARN, which leaves the digest disagreeing with the rest — so a check that verified only the digest would refuse them all and look sufficient. That test hands one caller an ARN that is internally consistent and belongs to a different caller, across both identity and Region.Mutation testing, established harness (anchor-count assert before applying,
gofmt -w && go vetgate,-race): 10 mutants, 10 CAUGHT, 0 survivors. Including the plan's two named ones — the scope check dropped (all seven out-of-scope subtests), and the resolver called after the absent-is-success tolerance (DeleteByARNSweepsResourcesplus every out-of-scope subtest) — as well as the report's narrow describe-only fix,GetTemplateleft verbatim, a prefix-only check that skips the UUID, the caller's account or Region replaced by the ARN's own, an empty name segment resolving, the name not truncated at the next slash, and a bare name put through the ARN check.Verified live on a fresh server:
describe-stacksandget-templateby the returnedStackIdbehave as by-name;delete-stackby ARN sweepspc-data(head-bucket→ 404) and frees the name; the foreign-account, foreign-Region and tampered-UUID ARNs are each refused withValidationErroron both describe and delete, and leave the in-scope stackCREATE_COMPLETEwith its bucket intact.Compatibility
A test that asserts a stack ARN in
StackNamereportsValidationError, or thatdelete-stackby ARN leaves resources standing, will go red. That is the fix. Bare names are unchanged, including the absent-name tolerances.Docs:
docs/services.mdgains a "A stack ARN is accepted whereverStackNameis" section, and a staleDeleteStackrow claiming it deletes "the stack record only" is corrected — it has swept resources since v0.89.0.