Skip to content

fix(secretsmanager): a SecretId resolves to the secret its own ARN names, and the tagging API reaches a secret (#928) - #931

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

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

Conversation

@scttfrdmn

Copy link
Copy Markdown
Owner

Closes #928. Part of #835 — the fifth of its eleven rows; six remain, plus the two ECS scanner halves.

One PR for both halves, for the reason the previous four rows established: the resolution fix and the
tagging row are the same change seen from two sides. Both need one context-free key builder, and
shipping them apart would leave two parsers that can disagree about which secret an ARN names.

The resolution fix

resolveSecretID split an identifier on : and returned the last segment, and every one of the
ten operations taking a SecretId then keyed its load and its store by the caller's own account and
Region. Four defects compounded:

  1. The account and Region came from the caller.
    arn:aws:secretsmanager:eu-west-1:999988887777:secret:db-password, presented by a us-east-1
    caller in 111122223333, addressed that caller's own db-password. UntagResource is the
    damaging direction and answered 200 while stripping its tags; GetSecretValue read its value and
    DeleteSecret deleted it. The rule of SQS state keys disagree: the tagging API and the authorizer address queue:<name>, the plugin writes queue:<account>/<name> #826/tagging: TagResources reports a nonexistent resource as InternalServiceException/500, the code AWS reserves for an unsupported type #845, applied service by service through Step Functions: all three tag operations take the account from the request, not the ARN, so a foreign-account ARN tags the caller's own state machine #910, cloudfront: the three tagging operations take the account from the caller, not the ARN, and match the resource type by substring #918,
    fix(kms): a key ARN resolves to the caller's own account, and an alias ARN resolves to its own name #922 and fix(sns): a topic ARN resolves to the caller's own account, and a subscription ARN resolves to its own UUID #925.
  2. The type keyword was never compared, so …:{account}:other:foo named a secret called foo.
    Unlike SNS this shape does have a segment to anchor on — the literal secret — and it is matched
    as a whole segment per Step Functions: all three tag operations take the account from the request, not the ARN, so a foreign-account ARN tags the caller's own state machine #910, so secretpolicy and any keyword AWS adds later are refused.
  3. The service segment was never compared either, so another service's ARN resolved to its own
    last segment as a secret name.
  4. The length guard fell through to returning its argument, so a malformed ARN became a name and
    was looked up as one.

Defect 4 is why this row is not the previous five repeated. AWS documents SecretId as "The ARN
or name of the secret"
, so a bare name is a valid identifier — and a name carries no account,
which makes the caller's own the correct source for that one case and only that one. Refusing
everything that is not an ARN would have been the easy over-correction.

The two are separated structurally rather than by convention: smParseSecretARN takes no account,
Region or *RequestContext as parameters at all, so the ARN path cannot reach for the caller's, and
only the name path is given them. Anything beginning arn: that does not parse is
InvalidParameterException/400 — a caller who wrote an ARN prefix meant an ARN, and a silent name
lookup turns a typo into a 200 against the wrong resource.

The name is the whole remainder after the keyword, so a hierarchical prod/db/password round-trips
through its own ARN where taking the last component would truncate it to password.

DeleteSecret had the same defect in its index and is fixed with the rest: it removed the name from
the caller's account and Region index while deleting the record the ARN named, so the owning
Region went on listing a secret whose record had just been removed.

The #835 row

The usual three parts — a resolveARN arm, a mergeResourceTags arm behind a kind guard, and a
scanner with its descriptor (now twenty-four) — all going through the same key builder Secrets
Manager's own operations use.

The tagging arm takes an ARN only, with no name fallback: its parameter is ResourceARNList and a
name is not an ARN, so there is nothing there for the caller's own account to supply. Isolation is
emergent rather than guarded, as SNS's and ACM's are — no cross-account prohibition appears on Secrets
Manager's tagging pages, and an account- and Region-qualified key means a foreign-account ARN builds a
key nothing is stored at.

#765's cross-readability criterion is asserted through DescribeSecret, not through a
ListTagsForResource — Secrets Manager publishes no such operation. The one substrate answers is an
operation AWS does not have; that is filed as #929 rather than removed here, so this PR does not mix a
removal into a resolution fix. Nothing in the new test file calls it.

The merge reuses mergeRecordTagListTags with Key/Value — KMS's TagKey/TagValue remains the
one exception, which is why the helper takes both field names as parameters. Both arms and
CreateSecret re-emit sorted by key per #862. This is the row where the map-range ordering claim
actually held
: Secrets Manager's TagResource builds its merged list by ranging a Go map. The SNS
pass corrected the record that it held there; it was re-verified here rather than inherited.

The guard tests a colon-terminated prefix, the fifth namespace to need one — secret is a
prefix of both secret_names and secret_version. Four of five have collided, so this is now the
default for a new row rather than a per-service discovery. The version key is the strongest case for
the guard anywhere in the set: its value is a caller's secret payload and not JSON at all, so a
merge there would corrupt the secret rather than merely write where nothing reads. That is also why
the scanner reports nothing for it — emitting an ARN for the one key in the tree whose value is a
caller's secret would be worse than reporting no secret.

Deliberately not changed, and why it is load-bearing

Substrate mints an ARN with no random suffix, where AWS appends - plus six characters. AWS's own
warning — "Do not end your secret name with a hyphen followed by six characters" — is why that
matters: a name may itself end that way, so trimming the suffix back off cannot be done in general.
Substrate minting none is precisely what makes this row's ARN-to-name derivation exact. Adding one
would make the resolver ambiguous by construction and would change a value CloudFormation records
as a physical ID. Recorded on #928 and in docs/services.md rather than left silent.

Tests

emulator/tagging_secretsmanager_test.go, 24 tests and subtest groups, all through
emulator.StartTestServer and real signed wire calls — no putTest* helper, per #765, since a helper
that writes state directly cannot prove cross-readability.

Proven load-bearing: copied onto origin/main in a detached worktree, 22 of them fail, including
every malformed-ARN subtest, the cross-Region untag, the foreign-account arms, the hierarchical name,
the DeleteSecret index, and all six #835 assertions. The ones that pass on main are the deliberate
regression guards — a bare name still resolving in the caller's account, a bare name still scoped to
the caller's Region, TagResource appending, UntagResource idempotent, and the two arms that
already refused via resolveARN's default.

Three assertions worth naming:

  • GetResources is asserted as an exact set, not a membership check. That is the only form that
    catches a scanner using a bare secret prefix, since neither secret_names: nor secret_version:
    has a wire-reachable ARN that could test the colon-terminated rule directly.
  • The absent Tags member is asserted on raw bytes. A decoded struct cannot tell an absent member
    from a null one, which is how v0.115.0's boundary defect got past a test written to catch it.
  • The cross-Region case asserts the secret's value, not just its tags. Two same-named secrets in
    two Regions could match on a tag by coincidence of the fixture; they cannot match on their values.

Also filed rather than folded in

Verification

Nine-command gate, all green. Coverage 84.1% emulator / 83.7% total — the baseline, unmoved.
make test, GOTOOLCHAIN=go1.26.6 make test, the four docs checks, the docs site build and the e2e
suite all pass.

…mes, and the tagging API reaches a secret (#928)

resolveSecretID split an identifier on ":" and returned the last segment, and every
one of the ten operations taking a SecretId then keyed its load and its store by the
caller's own account and Region. Four defects compounded: a foreign-account or
cross-Region secret ARN addressed the caller's own secret of that name, and
UntagResource answered 200 while stripping its tags.

The type keyword and the service segment were never compared either, and the length
guard fell through to returning its argument, so a malformed ARN became a *name* and
was looked up as one.

Defect four is the one that was not entirely wrong: AWS documents SecretId as "The ARN
or name of the secret", and a name carries no account, which makes the caller's own the
correct source for that one case. The two paths are now separated structurally — the ARN
parser takes no account, Region or *RequestContext as parameters at all — and anything
beginning "arn:" that does not parse is refused rather than looked up as a name.

The tagging row of #835 lands with it, because both halves need one context-free key
builder and shipping them apart would leave two parsers that can disagree about which
secret an ARN names: a resolveARN arm, a mergeResourceTags arm behind a
colon-terminated kind guard (secret: is a prefix of both secret_names: and
secret_version:), and a scanner with its descriptor. Cross-readability is asserted
through DescribeSecret, since Secrets Manager publishes no ListTagsForResource.

Also fixed: DeleteSecret removed the caller's index entry rather than the owning
account and Region's; CreateSecret and TagResource now store tags key-ordered per #862;
DescribeSecret omits Tags when a secret has none.

Filed rather than folded in: #929 (substrate implements ListTagsForResource, an
operation AWS does not have) and #930 (ResourceNotFoundException is 400, not 404, and
DescribeSecret emits other members AWS omits).
@scttfrdmn scttfrdmn added this to the v0.117.0 milestone Sep 16, 2026
@scttfrdmn
scttfrdmn merged commit 6bcf0ee into main Sep 16, 2026
16 checks passed
@scttfrdmn
scttfrdmn deleted the fix/secretsmanager-arn-resolution branch September 16, 2026 02:36
@codecov

codecov Bot commented Sep 16, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 85.51724% with 21 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
emulator/secretsmanager_plugin.go 79.10% 14 Missing ⚠️
emulator/tagging_plugin.go 82.85% 5 Missing and 1 partial ⚠️
emulator/secretsmanager_tags.go 97.67% 1 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(secretsmanager): a SecretId ARN resolves to the secret its own ARN names, and the tagging API reaches a secret

1 participant