Repository navigation
Description
What is wrong
snsNameFromARN (emulator/sns_plugin.go:1130) is four lines:
func snsNameFromARN(arn string) string {
parts := strings.Split(arn, ":")
if len(parts) >= 6 {
return parts[len(parts)-1]
}
return arn
}Ten operations reach it — DeleteTopic, GetTopicAttributes, SetTopicAttributes, Subscribe, Unsubscribe, ListSubscriptionsByTopic, Publish, PublishBatch, and all three of TagResource/UntagResource/ListTagsForResource — and every one of them then keys loadTopic/saveTopic by ctx.AccountID/ctx.Region. Three defects compound.
1. The account and Region come from the caller, not from the ARN. So
arn:aws:sns:eu-west-1:999988887777:orders
presented by a us-east-1 caller in account 111122223333 addresses that caller's own topic named orders, in their own Region. TagResource writes tags onto the wrong topic and answers 200; UntagResource — the damaging direction — strips them and answers 200; Publish publishes to the wrong topic; DeleteTopic deletes it. A caller cannot tell any of these from a correct call.
This is the rule #826 established for SQS and DynamoDB, #845 carried through the tagging API's resolver, #910 applied to Step Functions, #918 to CloudFront and #922 to KMS: the account and Region come from the ARN, never from the request context, and a resolver that cannot reach for the context does not have to remember not to.
2. The last colon segment is not the topic name. A subscription ARN is arn:aws:sns:{region}:{account}:{topic-name}:{subscription-id}, so the last segment of
arn:aws:sns:us-east-1:111122223333:orders:8a21d249-4329-4871-acc6-7be709c6ea7f
is the subscription UUID, returned as a topic name. That is #910's strings.Contains(arn, ":stateMachine:") mistake in the other direction: instead of matching a type keyword too loosely, this matches no keyword at all and takes whatever is last. SNS's topic ARN carries no type keyword and no separator — the resource portion is the name — so the anchored rule here is that a resource portion containing a : is not a topic ARN, and ResourceArn on the three tag operations is documented as an ARN, not as a name.
3. A malformed ARN becomes a topic name. The len(parts) >= 6 guard falls through to return arn, so arn:aws:sns — or any string at all — is used verbatim as a topic name and looked up. Combined with defect 1 that is a lookup at a key nothing is stored at, which answers NotFound; but nothing refuses the input, and NotFound is not a code SNS publishes.
Two smaller defects in the same three handlers
4. Tags.Tag.N.Key and TagKeys.TagKey.N are not decoded. tagResource reads Tags.member.%d.Key/.Value only, and untagResource reads TagKeys.member.%d only. AWS documents the members as Tags.member.N and TagKeys.member.N, but AWS's own request examples wire Tags.Tag.1.Key, Tags.Tag.1.Value and TagKeys.TagKey.1, and a caller that sends those gets 200 with nothing written or nothing removed — the "tag parameter decoded by nobody" class of v0.114.0. Both spellings must be accepted.
5. CreateTopic's Tags parameter is not decoded at all. createTopic (:210) reads Name and DisplayName and ignores Tags, so a topic created with tags in one call reports none. SNSTopic.Tags already exists and TagResource writes it.
The wrong error code
All three handlers answer Code: "NotFound" at http.StatusNotFound. SNS publishes ResourceNotFound at 404 — the status is right and the code name is not, and a caller matching on the code sees something no SDK models. A malformed ResourceArn should be InvalidParameter/400, which all three pages publish and none of them answers today. Unlike #921 and #923 this is not a status change, so it does not need its own issue.
Why it should be fixed with the tagging row of #835
The two are the same change seen from two sides:
- Both need one shared, context-free key builder. The Resource Groups Tagging API cannot write tags for eleven types: mergeResourceTags has no arm #835's
snsarm has to build the same state key from an ARN alone, and a resolver that re-derived the layout would be a second producer of it — the arrangement SQS state keys disagree: the tagging API and the authorizer address queue:<name>, the plugin writes queue:<account>/<name> #826 found had drifted for SQS and cloudfront: the three tagging operations take the account from the caller, not the ARN, and match the resource type by substring #918 for CloudFront. - Account isolation then becomes emergent rather than guarded, as ACM's is and as KMS's tagging arm is: the key is account- and Region-qualified, so a foreign-account ARN builds a key nothing is stored at. Note the difference from fix(kms): a key ARN resolves to the caller's own account, and an alias ARN resolves to its own name #922 — no cross-account statement was found on any of the three SNS tagging pages, so unlike KMS there is no published prohibition to map onto a refusal, and none should be invented. Not-found is the honest answer.
Acceptance criteria
- An SNS topic ARN is parsed as an ARN, by a function taking no
*RequestContext, and the account and Region used for the load and the store come from it. - A resource portion containing a
:is refused rather than resolved: a subscription ARN does not address the topic it names, nor the subscription's UUID as a topic. - A malformed ARN answers
InvalidParameter/400 rather than being used verbatim as a topic name. -
ResourceNotFoundreplacesNotFoundin all three tag handlers, at the published 404. -
Tags.Tag.N.Key/.ValueandTagKeys.TagKey.Nare decoded alongside themember.Nspellings, because AWS's own examples use them. -
CreateTopicdecodesTagsand the tags are readable throughListTagsForResource. -
ListTagsForResourceand the tagging API'sGetResourcesreport a topic's tags in the same order, so the two arms cannot disagree — the tagging: the four merge helpers store a resource's tags in Go map order, so one state hashes two ways #862 rule, reached here by the two arms sorting alike rather than by one of them being nondeterministic (see the correction below). - The five SNS key builders are free functions with no receiver state, so the resolver and the plugin cannot produce two layouts.
- The tagging API's kind guard tests a colon-terminated prefix, because
topicis a prefix oftopic_names— the fourth namespace to need one aftercert/cert_arns,cfdist/cfdist_idsandkey/key_ids. - Wire tests for each of the above through
StartTestServer, with every tag read back through SNS's ownListTagsForResourceper cfn: the aws:cloudformation:* stamp covers EC2 only, so the rest of a stack is unstamped #765 and in the other direction throughGetResources. -
docs/services.mdandCHANGELOG.mdrecord the change, including what it deliberately leaves alone.
A correction to the record
The comment I left on #835 when the KMS row shipped says all three remaining services "build their merged tag slice from a Go map range with no sort". That is wrong for SNS: tagResource merges over indexed request parameters into a slice and untagResource filters that slice, both of which are already deterministic. The ordering criterion above is therefore not a nondeterminism fix here — it is that SNS's own arm preserves insertion order while the tagging API's arm emits key-sorted order, so one topic's tags come back in two different orders depending on which API is asked. The claim stands for Secrets Manager and SSM and will be re-verified when each is taken.
Deliberately out of scope
- The
<Value>-before-<Key>element order. AWS's publishedListTagsForResourcesample response emits<Value>before<Key>; substrate emits<Key>first. XML member order is not significant to any SDK's parser, and no test can assert a difference a caller can act on, so this is recorded rather than changed. - The 10 TPS limit on SNS tagging actions. Substrate models no rate limiting for these operations; that is a seedable-throttle question, not an ARN one.
Provenance
The topic ARN format, the subscription ARN format, ResourceArn's 1011-character maximum, the Tags.Tag.N/TagKeys.TagKey.N request examples, the Key/Value field names and lengths, the absence of pagination on ListTagsForResource, and the error set — AuthorizationError 403, ConcurrentAccess 400, InvalidParameter 400, ResourceNotFound 404, StaleTag 400, TagLimitExceeded 400, TagPolicy 400 — are quoted from API_TagResource, API_UntagResource, API_ListTagsForResource, API_CreateTopic and API_Subscribe in the SNS API reference. That no cross-account statement appears on the three tagging pages is a negative finding, recorded as such rather than as permission.
Activity
fix(ssm): a tag call resolves to the resource type it names (#932) (#934
fix(sns): a topic operation checks that its topic exists, and DeleteT…