Skip to content

fix(cfn): accept a stack ARN wherever StackName is taken (#544) - #554

Merged
scttfrdmn merged 2 commits into
mainfrom
fix/cfn-stack-arn
Aug 4, 2026
Merged

scttfrdmn merged 2 commits into
mainfrom
fix/cfn-stack-arn

Conversation

@scttfrdmn

Copy link
Copy Markdown
Owner

Closes #544.

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". CreateChangeSet, ExecuteChangeSet, ListChangeSets, DetectStackDrift and DescribeStackResourceDrifts spell 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

DeleteStack documents 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, answered 200, and left the stack standing. A caller had no error to catch and no status to poll; the next CreateStack answering AlreadyExists was 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 200 and did nothing. The two paths disagreed about what a successful delete means.

The change

  • One resolver at the plugin boundary. cfnStackName is modelled on the existing cfnChangeSetName precedent — find :stack/, take the segment before the next / — so normalisation happens once where the caller's string arrives and the deployer's nine d.state.Get(ctx, cfnNamespace, "stack:"+stackName) sites keep taking a name and stay untouched. Normalising inside loadStack instead would leave ListStacks's index-driven reads and persistStack keyed differently from the lookups.
  • Thirteen call sites, not the two the report named. Every routed operation that takes StackName resolves: 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 a StackId.
  • Ordering. In DeleteStack the resolver runs ahead of the absent-is-success tolerance. That ordering is the whole fix for the silent 200.
  • CreateStack is the deliberate exception, documented at the call site: its StackName is "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. cfnStackARN builds the ARN from the partition, Region, account and a cfnDeterministicUUID over 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, and DeleteStack tear down, a stack in another account or Region by hand-writing an ARN.

An out-of-scope ARN reports the same ValidationError an 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, StackScopedOperations and all seven OutOfScopeARNIsRefused subtests go red. DeleteAbsentByARNSucceeds and BareNamesUnchanged are the regression halves and pass either way, which is the point of them.

AnotherCallersARNIsRefused is the sharpest case and needs two callers to state: every case in OutOfScopeARNIsRefused edits 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 vet gate, -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 (DeleteByARNSweepsResources plus every out-of-scope subtest) — as well as the report's narrow describe-only fix, GetTemplate left 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-stacks and get-template by the returned StackId behave as by-name; delete-stack by ARN sweeps pc-data (head-bucket → 404) and frees the name; the foreign-account, foreign-Region and tampered-UUID ARNs are each refused with ValidationError on both describe and delete, and leave the in-scope stack CREATE_COMPLETE with its bucket intact.

Compatibility

A test that asserts a stack ARN in StackName reports ValidationError, or that delete-stack by ARN leaves resources standing, will go red. That is the fix. Bare names are unchanged, including the absent-name tolerances.

Docs: docs/services.md gains a "A stack ARN is accepted wherever StackName is" section, and a stale DeleteStack row claiming it deletes "the stack record only" is corrected — it has swept resources since v0.89.0.

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

codecov Bot commented Aug 4, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 98.07692% with 1 line in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
emulator/cloudformation_plugin.go 98.07% 0 Missing and 1 partial ⚠️

📢 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.
@scttfrdmn
scttfrdmn merged commit b78fddb into main Aug 4, 2026
16 checks passed
@scttfrdmn
scttfrdmn deleted the fix/cfn-stack-arn 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.

CloudFormation: DeleteStack and DescribeStacks do not resolve a stack ARN, only a name

1 participant