Repository navigation
fix(stepfunctions): an ARN addresses the resource it names (#912) - #997
Merged
Merged
Conversation
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.
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
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 #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.
DescribeStateMachinedisclosed it,UpdateStateMachinerewrote it,DeleteStateMachineandDeleteActivityremoved it,StopExecutionaborted it — every one answering200.StopExecutionis the damaging direction here, asUntagResourcewas in #910: aborting the wrong execution destroys work and the caller is told it succeeded.StartExecutionandStartSyncExecutioncompounded 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
DescribeStateMachinelooked for a state machine named after the activity; an execution ARN there looked for one named after the execution. All now answerInvalidArn/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.goholds 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. (StartExecutionandStartSyncExecutionkeep theirs, because the ASL executor takes it.)The three
*DoesNotExistcodes move from HTTP 404 to 400, and each operation answers the code its own page publishes —StateMachineDoesNotExist,ActivityDoesNotExist,ExecutionDoesNotExist, andResourceNotFoundat the tagging operations — which is why there are four rather than one.ListExecutionsgained the checks it had none of. Neither or both ofstateMachineArn/mapRunArnanswersValidationException/400; amapRunArnalone answersResourceNotFound/400; and an absent state machine answersStateMachineDoesNotExist/400 rather than200with 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
Resourcewent through the same extraction and now has its own reader. A qualified ARN such asarn:aws:lambda:{region}:{account}:function:score:PRODinvoked a function named after the alias, andarn:aws:states:::lambda:invoke— the optimized integration, which contains:lambda:and so passed the old substring dispatch test — invoked one namedinvoke. Both failed the execution.Boundaries recorded rather than resolved
…:stateMachine:orders:1,…:stateMachine:orders:live) is refused withInvalidArn. 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.ExecutionDoesNotExist, becauseStartSyncExecutionmints that shape itself and refusing it for its shape would claim AWS rejects an ARN it issues.mapRunArnansweringResourceNotFoundis 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
DeleteStateMachineandDeleteActivityrefuse an absent resource with a code their own pages do not publish (their error lists areInvalidArn/ValidationExceptionandInvalidArnalone). This PR moved their status to 400 with the rest but left the question open, because the evidence is an absence from an error list rather than a published idempotence sentence, and it needs its own argument. Step Functions: DeleteStateMachine and DeleteActivity refuse an absent resource with a code their pages do not publish #995 also carries whether theDELETINGstatus andStateMachineDeleting/400 are modeled.StartSyncExecutionanswersInvalidDefinitionwhere AWS namesStateMachineTypeNotSupported, and separately reports the same code for a stored definition substrate itself cannot parse.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
*DoesNotExistcodes — which is why the status change is part of this PR rather than a nicety.API_ListExecutionssupplies both halves of themapRunArnrule:stateMachineArnis "Required: No", and "You can specify either amapRunArnor astateMachineArn, 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, themapRunArncode, and the express-ARN resolution.Testing
New
emulator/stepfunctions_arn_test.go— 20 tests, 173 subtests, all over the wire throughemulator.StartTestServerwith 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 throughscanScopeSignedTargetrather thansignedRequest, becausesignedRequestsigns every request forus-east-1and 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;
StopExecutionaborting 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:
Coverage holds the 84.5% / 84.0% baseline exactly.
Compatibility
StateMachineDoesNotExist,ActivityDoesNotExistandExecutionDoesNotExistnow answer 400, not 404. A consumer branching on the HTTP status must be updated; one branching on the code is unaffected.*DoesNotExistrefusal.StartExecutioncalled cross-Region reports a different ARN than before.InvalidArnwhere 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.InvalidArnwhere it previously resolved to the unqualified state machine.ListExecutionsrefuses three input shapes it used to accept, and refuses an absent state machine it used to report an empty list for.Resourceis a qualified Lambda ARN or an optimized integration now succeeds where the execution previously reportedFAILED.See
docs/services.md's Step Functions section and the## [Unreleased]CHANGELOG entry.