Skip to content

fix(stepfunctions): an ARN addresses the resource it names (#912) - #997

Merged
scttfrdmn merged 1 commit into
mainfrom
fix/sfn-arn-resolution
Sep 17, 2026
Merged

scttfrdmn merged 1 commit into
mainfrom
fix/sfn-arn-resolution

Conversation

@scttfrdmn

Copy link
Copy Markdown
Owner

Closes #912.

Eleven Step Functions operations took the resource name from the last colon-separated segment of the ARN they were handed and the account and Region from the caller's own request context. #910 fixed the three tagging operations against the rule #826 established for SQS and DynamoDB, and left these eleven, which had never been audited against it: DescribeStateMachine, UpdateStateMachine, DeleteStateMachine, StartExecution, StartSyncExecution, ListExecutions, DescribeActivity, DeleteActivity, DescribeExecution, StopExecution, GetExecutionHistory.

Three separate defects followed from the one extraction.

An ARN naming another account's or another Region's resource reached the caller's own same-named one. DescribeStateMachine disclosed it, UpdateStateMachine rewrote it, DeleteStateMachine and DeleteActivity removed it, StopExecution aborted it — every one answering 200. StopExecution is the damaging direction here, as UntagResource was in #910: aborting the wrong execution destroys work and the caller is told it succeeded. StartExecution and StartSyncExecution compounded it by minting the execution ARN from the caller's account and Region rather than the state machine's, so the ARN they reported named an execution that could not be found at the key it had been written to.

The resource-type segment was never read. An activity ARN at DescribeStateMachine looked for a state machine named after the activity; an execution ARN there looked for one named after the execution. All now answer InvalidArn/400 — the resource may well exist, and it is the ARN that does not belong at this operation, which is the decision #910 recorded for an execution ARN at a tagging operation.

An execution ARN's two names were reconstructed by stripping one segment, which is right only for an ARN of exactly that arity.

What changed

New emulator/stepfunctions_arn.go holds one parser serving all fourteen operations plus the tagging resolver. It takes no request context at all, so the guarantee is structural rather than something each call site has to remember — the arrangement ECS has had since #826. Nine of the eleven handlers now take _ *RequestContext, which is the compiler-enforced form of the same statement: there is no request context in scope to locate a resource with. (StartExecution and StartSyncExecution keep theirs, because the ASL executor takes it.)

The three *DoesNotExist codes move from HTTP 404 to 400, and each operation answers the code its own page publishes — StateMachineDoesNotExist, ActivityDoesNotExist, ExecutionDoesNotExist, and ResourceNotFound at the tagging operations — which is why there are four rather than one.

ListExecutions gained the checks it had none of. Neither or both of stateMachineArn/mapRunArn answers ValidationException/400; a mapRunArn alone answers ResourceNotFound/400; and an absent state machine answers StateMachineDoesNotExist/400 rather than 200 with an empty list — previously indistinguishable from a state machine that exists and has never run, the one pair a consumer polling for executions cannot tell apart.

A Task state's Resource went through the same extraction and now has its own reader. A qualified ARN such as arn:aws:lambda:{region}:{account}:function:score:PROD invoked a function named after the alias, and arn:aws:states:::lambda:invoke — the optimized integration, which contains :lambda: and so passed the old substring dispatch test — invoked one named invoke. Both failed the execution.

Boundaries recorded rather than resolved

  • A version or alias ARN (…:stateMachine:orders:1, …:stateMachine:orders:live) is refused with InvalidArn. Substrate's reading: both are well-formed at AWS and neither names anything substrate keeps a record of, so resolving either to the unqualified state machine would hand a caller a different resource from the one it asked for — the defect this work exists to end.
  • An express execution ARN resolves to nothing instead, answering ExecutionDoesNotExist, because StartSyncExecution mints that shape itself and refusing it for its shape would claim AWS rejects an ARN it issues.
  • A mapRunArn answering ResourceNotFound is substrate's reading: a Map Run is not modeled, no operation mints one, and that code is published on the page.

Deliberately out of scope, filed instead

Provenance

All eleven Step Functions API reference pages were read in full. Every error on every one of them is HTTP 400, including the three *DoesNotExist codes — which is why the status change is part of this PR rather than a nicety. API_ListExecutions supplies both halves of the mapRunArn rule: stateMachineArn is "Required: No", and "You can specify either a mapRunArn or a stateMachineArn, but not both." No page contains any cross-Region, cross-account, or "ARN in another account" statement, so the resolution rule rests on #826's precedent rather than on a sentence.

Substrate's readings, stated as such in docs/services.md: the version/alias refusal, the mapRunArn code, and the express-ARN resolution.

Testing

New emulator/stepfunctions_arn_test.go — 20 tests, 173 subtests, all over the wire through emulator.StartTestServer with two accounts registered. Every ARN is either taken out of a create response (per #765) or composed deliberately to name something that does not exist, and the two cases are kept visibly separate. Requests go through scanScopeSignedTarget rather than signedRequest, because signedRequest signs every request for us-east-1 and a cross-Region assertion needs the Host and the credential scope to agree.

Statuses are asserted alongside codes throughout, and error codes are read off the raw body rather than a decoded struct.

Covered: cross-Region and cross-account resolution reporting the target's definition; every operation's published not-found code at 400; ten malformed ARN shapes past all eleven operations; wrong-type ARNs in all six directions; a delete through a foreign ARN leaving the caller's own resource and its index intact; StopExecution aborting the ARN's execution and not the caller's; execution ARNs minted in the state machine's account and Region and then findable from either endpoint; ListExecutions' four input cases and its absent-state-machine refusal; version and alias ARNs; the express ARN and its trailing-extra-segment form; tag-then-read cross-readability between the #910 operations and these; and the qualified-Lambda and optimized-integration Task resources, each asserted on the execution's output so the test cannot pass on the stub path.

Verification

Nine-command gate, all clean:

gofmt -l . && go build ./... && go vet ./...          ✓ (no output)
golangci-lint run ./...                                ✓ 0 issues
make test                                              ✓
GOTOOLCHAIN=go1.26.6 make test                         ✓
GOTOOLCHAIN=go1.26.6 make coverage                     ✓ 84.5% emulator / 84.0% total
make docs-reference docs-reference-check docs-versions authz-reference-check   ✓
npm --prefix docs run build                            ✓
go vet -C test/e2e ./... && go test -C test/e2e ./...   ✓

Coverage holds the 84.5% / 84.0% baseline exactly.

Compatibility

  • StateMachineDoesNotExist, ActivityDoesNotExist and ExecutionDoesNotExist now answer 400, not 404. A consumer branching on the HTTP status must be updated; one branching on the code is unaffected.
  • An ARN naming another account's or another Region's resource no longer reaches the caller's own. A test that relied on the old behaviour — passing a hand-composed ARN and getting the local resource back — now gets a *DoesNotExist refusal.
  • An execution ARN's account and Region come from the state machine, not the caller. StartExecution called cross-Region reports a different ARN than before.
  • A wrong-type ARN now answers InvalidArn where it previously answered a not-found code, or in some cases resolved to an unrelated resource that happened to share the last segment's name.
  • A version or alias ARN now answers InvalidArn where it previously resolved to the unqualified state machine.
  • ListExecutions refuses three input shapes it used to accept, and refuses an absent state machine it used to report an empty list for.
  • A Task state whose Resource is a qualified Lambda ARN or an optimized integration now succeeds where the execution previously reported FAILED.

See docs/services.md's Step Functions section and the ## [Unreleased] CHANGELOG entry.

Eleven operations took the resource name from the last colon-separated segment of
the ARN they were handed and the account and Region from the caller's own request
context. #910 fixed the three tagging operations and left these eleven.

Three defects followed from the one extraction:

  1. An ARN naming another account's or another Region's resource reached the
     caller's own same-named one. DescribeStateMachine disclosed it,
     UpdateStateMachine rewrote it, DeleteStateMachine and DeleteActivity removed
     it, StopExecution aborted it — every one answering 200. StartExecution and
     StartSyncExecution compounded it by minting the execution ARN from the
     caller's account and Region rather than the state machine's, so the ARN they
     reported named an execution that could not be found at the key it had been
     written to.
  2. The resource-type segment was never read, so an activity ARN at a
     state-machine operation and an execution ARN at either were told apart only
     by accident. All now answer InvalidArn/400.
  3. An execution ARN's two names were reconstructed by stripping one segment,
     which is right only for an ARN of exactly that arity.

New emulator/stepfunctions_arn.go holds one parser for all fourteen operations
and the tagging resolver. It takes no request context at all, so the guarantee is
structural rather than something each call site has to remember — the arrangement
ECS has had since #826. Nine handlers now take `_ *RequestContext`, which is the
compiler-enforced form of the same statement.

The three *DoesNotExist codes move from HTTP 404 to 400: every error on all
eleven API reference pages consulted is published at 400, and each operation now
answers the code its own page publishes. A version or alias ARN is refused with
InvalidArn (substrate's reading); an express execution ARN resolves to nothing
instead, since StartSyncExecution mints that shape itself.

ListExecutions gained the checks it had none of: neither or both of
stateMachineArn/mapRunArn is a ValidationException, a mapRunArn alone is
ResourceNotFound, and an absent state machine is StateMachineDoesNotExist rather
than 200 with an empty list.

A Task state's Resource went through the same extraction, so a qualified Lambda
ARN invoked a function named after the alias and arn:aws:states:::lambda:invoke
invoked one named "invoke". It now has its own reader.

DeleteStateMachine/DeleteActivity refusing an absent resource with an unpublished
code is #995; StartSyncExecution's InvalidDefinition is #996.
@scttfrdmn scttfrdmn added this to the v0.118.0 milestone Sep 17, 2026
@codecov

codecov Bot commented Sep 17, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 96.91358% with 5 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
emulator/stepfunctions_plugin.go 96.55% 3 Missing ⚠️
emulator/stepfunctions_arn.go 96.61% 2 Missing ⚠️

📢 Thoughts on this report? Let us know!

@scttfrdmn
scttfrdmn merged commit ce5316f into main Sep 17, 2026
17 checks passed
@scttfrdmn
scttfrdmn deleted the fix/sfn-arn-resolution branch September 17, 2026 07:13
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.

Eleven Step Functions operations resolve a resource by the ARN's last segment plus the caller's own account and Region

1 participant