Skip to content

fix(sns): a TopicArn resolves to the topic its own ARN names, and the tagging API reaches an SNS topic (#925) - #927

Merged
scttfrdmn merged 1 commit into
mainfrom
fix/sns-arn-resolution
Sep 16, 2026
Merged

scttfrdmn merged 1 commit into
mainfrom
fix/sns-arn-resolution

Conversation

@scttfrdmn

Copy link
Copy Markdown
Owner

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)

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 — DeleteTopic, GetTopicAttributes, SetTopicAttributes, Subscribe,
Unsubscribe, ListSubscriptionsByTopic, Publish, PublishBatch, TagResource, UntagResource
and ListTagsForResource:

  1. arn:aws:sns:eu-west-1:999988887777:orders presented by a us-east-1 caller in account
    111122223333 addressed that caller's own topic named orders. UntagResource is the
    damaging direction and answered 200 while stripping its tags; Publish published to the wrong
    topic and DeleteTopic deleted it.
  2. A subscription ARN is arn:aws:sns:{region}:{account}:{topic}:{sub-id}, so its last segment is the
    subscription's own identifier — returned as a topic name.
  3. The length guard fell through to returning its argument, so any string at all — arn:aws:sns, a
    bare name, a URL — became a topic name and was looked up rather than refused.

The replacement, snsParseTopicARN in the new emulator/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.

Subscribe now mints its subscription ARN under the topic's account and Region rather than the
caller's, so the ARN it hands back addresses the topic it subscribed to. DeleteTopic removes the
owning Region's name-index entry rather than the caller's.

The tagging row (part of #835)

A topic ARN answered an InternalServiceException FailedResourcesMap entry from resolveARN's
default arm while SNS's own TagResource wrote the tag perfectly well, so a tag was writable through
one 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).

  • The resolver is snsResolveARN, a thin wrapper over the same parser SNS's own operations use — the
    two APIs cannot disagree. It exists at all only because the two callers need different error
    shapes.
  • The merge reuses mergeRecordTagListTags for the array-shaped tags member, spelled Key/Value as
    AWS's Tag shape has it — KMS's TagKey/TagValue remains the one exception, which is why the
    helper takes both field names as parameters.
  • Both arms re-emit the list sorted by key, per tagging: the four merge helpers store a resource's tags in Go map order, so one state hashes two ways #862, so the two APIs agree on order as well as on
    content.
  • The taggability guard tests a colon-terminated prefix, the fourth namespace to need one:
    topic is a prefix of topic_names, whose value is a JSON array of names that a bare-prefix test
    would 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:

  • AWS's reference names the members Tags.member.N and TagKeys.member.N, but AWS's own request
    examples on those same pages wire Tags.Tag.1.Key, Tags.Tag.1.Value and TagKeys.TagKey.1
    .
    Substrate decoded only the first form, so a caller following the example got 200 with nothing
    written or nothing removed. Both spellings are now accepted, because the reference and its example
    disagree and a caller may reasonably have followed either.
  • CreateTopic's Tags parameter was decoded by nobody, and is now applied at creation.
  • 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. The
    topic operations keep NotFound, which is what they publish.

Deliberately not in scope, and recorded

  • The subscription record and both subscription indexes stay keyed by the calling account. A
    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 Publish would silently stop
    delivering. The topic record is what an ARN addresses, and it is the record tags live on. Same
    argument as the ACM pass.
  • SNS's published ListTagsForResource sample 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 a
    difference a caller can act on.
  • The 10 TPS limit on the three tagging actions is not modeled — a seedable-throttle question
    rather than an ARN one.
  • Publish, PublishBatch and Subscribe never load the topic at all, so they succeed against
    one that does not exist where AWS answers NotFound. Subscribe is the one that writes, leaving
    an 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 through emulator.StartTestServer(t) and real
signed wire calls per #765 — no putTest* helper writes state directly. Three sections: the
resolution fix (cross-Region, foreign-account, subscription-ARN, seven malformed-ARN subtests, the
three ResourceNotFound arms, subscription-ARN minting, and the owning-Region index entry), tag
decoding (both parameter spellings, CreateTopic, the untagged case), and the #835 row
(cross-readability in both directions, exact-set GetResources, Region scoping, foreign-account and
subscription-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 is package emulator_test and touches no unexported symbol — where
31 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 an
sns arm.

TestTaggingSNS_GetResourcesReportsTheTopicAndNothingElse is deliberately an exact-set match over
two topics rather than a membership check, because that is the only form that catches a scanner using
a bare topic prefix and picking up topic_names:{account}/{region} — the colon-terminated-prefix
rule has no wire-reachable ARN to test it directly.

Verification

The nine-command gate, all clean:

  • gofmt -l ., go build ./..., go vet ./... — clean
  • golangci-lint run ./... — 0 issues.
  • make test and GOTOOLCHAIN=go1.26.6 make test — pass
  • GOTOOLCHAIN=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 — clean
  • npm --prefix docs run build — clean
  • go vet -C test/e2e ./... && go test -C test/e2e ./... — pass

Provenance

Every shape, error code and parameter spelling above is from AWS's API_TagResource,
API_UntagResource, API_ListTagsForResource, API_Publish, API_Subscribe and
API_GetTopicAttributes pages, the SNS tagging developer-guide page, and the Resource Groups Tagging
API 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.

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.
@scttfrdmn scttfrdmn added this to the v0.117.0 milestone Sep 16, 2026
@scttfrdmn
scttfrdmn merged commit ebea384 into main Sep 16, 2026
16 checks passed
@scttfrdmn
scttfrdmn deleted the fix/sns-arn-resolution branch September 16, 2026 02:09
@codecov

codecov Bot commented Sep 16, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 92.52874% with 13 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
emulator/sns_plugin.go 91.11% 8 Missing ⚠️
emulator/tagging_plugin.go 85.71% 5 Missing ⚠️

📢 Thoughts on this report? Let us know!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

fix(sns): a topic ARN resolves to the caller's own account, and a subscription ARN resolves to its own UUID

1 participant