Repository navigation
fix(secretsmanager): a SecretId resolves to the secret its own ARN names, and the tagging API reaches a secret (#928) - #931
Merged
Conversation
…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).
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 #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
resolveSecretIDsplit an identifier on:and returned the last segment, and every one of theten operations taking a
SecretIdthen keyed its load and its store by the caller's own account andRegion. Four defects compounded:
arn:aws:secretsmanager:eu-west-1:999988887777:secret:db-password, presented by aus-east-1caller in
111122223333, addressed that caller's owndb-password.UntagResourceis thedamaging direction and answered
200while stripping its tags;GetSecretValueread its value andDeleteSecretdeleted 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.
…:{account}:other:foonamed a secret calledfoo.Unlike SNS this shape does have a segment to anchor on — the literal
secret— and it is matchedas 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
secretpolicyand any keyword AWS adds later are refused.last segment as a secret name.
was looked up as one.
Defect 4 is why this row is not the previous five repeated. AWS documents
SecretIdas "The ARNor 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:
smParseSecretARNtakes no account,Region or
*RequestContextas parameters at all, so the ARN path cannot reach for the caller's, andonly the name path is given them. Anything beginning
arn:that does not parse isInvalidParameterException/400 — a caller who wrote an ARN prefix meant an ARN, and a silent namelookup turns a typo into a
200against the wrong resource.The name is the whole remainder after the keyword, so a hierarchical
prod/db/passwordround-tripsthrough its own ARN where taking the last component would truncate it to
password.DeleteSecrethad the same defect in its index and is fixed with the rest: it removed the name fromthe 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
resolveARNarm, amergeResourceTagsarm behind a kind guard, and ascanner 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
ResourceARNListand aname 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 aListTagsForResource— Secrets Manager publishes no such operation. The one substrate answers is anoperation 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
mergeRecordTagListTagswithKey/Value— KMS'sTagKey/TagValueremains theone exception, which is why the helper takes both field names as parameters. Both arms and
CreateSecretre-emit sorted by key per #862. This is the row where the map-range ordering claimactually held: Secrets Manager's
TagResourcebuilds its merged list by ranging a Go map. The SNSpass 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 —
secretis aprefix of both
secret_namesandsecret_version. Four of five have collided, so this is now thedefault 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 ownwarning — "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.mdrather than left silent.Tests
emulator/tagging_secretsmanager_test.go, 24 tests and subtest groups, all throughemulator.StartTestServerand real signed wire calls — noputTest*helper, per #765, since a helperthat writes state directly cannot prove cross-readability.
Proven load-bearing: copied onto
origin/mainin a detached worktree, 22 of them fail, includingevery malformed-ARN subtest, the cross-Region untag, the foreign-account arms, the hierarchical name,
the
DeleteSecretindex, and all six #835 assertions. The ones that pass onmainare the deliberateregression guards — a bare name still resolving in the caller's account, a bare name still scoped to
the caller's Region,
TagResourceappending,UntagResourceidempotent, and the two arms thatalready refused via
resolveARN's default.Three assertions worth naming:
GetResourcesis asserted as an exact set, not a membership check. That is the only form thatcatches a scanner using a bare
secretprefix, since neithersecret_names:norsecret_version:has a wire-reachable ARN that could test the colon-terminated rule directly.
Tagsmember is asserted on raw bytes. A decoded struct cannot tell an absent memberfrom a null one, which is how v0.115.0's boundary defect got past a test written to catch it.
two Regions could match on a tag by coincidence of the fixture; they cannot match on their values.
Also filed rather than folded in
ListTagsForResource, an operation the Secrets Manager API does notpublish. Verified against its 23-operation list. An emulator answering an operation AWS refuses is
as wrong as one refusing an operation AWS answers, and the second is at least visible in a test.
ResourceNotFoundExceptionis answered at 404 where AWS publishes 400, at allten operations through one helper. Same class as ACM tagging: ResourceNotFoundException is published at 400, not 404, and InvalidArnException is unmodelled #921 (ACM) and fix(kms): NotFoundException is HTTP 400, and InvalidRequest is not a KMS code #923 (KMS), both filed rather than
folded into their row for the same reason: correcting which resource an identifier names is a
different change from correcting what status a refusal carries.
DescribeSecret's otherunconditionally-emitted members ride along there;
Tagswas fixed here because it is the memberthis row is asserted through.
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 e2esuite all pass.