Repository navigation
fix(ssm): a tag call resolves to the resource type it names, and the tagging API reaches a parameter (#932) - #934
Merged
Conversation
All three of Systems Manager's tag operations declared `ResourceType string`
and then went straight to the parameter loader, so every SSM tag call was
answered as though it named a Parameter Store parameter. Four defects:
1. A type other than Parameter reached a same-named parameter, and
ListTagsForResource read the tag back, confirming the wrong resource
had been tagged.
2. A value outside AWS's ten-value enum was accepted, making
InvalidResourceType unreachable; an absent ResourceType was accepted.
3. Anything without a leading "/" was normalized into a name, so an ARN
became the *name* "/arn:aws:ssm:...".
4. An untagged parameter's TagList rendered as null, not [].
The resource-type counterpart of the account confusion #826 established and
#910/#918/#922/#925/#928 carried through. #826's own rule is inapplicable to
this half, because an SSM ResourceId is a name and carries no account; the
tagging API's half does take an ARN, and its parser takes no account, Region
or request context, so the rule is structural there.
The two refusals are distinct on purpose: outside the enum is
InvalidResourceType ("The resource type isn't valid"), inside it but not
modelled is InvalidResourceId (the type is real, the identifier names
nothing — #827's honest-empty behaviour). The leading-slash tolerance is kept
and recorded as substrate's reading: AWS documents it only for OpsMetadata,
but PutParameter normalizes Name, so a caller who created "MyParam" must be
able to tag it. Tag order is sorted by key at every arm per #862, re-verified
against the tree rather than inherited.
Also delivers the sixth of #835's eleven rows: the Resource Groups Tagging
API now reaches a Systems Manager parameter. Same three parts as the five
before it — resolver arm, merge arm behind a colon-terminated kind guard
(the sixth namespace to collide: parameter/parameter_paths), and a scanner
with its descriptor, now twenty-five. The ARN has no separator before the
name, so the first "/"-delimited segment must be exactly "parameter" per
#910 and the name is the remainder; taking the last component would truncate
/db/password to password.
InvalidResourceId's 404 is left alone and filed as #933, per #921/#923/#930.
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
5 tasks
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 #932.
The sixth row of #835's eleven, and the first carrying an owning-service resolution fix of its own that
is about resource types rather than about accounts.
What was wrong
All three of Systems Manager's tag operations —
AddTagsToResource,RemoveTagsFromResource,ListTagsForResource— declaredResourceType stringand then went straight to the parameter loader.Four defects compounded:
Parameterreached a same-named parameter. AWS publishesResourceTypeasRequired: Yesover a ten-value enum, so{"ResourceType": "Document", "ResourceId": "MyRunbook"}tagged the parameter named
/MyRunbook— andListTagsForResourcewith the same pair read the tagback, so the round trip confirmed that the wrong resource had been tagged.
InvalidResourceType— published at all threeoperations — unreachable, and an absent
ResourceTypewas accepted as though it had saidParameter./became one, soarn:aws:ssm:us-east-1:123456789012:parameter/db/passwordwas looked up as the name/arn:aws:ssm:…. Refused either way, but for the wrong reason and after a normalization that makesthe message nonsense — the fall-through fix(secretsmanager): a SecretId ARN resolves to the secret its own ARN names, and the tagging API reaches a secret #928 removed from Secrets Manager's
SecretId.ListTagsForResourcerendered an untagged parameter'sTagListasnull, not as the emptyarray AWS publishes.
Separately, the Resource Groups Tagging API could not reach a parameter at all: an ARN answered an
InternalServiceExceptionFailedResourcesMapentry fromresolveARN's default arm while SSM's ownAddTagsToResourcewrote the tag, andGetResourcesreported no parameters.Why this row is different
This is the resource-type counterpart of the account confusion #826 established for SQS and
DynamoDB and #910, #918, #922, #925 and #928 carried through Step Functions, CloudFront, KMS, SNS and
Secrets Manager: an identifier must resolve to the thing it names, and the one thing it must never
resolve to is a same-named resource of a different kind.
But #826's own rule — the account comes from the ARN — is inapplicable to half of this row. AWS is
explicit that "for the
DocumentandParametervalues, use the name of the resource", so an SSMResourceIdcarries neither account nor Region and the caller's own are the only possible source forthem. This is the first of #835's rows where the owning service's tag operations take no ARN at all.
The tagging API's half does take an ARN, and
ssmParseParameterARNaccordingly takes no account,Region or
*RequestContext, so the rule is structural there rather than remembered. Both arms meet atone state-key builder, so neither API can address a parameter the other would not.
Decisions, and their provenance
Two distinct refusals, because they tell a caller two different things. A
ResourceTypeoutsidethe enum is
InvalidResourceType, whose own AWS description — "The resource type isn't valid" — is thetrue statement about it, and the message lists the ten valid values because a caller who sent
parameterforParameterhas no other way to see the difference. AResourceTypeAWS publishes butsubstrate models no taggable resource for is
InvalidResourceId: the type is real, and it is theidentifier that names nothing — #827's honest-empty behaviour. Answering one code for both would tell a
caller who mistyped
Parameterthat their parameter is missing.An absent
ResourceTypeisValidationException, and that is substrate's reading. AWS's ownserver-side code cannot be verified: the member is
Required: Yesand every SDK refuses the call beforeit reaches the service.
The leading-slash tolerance is kept, as substrate's reading rather than AWS's. AWS documents that
tolerance explicitly only for
OpsMetadata, whoseResourceIDmay be given as eitheraws/ssm/MyGroup/appmanageror/aws/ssm/MyGroup/appmanager. For aParameterit is required bysubstrate's own behaviour, since
PutParameternormalizesNameto a leading/— so a caller whocreated
MyParamwould otherwise be unable to tag it. Asserted from both directions.The ARN has no separator before the name, because the name carries its own:
parameter/db/passwordis the whole resource portion. So the first
/-delimited segment must be exactlyparameter— matchedas a whole segment per #910, since the same namespace addresses
document/,servicesetting/,opsmetadata/,maintenancewindow/,patchbaseline/andmanaged-instance/— and the name is theremainder with the
/restored. Taking the last component would truncate/db/passwordtopassword,which a test asserts against a decoy parameter planted at that name. The state key consequently holds a
doubled separator,
parameter:{account}/{region}//db/password; that is the shape already on disk and isleft alone, since changing it would orphan every stored parameter.
Sixth colon-terminated kind guard.
parameteris a prefix ofparameter_paths, whose value is aJSON array of names. Five of the six namespaces reached so far have collided, so the guard is now
unambiguously the default for a new row rather than a per-service discovery.
Tag order sorted by key at every arm, per #862 — re-verified against the tree rather than inherited,
as the #835 comment promised. It held:
AddTagsToResourcebuilt its merged list by ranging a Go map,and
PutParameterstored the caller's order, so a parameter tagged at creation and one taggedafterwards reported their tags differently.
Isolation is emergent rather than guarded, as ACM's, SNS's and Secrets Manager's are: the state key
carries the ARN's own account and Region, so a foreign-account or foreign-Region ARN builds a key
nothing is stored at.
Left alone deliberately
InvalidResourceIdstill answers HTTP 404 where AWS publishes 400 — filed as fix(ssm): InvalidResourceId is a 400, not a 404 #933, on thereasoning ACM tagging: ResourceNotFoundException is published at 400, not 404, and InvalidArnException is unmodelled #921 (ACM), fix(kms): NotFoundException is HTTP 400, and InvalidRequest is not a KMS code #923 (KMS) and fix(secretsmanager): ResourceNotFoundException is 400, not 404, and DescribeSecret emits members AWS omits #930 (Secrets Manager) established: correcting which resource
an identifier names is a different change from correcting what status a refusal carries, and a wire
status is a compatibility surface a consumer may already assert. All three operations now route
through one helper, so that correction is a single line.
for Automations).
LabelParameterVersionremains a stub that always reportsParameterVersion: 1.Tests
emulator/tagging_ssm_test.go— 21 top-level tests, 47 test/subtest groups, all throughStartTestServerand real signed wire calls. #765's cross-readability criterion is asserted throughListTagsForResource, an operation Systems Manager genuinely publishes — unlike the one SecretsManager's row had to work around (#929).
Load-bearing proof: copied onto
origin/mainin a detached worktree, 14 of the 21 top-level testsand 29 test/subtest groups fail, including all nine resource-type subtests, all four enum subtests, the
absent-
ResourceTyperefusal, the raw-bytes"TagList":[]assertion, all three determinism subtests andeight of the ten tagging-API assertions. The 7 that pass are deliberate guards and baselines, and each
one's doc comment says so — an ARN as a
ResourceIdwas refused before too (by a nonsense path), and aforeign-account ARN was refused before because every SSM ARN was; the point of that assertion is that
adding the arm did not open the reach.
Verification
The nine-command gate, all green:
Coverage 84.2% emulator / 83.7% total (baseline 84.1% / 83.7%).
Part of #835 — the sixth of eleven rows; five remain (a Step Functions activity, an RDS DB cluster and
DB subnet group, and the two ECS types' scanner halves).