Repository navigation
fix(sns): a TopicArn resolves to the topic its own ARN names, and the tagging API reaches an SNS topic (#925) - #927
Merged
Merged
Conversation
snsNameFromARN split the identifier on ":" and returned the last segment, and its callers then keyed the load and the store by the caller's own AccountID and Region. Three defects compounded across ten operations: an ARN naming another account or Region addressed the caller's own same-named topic (UntagResource answered 200 while stripping its tags, Publish published to it and DeleteTopic deleted it); a subscription ARN's last segment is the subscription's own identifier, returned as a topic name; and the length guard fell through to returning its argument, so any string at all became a topic name. The replacement, snsParseTopicARN in the new emulator/sns_tags.go, takes no *RequestContext, which makes "the account and Region come from the ARN" structural rather than a thing ten call sites have to remember — the arrangement #826, #845, #910, #918 and #922 established for SQS/DynamoDB, the tagging resolver, Step Functions, CloudFront and KMS. An SNS topic ARN has no type keyword and no separator before the name, so the anchored-segment rule of #910 has nothing to anchor on; the discriminator the shape does offer is the colon, and a resource portion containing one names a subscription. A malformed ARN is InvalidParameter/400. Subscribe now mints its subscription ARN under the topic's account and Region, and DeleteTopic removes the owning Region's name-index entry. The subscription record and the two subscription indexes stay keyed by the caller deliberately: a cross-account subscription is not modeled at all, so moving them would leave Publish reading an index the subscriptions are not in. Also in this pass, and part of #835: the Resource Groups Tagging API reaches an SNS topic. It answered an InternalServiceException FailedResourcesMap entry from resolveARN's default arm while SNS's own TagResource wrote the tag, so a tag was writable through one API and invisible to the other. The fourth of the eleven rows; a resolver arm, a merge arm and a scanner, over the same context-free parser SNS's own operations use, so neither API can address a topic the other would not. The merge reuses mergeRecordTagListTags with Key/Value field names, behind a colon-terminated taggability guard — the fourth namespace to need one, since "topic" is a prefix of "topic_names". Both arms re-emit sorted by key, per #862. Account isolation is emergent rather than guarded, as ACM's is; no cross-account statement appears on any of SNS's three tagging pages, so nothing is refused that the ARN's own account and Region do not already refuse by construction. Two tagging defects with it: AWS's reference names the members Tags.member.N and TagKeys.member.N while AWS's own request examples on those same pages wire Tags.Tag.1.Key and TagKeys.TagKey.1, so both spellings are now decoded; and CreateTopic's Tags parameter was decoded by nobody. The three tag operations answer ResourceNotFound/404, which they publish, rather than the plain NotFound substrate used — the status was right and the code name was one no SDK models. Deliberately left: the <Value>-before-<Key> XML order of AWS's sample response, the 10 TPS limit on the tagging actions, and that Publish/PublishBatch/Subscribe never load the topic at all — filed as #926. Closes #925. Part of #835.
5 tasks
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 #925.
Part of #835 — the fourth of its eleven rows. Seven remain (Secrets Manager, SSM, and five others);
the ECS scanner halves are also still open there.
Same shape as the ACM, CloudFront and KMS passes: one PR per service that does both the resolution
fix and the tagging row, because the two are the same change seen from two sides — both need one
shared, context-free key builder, and shipping them apart would mean two parsers that can disagree
about which topic an ARN names.
The resolution fix (#925)
snsNameFromARNsplit the identifier on:and returned the last segment, and its callers thenkeyed the load and the store by the caller's own
AccountIDand Region. Three defects compoundedacross ten operations —
DeleteTopic,GetTopicAttributes,SetTopicAttributes,Subscribe,Unsubscribe,ListSubscriptionsByTopic,Publish,PublishBatch,TagResource,UntagResourceand
ListTagsForResource:arn:aws:sns:eu-west-1:999988887777:orderspresented by aus-east-1caller in account111122223333addressed that caller's own topic namedorders.UntagResourceis thedamaging direction and answered
200while stripping its tags;Publishpublished to the wrongtopic and
DeleteTopicdeleted it.arn:aws:sns:{region}:{account}:{topic}:{sub-id}, so its last segment is thesubscription's own identifier — returned as a topic name.
arn:aws:sns, abare name, a URL — became a topic name and was looked up rather than refused.
The replacement,
snsParseTopicARNin the newemulator/sns_tags.go, takes no*RequestContext,which is what makes "the account and Region come from the ARN" structural rather than something ten
call sites have to remember — the arrangement #826 established for SQS and DynamoDB, #845 carried
through the tagging API's resolver, and #910, #918 and #922 applied to Step Functions, CloudFront and
KMS.
An SNS topic ARN carries no type keyword and no separator before the name — the resource portion
is the name — so the anchored-segment rule of #910 has nothing to anchor on. The discriminator the
shape does offer is the colon: a resource portion containing one names a subscription, not a topic.
A malformed ARN is
InvalidParameter/400, which every one of those operations publishes.Subscribenow mints its subscription ARN under the topic's account and Region rather than thecaller's, so the ARN it hands back addresses the topic it subscribed to.
DeleteTopicremoves theowning Region's name-index entry rather than the caller's.
The tagging row (part of #835)
A topic ARN answered an
InternalServiceExceptionFailedResourcesMapentry fromresolveARN'sdefault arm while SNS's own
TagResourcewrote the tag perfectly well, so a tag was writable throughone API and invisible to the other. Three parts, as with the previous three rows: a resolver arm, a
merge arm and a scanner (
scanSNSTopics, descriptor 23).snsResolveARN, a thin wrapper over the same parser SNS's own operations use — thetwo APIs cannot disagree. It exists at all only because the two callers need different error
shapes.
mergeRecordTagListTagsfor the array-shaped tags member, spelledKey/ValueasAWS's
Tagshape has it — KMS'sTagKey/TagValueremains the one exception, which is why thehelper takes both field names as parameters.
content.
topicis a prefix oftopic_names, whose value is a JSON array of names that a bare-prefix testwould report taggable and a merge would leave looking like a record. Only the topic record stores
tags; the subscription record and both subscription indexes are refused.
Account isolation here is emergent rather than guarded, as ACM's is: the resolver builds an
account- and Region-qualified state key, so a foreign-account ARN builds a key nothing is stored at
and the merge reports the resource absent. Unlike KMS (#922) there is nothing to refuse explicitly —
no cross-account statement appears on any of SNS's three tagging pages, so inventing a prohibition
would be substrate's invention rather than its reading. That is a negative finding, recorded as one.
Two further tagging defects fixed in the same pass:
Tags.member.NandTagKeys.member.N, but AWS's own requestexamples on those same pages wire
Tags.Tag.1.Key,Tags.Tag.1.ValueandTagKeys.TagKey.1.Substrate decoded only the first form, so a caller following the example got
200with nothingwritten or nothing removed. Both spellings are now accepted, because the reference and its example
disagree and a caller may reasonably have followed either.
CreateTopic'sTagsparameter was decoded by nobody, and is now applied at creation.ResourceNotFound/404, which they publish, rather than theplain
NotFoundsubstrate used — the status was right and the code name was one no SDK models. Thetopic operations keep
NotFound, which is what they publish.Deliberately not in scope, and recorded
cross-account subscription is not modeled at all — nothing mints one, and no operation distinguishes
a subscriber's account from a topic's — so moving those three would put the index under an account
the subscriptions substrate does have are not stored in, and
Publishwould silently stopdelivering. The topic record is what an ARN addresses, and it is the record tags live on. Same
argument as the ACM pass.
ListTagsForResourcesample emits<Value>before<Key>and substrate emits<Key>first. XML member order is not significant to any SDK's parser, so no test could assert adifference a caller can act on.
rather than an ARN one.
Publish,PublishBatchandSubscribenever load the topic at all, so they succeed againstone that does not exist where AWS answers
NotFound.Subscribeis the one that writes, leavingan orphan subscription record and two index entries. A different defect from this one — this PR
settles which topic an ARN addresses, that is about whether it has to exist — so it is filed as
SNS: Publish, PublishBatch and Subscribe never load the topic, so an absent topic answers 200 #926 (milestone v0.118.0) rather than folded in here.
Tests
emulator/tagging_sns_test.go, 37 assertions, all throughemulator.StartTestServer(t)and realsigned wire calls per #765 — no
putTest*helper writes state directly. Three sections: theresolution fix (cross-Region, foreign-account, subscription-ARN, seven malformed-ARN subtests, the
three
ResourceNotFoundarms, subscription-ARN minting, and the owning-Region index entry), tagdecoding (both parameter spellings,
CreateTopic, the untagged case), and the #835 row(cross-readability in both directions, exact-set
GetResources, Region scoping, foreign-account andsubscription-ARN refusals) plus a determinism pair.
Proved load-bearing rather than assumed so: the file was applied alone to a detached worktree at
origin/main— legal because it ispackage emulator_testand touches no unexported symbol — where31 of the 37 subtests fail. The six that pass on both are understood: the documented-spelling
subtest already worked, the Region-scoping scanner test was vacuously true with no scanner, and the
two tagging-API refusals reached the right outcome via
resolveARN's default arm rather than via ansnsarm.TestTaggingSNS_GetResourcesReportsTheTopicAndNothingElseis deliberately an exact-set match overtwo topics rather than a membership check, because that is the only form that catches a scanner using
a bare
topicprefix and picking uptopic_names:{account}/{region}— the colon-terminated-prefixrule has no wire-reachable ARN to test it directly.
Verification
The nine-command gate, all clean:
gofmt -l .,go build ./...,go vet ./...— cleangolangci-lint run ./...—0 issues.make testandGOTOOLCHAIN=go1.26.6 make test— passGOTOOLCHAIN=go1.26.6 make coverage— 84.1% emulator / 83.7% total, against a 84.1% / 83.6%baseline
make docs-reference docs-reference-check docs-versions authz-reference-check— cleannpm --prefix docs run build— cleango vet -C test/e2e ./... && go test -C test/e2e ./...— passProvenance
Every shape, error code and parameter spelling above is from AWS's
API_TagResource,API_UntagResource,API_ListTagsForResource,API_Publish,API_SubscribeandAPI_GetTopicAttributespages, the SNS tagging developer-guide page, and the Resource Groups TaggingAPI welcome page. Two things are substrate's reading, stated as such: the message text of
InvalidParameter(the reference publishes codes, not messages), and the colon-as-discriminator rule,which follows from the two ARN shapes rather than from any published sentence. The absence of a
cross-account prohibition is a negative finding — the pages were searched for one and it is not
there.