Repository navigation
Description
All three Step Functions tag operations — TagResource (emulator/stepfunctions_plugin.go:1015), UntagResource (:1068) and ListTagsForResource (:1120) — take the resource name out of the resourceArn and the account and Region out of the calling request:
name := extractSMNameFromARN(input.ResourceArn)
if strings.Contains(input.ResourceArn, ":stateMachine:") {
sm, err := p.loadStateMachine(goCtx, ctx.AccountID, ctx.Region, name)extractSMNameFromARN (:275-280) is arn[strings.LastIndexByte(arn, ':')+1:] — the last segment and nothing else. The account and Region segments of the ARN are never read.
So an ARN naming another account's state machine resolves the caller's own same-named one:
TagResourceonarn:aws:states:us-east-1:999999999999:stateMachine:orderswrites tags onto the caller'sordersstate machine and answers200.UntagResourceon the same ARN strips tags from the caller's own state machine — the more damaging direction, and the one that turns anaws:ResourceTagcondition from aDenyinto an allow.ListTagsForResourcereports the caller's tags as though they were the foreign resource's.
A cross-Region ARN does the same thing: arn:aws:states:eu-west-1:{own account}:stateMachine:orders reaches the us-east-1 record when the request is made to the us-east-1 endpoint.
This is exactly the class #826 closed for SQS and DynamoDB and #845 closed across the tagging API's resolver: the account in a key comes from the ARN, not from the calling request. docs/services.md states that rule for the tagging API. Step Functions' own three operations were never audited against it, so the rule holds on one side of the pair and not the other — and since #835's remaining Step Functions row will route the tagging API's activity: ARNs through the same code, the divergence has to be closed before that lands rather than after.
Two smaller defects in the same three functions
-
strings.Contains(arn, ":stateMachine:")is not a resource-type check. It is a substring test over the whole ARN, so it is satisfied by a name as readily as by the type segment —arn:aws:states:us-east-1:{acct}:activity:x:stateMachine:ytakes the state-machine branch. The tagging API's own resolver arm (tagging_plugin.go:1029-1043) does this correctly withstrings.CutPrefix(resource, "stateMachine:")on the resource segment alone plus a refusal of any remaining:, and records why the capital M matters. The two should share one function. -
An execution ARN is silently refused with the wrong code.
arn:aws:states:{region}:{acct}:execution:{sm}:{exec}contains neither:stateMachine:nor:activity:, so it falls to theelseand answersInvalidArn/400 — which happens to be defensible, but by accident rather than by a check, andAWS::StepFunctionspublishesResourceNotFoundfor a well-formed ARN naming nothing. Worth deciding deliberately rather than inheriting.
Suggested shape
Extract one sfnTagStateKey(arn) (namespace, key string, err error) that takes no *RequestContext, so no arm can reach for the caller's account again — the structural guarantee rdsResolveARN and the tagging resolver now both have. Route all three Step Functions tag operations and the tagging API's states arm through it, per the one-builder rule ecsTagStateKey established.
Acceptance criteria
-
sfnTagStateKey(arn)exists, takes no request context, and derives account and Region from the ARN's own segments. - All three Step Functions tag operations and the tagging API's
statesarm key through it — asserted by there being one producer of astatemachine:/activity:key outside the plugin's ownsmKey/activityKeyhelpers, which it must agree with. -
TagResourcenaming another account's same-named state machine answersResourceNotFoundrather than tagging the caller's, asserted over the wire. -
UntagResourcenaming another account's same-named state machine leaves the caller's tags in place — asserted on the caller's tags, not only on the response code. - The same pair for a cross-Region ARN in the caller's own account.
- The same pair for an activity.
- The resource type is determined from the resource segment with a delimiter, not by
strings.Containsover the whole ARN: an ARN whose name contains:stateMachine:is refused, and the case-sensitivity ofstateMachineis preserved and asserted. - An execution ARN's refusal code is decided against the AWS reference and recorded, whichever way it goes.
-
docs/services.md's Step Functions section states that account and Region come from the ARN, matching what the tagging section already says.
Found while implementing #835's RDS rows (PR #908), whose RDS half is the same defect already fixed. Blocks #835's Step Functions rows.
Activity
fix(stepfunctions): tag the resource the ARN names, in the shape AWS …
fix(cloudfront): a tagging ARN addresses the distribution it names (#918
fix(sns): a TopicArn resolves to the topic its own ARN names (#925) (#…
fix(ssm): a tag call resolves to the resource type it names (#932) (#934
fix(tagging): an absent resource is InvalidParameterException, not a …
fix(stepfunctions): an ARN addresses the resource it names (#912) (#997)
fix(#1098): the status Glue's and WAFv2's own pages publish for a not…