Skip to content

Step Functions: all three tag operations take the account from the request, not the ARN, so a foreign-account ARN tags the caller's own state machine #910

Closed

Description

@scttfrdmn

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:

  • TagResource on arn:aws:states:us-east-1:999999999999:stateMachine:orders writes tags onto the caller's orders state machine and answers 200.
  • UntagResource on the same ARN strips tags from the caller's own state machine — the more damaging direction, and the one that turns an aws:ResourceTag condition from a Deny into an allow.
  • ListTagsForResource reports 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

  1. 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:y takes the state-machine branch. The tagging API's own resolver arm (tagging_plugin.go:1029-1043) does this correctly with strings.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.

  2. 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 the else and answers InvalidArn/400 — which happens to be defensible, but by accident rather than by a check, and AWS::StepFunctions publishes ResourceNotFound for 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 states arm key through it — asserted by there being one producer of a statemachine:/activity: key outside the plugin's own smKey/activityKey helpers, which it must agree with.
  • TagResource naming another account's same-named state machine answers ResourceNotFound rather than tagging the caller's, asserted over the wire.
  • UntagResource naming 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.Contains over the whole ARN: an ARN whose name contains :stateMachine: is refused, and the case-sensitivity of stateMachine is 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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    type: bug

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions