Skip to content

fix(rds): tag a DB cluster and subnet group through the ARN RDS reports (#835) - #908

Merged
scttfrdmn merged 3 commits into
mainfrom
fix/rds-tagging-reachability
Sep 15, 2026
Merged

scttfrdmn merged 3 commits into
mainfrom
fix/rds-tagging-reachability

Conversation

@scttfrdmn

Copy link
Copy Markdown
Owner

Two of #835's nine remaining rows: RDS DB cluster and DB subnet group. No closing keyword — seven rows remain.

The reachability defect

CreateDBCluster and CreateDBSubnetGroup report cluster: and subgrp: ARNs. rdsResolveARN recognized db: and snapshot: only, so RDS's own AddTagsToResource, RemoveTagsFromResource and ListTagsForResource refused an ARN substrate had just handed the caller — "unsupported RDS ARN resource type" — and the Resource Groups Tagging API's rds arm could not reach either resource. That is #765's rule broken in the plainest way: a value substrate reports has to be usable against the API that reported it.

Both now resolve through one builder, shared by RDS's three tag operations and the tagging API's arm. That is the arrangement ECS has had since #826, adopted here for the same reason: two derivations of one key drift, and where they drift a tag is written to a record the other side does not read. rdsResolveARN takes no *RequestContext at all, so account and Region come from the ARN structurally rather than by discipline.

The truncation defect, which is why this is Fixed and not Added

The tagging API's rds arm merged a tag like this:

var inst RDSDBInstance
if err := json.Unmarshal(raw, &inst); err != nil { … }
inst.Tags = mergeStringMap(inst.Tags, addTags, removeKeys)
updated, _ := json.Marshal(inst)
return state.Put(goCtx, ns, key, updated)

— whatever the key named. Round-tripping a cluster through an instance-shaped struct loses every member an instance does not carry under the same name, so after one TagResources call DescribeDBClusters reported no Endpoint, no ReaderEndpoint, no MasterUsername and no Port. Nothing refused, and the tag itself was correct — which is exactly why a test asserting on the tag cannot see it. This is data loss, not a missing feature, and it becomes reachable the instant a cluster resolves, so it lands in the same PR rather than after it.

The arm now decodes into map[string]json.RawMessage, edits the tags member, and re-marshals, so no other member is touched. That is ecsMergeRecordTags' pattern, generalized into a shared mergeRecordStringMapTags that both services use — PR B for the Step Functions half will use the same helper for statesNamespace, which has the identical defect against an activity.

Two details of the helper:

  • The member name is a parameter, because RDS spells it Tags and ECS spells it tags. A hardcoded name would add a second member and leave the real one untouched: a tag call that answers 200 and stores nothing.
  • A member differing only in case is an error, not something written alongside. Per applyTagsToResource' standing rule, every way of not writing a tag has to fail.

A kind guard (rdsKeyIsTaggable) sits in front of the merge, because the rds namespace also holds a parameter group, a container handle and the plugin's own index keys — keys no ARN addresses and that store no tags. The guard and the raw-JSON merge fix two different failures and neither substitutes for the other; the arm's comment names both separately.

Three smaller things on the same path

  • A missing resource named the wrong kind. Every kind answered DBInstanceNotFound, which tells a caller polling for a cluster that it asked about the wrong sort of thing — and a consumer branching on the code to decide whether to keep waiting branches wrong. Now DBClusterNotFoundFault, DBSnapshotNotFound and DBSubnetGroupNotFoundFault respectively, at 404.
  • TagList was in Go map order. Built by ranging a map, so two identical calls could answer differently and a recorded run could not replay. Sorted by key.
  • loadTagsByARN discarded a JSON unmarshal error and returned (nil, nil), so a record substrate could not read answered 200 with an empty TagList — indistinguishable from an untagged resource, and the same accepted-and-ignored shape The Resource Groups Tagging API cannot write tags for eleven types: mergeResourceTags has no arm #835 exists to remove. It reports the error.

GetResources gained scanRDSClusters and scanRDSSubnetGroups, 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.

Recorded rather than acted on

An automated snapshot needs no arm. AWS writes its ARN snapshot:rds:{name} and the extra segment belongs to the identifier — such a snapshot really is named rds:mydb-2019-07-22-07-23 — so SplitN(arn, ":", 7) already keeps the remainder intact and addresses the right identifier. The prior analysis that called this a mis-parse was wrong; the finding is recorded in rds_tags.go' preamble and asserted by a test in both directions (the automated form resolves, and the manual form of the same trailing name is a different resource).

The create paths needed nothing: createDBCluster and createDBSubnetGroup already store Tags and their own ARN member.

Not fixed, noted: matchesResourceType' bare HasPrefix means the rds:cluster resource-type filter would also match a cluster-pg: or cluster-snapshot: ARN. It is unreachable today because the resolver refuses both, so nothing can be stored under one — but the filter is wrong independently of that and deserves its own issue.

Provenance

AWS's, verified by fetch against the API reference rather than recollection:

  • The four resource-type segments, from Constructing an ARN for Amazon RDS: db:{name}, cluster:{name}, snapshot:{name}, subgrp:{name} — and cluster-pg / cluster-snapshot as distinct resource types rather than prefixes of cluster. Both are refused, as are pg and es.
  • The automated-snapshot form snapshot:rds:{name}, from the same table.
  • Three of the four 404 codes, verbatim from API_AddTagsToResource and API_ListTagsForResource' own error lists: DBInstanceNotFound ("DBInstanceIdentifier doesn't refer to an existing DB instance."), DBClusterNotFoundFault, DBSnapshotNotFound — all 404.
  • DBSubnetGroupNotFoundFault/404 and its message, from API_DescribeDBSubnetGroups. (Checked and not found on API_ModifyDBInstance, which an earlier draft of the doc comment wrongly cited.)

Substrate's reading, stated as such in the code and in docs/services.md:

  • Answering DBSubnetGroupNotFoundFault at a tagging operation. A DB subnet group is a taggable type in AWS's ARN table, but neither tagging operation's published error list names a subnet-group fault. The code and status are AWS's; only the decision to answer it here is substrate's. The alternative — keeping DBInstanceNotFound for a subnet group — is wrong under any reading.
  • Sorting TagList by key. AWS documents no order for it, and its own sample response renders owner before environment. The justification is the replay promise, per tagging: the four merge helpers store a resource's tags in Go map order, so one state hashes two ways #862.
  • Refusing an identifier containing / or : for the three non-snapshot types. RDS accepts neither in a name; 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.

Tests

emulator/rds_tags_test.go, ten top-level tests, all over the wire through StartTestServer. Every resource is created through its owning operation and every ARN taken out of the response rather than composed — a composed ARN would let the test agree with a resolver that disagreed with what CreateDBCluster reports, which is the divergence being fixed. No putTest* helper is touched (#765's standing rule).

Coverage: 84.0% emulator / 83.5% total, above the 83.9% / 83.4% baseline.

Mutation test, in two stages (by cp, never git stash)

1. Full revert — rds_tags.go removed, rds_plugin.go and tagging_plugin.go restored from main: all 10 tests fail, each for the right reason. Sampled from the output:

error code "InvalidParameterValue", want DBClusterNotFoundFault
  (Message: unsupported RDS ARN resource type: "cluster")
error code "DBInstanceNotFound", want DBSnapshotNotFound
arn:…:db:orders/replica: error code "DBInstanceNotFound", want InvalidParameterValue
TagResources arn:…:cluster:billing-cluster: {ErrorCode:InternalServiceException …
  the resource type in the request is not supported by the Resource Groups Tagging API}

2. Narrow revert of the merge arm only — new resolver and scanners kept, the RDSDBInstance decode put back. This is the stage that proves the truncation assertions have teeth, since under a full revert those tests fail earlier, at the refusal:

  • ATaggedSubnetGroupKeepsItsOwnMembers — fails on the read-back: the subnet group comes back missing its members, silently. This is the defect exactly as described.
  • ATaggedClusterKeepsItsOwnMembers — fails harder than expected: a cluster record does not even decode into RDSDBInstance, so TagResources answers InternalServiceException/500. Worth recording, since it means a cluster's truncation would have surfaced as a 500 rather than as silent loss — the subnet group is the silent one.

What is asserted

  • Cross-readability both directions for instance, cluster and subnet group: tag through RDS → read through RDS; tag through the tagging API → read through RDS ListTagsForResource; tag through RDS → read through GetResources; and UntagResources → gone. A removal aimed at a resource the resolver could not key is the more damaging half, so it is never the untested one.
  • Non-truncation for cluster and subnet group, asserted on Endpoint/ReaderEndpoint/MasterUsername/Port and on VpcId/Description/Status — the other members, not the tag. Each test first asserts the create path stored those members, so it cannot pass vacuously against an empty record.
  • Per-kind 404 across all three tag operations for all four kinds, because the read side and the write side resolved through separate paths and so could disagree about the code.
  • Refusal of pg:, cluster-pg:, cluster-snapshot:, es:, an empty identifier, an identifier with /, a too-short ARN, and another service's ARN.
  • The automated-snapshot identifier surviving intact, and the manual form of the same trailing name resolving to a different resource.
  • TagList key order, asserted twice — one call cannot distinguish a sorted order from a map order that happened to come out sorted.
  • The SQS state keys disagree: the tagging API and the authorizer address queue:<name>, the plugin writes queue:<account>/<name> #826 foreign-account case: a RemoveTagsFromResource naming another account's same-named cluster is refused and the caller's own cluster still carries its tag.
  • GetResources reporting all three types.

Compatibility

A cluster: or subgrp: ARN that previously answered InvalidParameterValue/400 at RDS's three tag operations, or InternalServiceException/500 in a FailedResourcesMap, now succeeds. A missing DB cluster, snapshot or subnet group answers its own 404 code where it previously answered DBInstanceNotFound — a consumer branching on that code needs updating, and this is the point of the change. ListTagsForResource now returns TagList sorted by key, so an assertion that happened to pass on Go's map order may fail. GetResources reports DB clusters and DB subnet groups it previously omitted.

Verification

The full gate, all green:

gofmt -l . && go build ./... && go vet ./...        ✓
golangci-lint run ./...                             ✓ (0 issues)
make test                                           ✓
GOTOOLCHAIN=go1.26.6 make test                      ✓
GOTOOLCHAIN=go1.26.6 make coverage                  ✓ 84.0% / 83.5%
make docs-reference docs-reference-check docs-versions authz-reference-check   ✓
npm --prefix docs run build                         ✓
go vet -C test/e2e ./... && go test -C test/e2e ./...   ✓

docs/services.md gains the RDS ARN table, the per-kind 404 table and the TagList order note, brings the RDS operations table up to date (it listed 8 of 23 operations), and corrects the tagging section's scanner count from sixteen to eighteen. Prose cites #835, never a version.

…ts (#835)

rdsResolveARN recognized `db:` and `snapshot:` only, while CreateDBCluster and
CreateDBSubnetGroup hand callers `cluster:` and `subgrp:` ARNs that substrate's
own three tag operations then refused as an unsupported resource type. So
substrate reported a value its own API would not accept — #765's rule — and the
Resource Groups Tagging API could not reach either resource at all.

Both now resolve, through the one builder RDS's own tag operations and the
tagging API's `rds` arm share, so the two cannot disagree about which record a
tag lands on. Account and Region come from the ARN, never the request context.

The worse half arrived with reachability: the tagging API's `rds` arm decoded
every record into an RDSDBInstance and stored the result back, so tagging a
cluster dropped its endpoint, reader endpoint, master username and port. The arm
now edits the tags member of the raw JSON, through a shared helper the ECS arm's
pattern is generalized into; the member name is a parameter because RDS spells it
`Tags` and ECS `tags`, and a case-differing member is refused rather than written
alongside the real one.

Also: a per-kind 404 instead of DBInstanceNotFound for everything; TagList sorted
by key rather than in Go map order; a discarded unmarshal error in loadTagsByARN
now reported; and GetResources scanners for both new types.

Part of #835 — two of its nine remaining rows.
@codecov

codecov Bot commented Sep 15, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 90.10417% with 19 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
emulator/tagging_plugin.go 80.30% 13 Missing ⚠️
emulator/rds_tags.go 95.23% 6 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.

1 participant