Skip to content

fix(ssm): a tag call resolves to the resource type it names, and the tagging API reaches a parameter (part of #835) #932

Closed

Description

@scttfrdmn

Summary

SSM's three tag operations decode ResourceType and never read it, so every SSM tag call is
answered as though it named a Parameter Store parameter
— whatever type it actually named. And the
Resource Groups Tagging API has no ssm arm at all, so a parameter is invisible to GetResources
and untaggable through TagResources (the eighth of #835's eleven rows).

Verified at 6bcf0ee (v0.116.0) against the tree, and against
API_AddTagsToResource,
API_RemoveTagsFromResource
and
API_ListTagsForResource.

1. ResourceType is decoded and never read, at all three operations

addTagsToResource (emulator/ssm_plugin.go:640-680), removeTagsFromResource (:682-721) and
listTagsForResource (:723-748) each declare

ResourceType string `json:"ResourceType"`

and then never mention input.ResourceType again. All three go straight to
p.loadParam(goCtx, ctx.AccountID, ctx.Region, name).

AWS publishes ResourceType as Required: Yes with a ten-value enum:

Valid Values: Document | ManagedInstance | MaintenanceWindow | Parameter | PatchBaseline | OpsItem | OpsMetadata | Automation | Association | CloudConnector

Consequences, in the order they matter:

Substrate models exactly one taggable SSM resource type — the parameter (ssm_plugin.go:87,
ssm_types.go). It models no documents, maintenance windows, patch baselines, OpsItems, OpsMetadata
objects, automations, associations, managed instances or cloud connectors. That is fine; what is not
fine is answering as though a request naming one of them had named a parameter.

2. A full ARN passed as a Parameter ResourceId is silently turned into a name

AWS is explicit about which form each type takes:

For the Document and Parameter values, use the name of the resource. If you're tagging a shared
document, you must use the full ARN of the document.

So for a parameter the identifier is the name, not the ARN — this is the first of #835's rows
where the owning service's own tag operations do not take an ARN at all. Substrate's normalization
(ssm_plugin.go:650-652) prepends / to anything without one, so
arn:aws:ssm:us-east-1:123456789012:parameter/db/password becomes the name
/arn:aws:ssm:us-east-1:123456789012:parameter/db/password and is looked up as one. It is refused,
but for the wrong reason and after a normalization that makes the message nonsense. Secrets Manager's
resolver settled this shape in #928: anything beginning arn: is a caller who meant an ARN, and
guessing is how a typo becomes a 200 against the wrong resource.

3. addTagsToResource builds its merged tag list by ranging a Go map

ssm_plugin.go:663-674 merges through map[string]string and then

for k, v := range tagMap {
    newTags = append(newTags, SSMTag{Key: k, Value: v})
}

with no sort. Two identical AddTagsToResource calls in one run can store — and
ListTagsForResource can therefore report — a different order. This is exactly the defect #862
fixed in all four tagging-API merge helpers, still live in SSM's own path. sortTagsByKey
(tagging_plugin.go:1980) is the helper. putParameter (:194) stores input.Tags unsorted too,
so a parameter tagged at creation and one tagged afterwards report their tags in different orders.

4. ListTagsForResource answers "TagList": null for an untagged parameter

SSMParameter.Tags is json:"Tags,omitempty", so it is nil on an untagged parameter, and
ssm_plugin.go:744-746 renders it directly. AWS's TagList is an array; null is not one, and a
strict client decoding a list member from null is entitled to fail.

5. The Resource Groups Tagging API has no ssm arm (part of #835)

Three pieces are missing, the same three every row of #835 needs:

  • No case "ssm": in TaggingPlugin.resolveARN (tagging_plugin.go:1160-1451), so an ARN falls
    to the default arm and TagResources reports it unsupported.
  • No case ssmNamespace: in mergeResourceTags (:1481), so nothing could write the record even
    if the ARN resolved.
  • No scanner, so GetResources never reports a parameter. The descriptor list (:241-264) holds
    twenty-four; a parameter would be the twenty-fifth.

The colon-terminated taggability guard applies again, and this is the sixth namespace to need it:
ssm_plugin.go:87 writes "parameter:" + … and :91 writes "parameter_paths:" + …, whose value is
a JSON array of names. A bare "parameter" prefix matches both. (cert/cert_arns,
cfdist/cfdist_ids, key/key_ids, topic/topic_names and secret/secret_names were the
first five — five of six namespaces reached so far have collided, so it is the default rather than a
per-service discovery.)

ssmParameterARN (ssm_types.go:55-57) is arn:aws:ssm:{region}:{account}:parameter{name} with the
name's own leading / absorbed and no separator in the format string — so the inverse derivation
is exact, and the type segment is parameter matched as a whole /-delimited segment per #910. Its
confusable siblings in the same namespace are document/, servicesetting/, opsmetadata/,
automation-execution/, maintenancewindow/, patchbaseline/ and managed-instance/.

6. InvalidResourceId is answered at 404 where AWS publishes 400

All three sites answer HTTPStatus: http.StatusNotFound (:660, :702, :741). AWS publishes
400 for InvalidResourceId, as it does for InvalidResourceType, TooManyTagsError and
TooManyUpdates; only InternalServerError is 500, and SSM publishes no distinct not-found code
for these operations at all. This is the same class as #921 (ACM), #923 (KMS) and #930 (Secrets
Manager) and will be filed separately on the same reasoning: correcting which resource an
identifier names is a different change from correcting what status a refusal carries. This issue
routes all three sites through one helper so that fix is one line.

Acceptance criteria

  • A context-free ssm_tags.go holding the parameter-ARN parser, the state-key builders, the
    taggability guard and the refusal helpers — taking no *RequestContext, so no arm can reach
    for the caller's account, per SQS state keys disagree: the tagging API and the authorizer address queue:<name>, the plugin writes queue:<account>/<name> #826.
  • ResourceType is required at all three operations. A value outside the enum answers
    InvalidResourceType/400 (which is what AWS's own description of that code states); a valid
    enum value substrate models no resource for answers InvalidResourceId/400, because the type is
    one AWS publishes and it is the ID that names nothing. Where AWS is silent, recorded as
    substrate's reading.
  • A ResourceId beginning arn: is refused rather than normalized into a name.
  • The leading-slash tolerance is kept and documented: substrate's own putParameter normalizes
    Name to a leading / (ssm_plugin.go:164-166), so a caller who created MyParam must be
    able to tag MyParam. AWS documents this tolerance explicitly only for OpsMetadata, so for
    Parameter it is stated as substrate's reading, required by substrate's own normalization.
  • addTagsToResource and putParameter sort through sortTagsByKey, so the order is
    deterministic and creation-time and post-hoc tagging agree.
  • ListTagsForResource reports [] rather than null for an untagged parameter, and its order
    is deterministic.
  • TaggingPlugin.resolveARN gains an ssm arm through the same parser, so the two APIs cannot
    disagree about which parameter an ARN names (cfn: the aws:cloudformation:* stamp covers EC2 only, so the rest of a stack is unstamped #765's cross-readability criterion).
  • mergeResourceTags gains an ssmNamespace arm behind the colon-terminated guard, merging
    through mergeRecordTagListTags on the raw record so no sibling member is truncated.
  • A scanner reports every parameter in the caller's account and Region, and the descriptor list
    reaches twenty-five.
  • Tests are behavioural, through emulator.StartTestServer and signed wire calls only — no
    helper writing state directly, per cfn: the aws:cloudformation:* stamp covers EC2 only, so the rest of a stack is unstamped #765. Including: a Document/OpsItem/MaintenanceWindow
    ResourceType does not reach a same-named parameter; an out-of-enum type is refused; an ARN as
    ResourceId is refused; a tag written through SSM is reported by GetResources and vice
    versa; a parameter in another Region or account is not reported or tagged; a hierarchical name
    round-trips through its ARN; the order is deterministic across two identical calls.
  • docs/services.md and CHANGELOG.md updated.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    type: bug

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions