Repository navigation
fix(stepfunctions): tag the resource the ARN names, in the shape AWS publishes (#910) - #911
Merged
Merged
Conversation
…publishes (#910) TagResource, UntagResource and ListTagsForResource took the resource name from the ARN's last colon-separated segment and the account and Region from the calling request, so an ARN naming another account's state machine reached the caller's same-named one. UntagResource is the damaging direction: stripping a tag can turn an aws:ResourceTag Deny into an allow, and it answered 200 while doing it. A cross-Region ARN did the same. That is the rule #826 established for SQS and DynamoDB and #845 carried across the tagging resolver; these three were never audited against it. All four readers — the three operations and the tagging API's states arm — now key through one sfnResolveARN that takes no *RequestContext, so the account coming from the ARN is structural rather than remembered at each call site. The type check was strings.Contains(arn, ":stateMachine:"), a substring test satisfied by a name as readily as by a type segment; it now compares the resource segment alone, still case-sensitively, because AWS distinguishes stateMachine from activity by the literal segment. Three more in the same functions: ResourceNotFound answers 400, the status AWS publishes for it, where substrate answered a 404 no Step Functions endpoint returns; an execution ARN's InvalidArn is now a decision rather than the end of a Contains chain; and tags is an array of {key, value} objects on the wire, which CreateStateMachine and CreateActivity in the same plugin already decoded — so TagResource could not be called by any SDK and ListTagsForResource answered a shape none could decode. For #835's two Step Functions rows: the states merge arm decoded StateMachineState whatever the key named, so tagging an activity dropped its activityArn. It now edits the raw JSON's tags member through the shared helper, behind a kind guard for the executions and index keys no ARN addresses, and GetResources gained an activities scanner. Closes #910. Part of #835 — two more of its remaining rows.
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
This was referenced Sep 15, 2026
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 #910. Part of #835 — two more of its remaining rows (Step Functions state machine and activity), leaving five.
The account defect
TagResource(stepfunctions_plugin.go:1015),UntagResource(:1068) andListTagsForResource(:1120) each did this:extractSMNameFromARNisarn[strings.LastIndexByte(arn, ':')+1:]— the last segment and nothing else. The account and Region segments were never read. So an ARN naming another account's same-named state machine resolved the caller's own, andUntagResourcestripped tags from it: the damaging direction, since removing a tag turns anaws:ResourceTagDenyinto an allow, and it answered200while doing it. A cross-Region ARN in the caller's own account did the same.This is the class #826 closed for SQS and DynamoDB and #845 closed across the tagging API's resolver. One builder, no request context:
sfnResolveARN(arn) (ns, key string, err error)takes no*RequestContextat all, and the plugin'ssmKey/activityKeyare now thin wrappers over the two package-level key functions it calls — so there is exactly one producer of astatemachine:/activity:key in the tree, and the tagging API'sstatesarm goes through the same one. That isecsTagStateKey's arrangement, adopted for the same reason: two derivations of one key drift, and where they drift a tag lands on a record the other side does not read.The type check was not a type check
strings.Contains(arn, ":stateMachine:")is a substring test over the whole ARN, satisfied by a name as readily as by the type segment —arn:aws:states:{region}:{acct}:activity:x:stateMachine:ytook the state-machine branch. The comparison is now againstparts[5]alone, and stays case-sensitive, because AWS distinguishes its two taggable resources by the literal segment:stateMachinewith a capital M againstactivity. The tagging API's arm already did this correctly and recorded why; the two now share the function rather than the reasoning.Two things AWS publishes that substrate did not answer
ResourceNotFoundis HTTP 400. All three operation pages list it as "Could not find the referenced resource." with "HTTP Status Code: 400". Substrate answered 404 — a status no Step Functions endpoint returns — so a consumer branching on the status rather than the code saw something impossible. Verified by fetch onAPI_TagResourceandAPI_ListTagsForResource, not from recollection.tagsis an array of{key, value}objects, not an object. This is the one that made the operations unusable:{"tags": [{"key": "env", "value": "test"}]}Substrate decoded
Tags map[string]stringonTagResource's request and rendered a map onListTagsForResource's response — whileCreateStateMachine(:301) andCreateActivity(:830) in the same plugin already decoded[]map[string]string. So the plugin disagreed with itself about the wire shape of its own tags: a tag set at create time could not be read back in a shape any SDK decodes, andTagResourcecould not be called by an SDK at all (its array body fails to unmarshal into a map, answeringInvalidRequest/400).That is why the shape fix is in this PR rather than its own. It is not scope creep in the direction of "more": without it there is no way to write an over-the-wire test in AWS's actual shape, so the ARN fix would be asserted only on a path no consumer can reach.
ListTagsForResourcesorts the array by key. AWS documents no order, so this is substrate's reading, justified by the replay promise — an order following Go's map hash seed differs between two identical calls in one run and cannot replay from the event log (#862).#835's two rows
Sharing the resolver was again only half of it. The
statesNamespacemerge arm (tagging_plugin.go:1266) decodedStateMachineStatewhatever the key named, so tagging an activity through the tagging API replaced its record with a state-machine-shaped one.ActivityArnhas no counterpart in that struct, so it vanished outright — nothing refused, and the tag itself was correct, which is exactly why a test asserting on the tag cannot see it. The arm now goes through the sharedmergeRecordStringMapTags#908 generalized out ofecsMergeRecordTags, behindsfnKeyIsTaggable, because thestatesnamespace also holds executions and three index keys (statemachine_names:,execution_ids:,activity_names:) that no ARN addresses and that store no tags. The guard and the raw-JSON merge fix different failures and neither substitutes for the other; the arm's comment names both separately.GetResourcesgainedscanStepFunctionsActivities, since a resolver arm alone makes a resource taggable by name while leaving it invisible to a caller discovering resources — the two halves of #835's criterion per row. Nineteen resource types are now scanned.Provenance
AWS's, verified by fetch against the API reference:
resourceArnis "the Amazon Resource Name (ARN) for the Step Functions state machine or activity" on all three operations — so those two are the whole taggable set and an execution ARN is not admissible.TagResource's errors:InvalidArn/400,ResourceNotFound/400,TooManyTags/400.ListTagsForResource':InvalidArn/400,ResourceNotFound/400. Both publishResourceNotFoundat 400, not 404.Tagshape and the array-valuedtagsmember, fromAPI_TagResource's Request Syntax andAPI_ListTagsForResource's Response Syntax.Substrate's reading, stated as such in the code and in
docs/services.md:InvalidArnfor an execution ARN. It is well-formed and names a resource these operations do not accept; AWS publishes no code for that case specifically.InvalidArnsays the ARN does not belong at this operation, whereResourceNotFoundwould claim a resource is missing that may well exist. Substrate answeredInvalidArnbefore this change too, but by falling off the end of thestrings.Containschain — it is now a decision.tagsby key, per tagging: the four merge helpers store a resource's tags in Go map order, so one state hashes two ways #862./or:. AWS'sNamepattern excludes both; a key built from one addresses nothing, and reporting the ARN malformed rather than the resource absent is the difference between a caller fixing its ARN and a caller waiting for a resource to appear.TooManyTagsis not implemented and no tag-count cap is enforced here, which is unchanged by this PR.Tests
emulator/stepfunctions_tags_test.go, 11 top-level tests, all over the wire throughStartTestServer. Every resource is created through its own operation and every ARN taken out of the create response rather than composed — a composed ARN would let the test agree with a resolver that disagreed with whatCreateStateMachinereports, which is the divergence being fixed. NoputTest*helper (#765).Coverage: 84.1% emulator / 83.6% total, up from 84.0% / 83.5%.
Mutation test, three stages (by
cp, nevergit stash)1. Account and Region from the request context restored (name from the last segment,
strings.Containsbranch): exactly the two cross-boundary tests fail and nothing else —2. The
StateMachineStatedecode restored in the merge arm:TestSFNTags_BothTypesAreReachableFromTheTaggingAPI/activityfails with it, because the scanner reports the now-emptyActivityArnandGetResourcescan no longer find the resource it just tagged.3. The map wire shape restored on both the request and the response: 8 of the 11 fail. That breadth is the point — every test that reads a tag back reads it through
ListTagsForResource, so the shape is load-bearing for all of them.What is asserted
ListTagsForResource; tag through Step Functions → read throughGetResources;UntagResources→ gone. The removal direction is never the untested one.activityArn/name/creationDate,definition/roleArn/type/status). Each test first asserts the create path stored those members, so it cannot pass vacuously against an empty record.ResourceNotFoundat 400 across all three operations for both kinds — the read side and the write side resolved separately before, so they could disagree about the code.statemachine:segment, a capitalizedActivity:segment, a name carrying:stateMachine:as a substring, a name carrying/, an empty name, another service's ARN, and a truncated ARN. A state machine is created first so none of these can be passing merely because nothing exists.tagsmember is refused rather than half-accepted — with a follow-up assertion that the refused call wrote nothing.GetResourcesreporting both types.Three existing tests asserted the map shape and now assert the array (
stepfunctions_plugin_test.go,tagging_arn_guards_test.go,cfn_stamp_beyond_ec2_test.go). They were passing on a shape no SDK produces, so this is a finding recorded rather than a test relaxed — each carries a comment saying so.Recorded, not fixed
Eleven non-tagging operations are still on the old path — filed as #912, not folded in here.
DescribeStateMachine,UpdateStateMachine,DeleteStateMachine,StartExecution,StartSyncExecution,StopExecution,DescribeExecution,GetExecutionHistory,ListExecutions,DescribeActivityandDeleteActivityall use the sameextractSMNameFromARN(:278) +ctx.AccountID/ctx.Regionpair, so a cross-account or cross-Region ARN reaches the caller's own resource there too. Four of them mutate it:DeleteStateMachineandDeleteActivitydelete the caller's own same-named resource and answer 200, which is this PR'sUntagResourcefinding one severity worse. Executions also need a third resolver arm with per-type segment arity, sincesfnResolveARN'sContainsAny(name, "/:")guard deliberately refuses the two-segment execution form. That is a rewrite of the plugin's execution and lifecycle paths, which does not belong in a tagging diff — hence its own issue rather than a note implied by this one.Compatibility
ListTagsForResourceandTagResourcechange wire shape.tagsis now an array of{key, value}objects on the response and required as one on the request — a caller that sent or decoded an object must change, and a caller using an AWS SDK now works where it previously could not.ResourceNotFoundanswers 400 where it previously answered 404. An ARN naming another account's or another Region's resource now answersResourceNotFoundrather than silently tagging the caller's own. Anactivity:ARN now succeeds at the tagging API where it previously resolved to a same-named state machine or wrote a phantom record, andGetResourcesreports activities it previously omitted.tagsis ordered by key, so an assertion that happened to pass on Go's map order may fail.Verification
docs/services.mdbrings the Step Functions operations table up to date (it listed 7 of 18), and adds three sections: the taggable ARN table with the account-from-ARN rule and the execution-ARN decision, the two-code error table with the 400 status called out, and the array tag shape. The tagging section gains a Step Functions paragraph beside the RDS one and its scanner count goes from eighteen to nineteen. Prose cites#910, never a version.