Skip to content

fix(iam): decode query-protocol list parameters (#639) - #640

Merged
scttfrdmn merged 1 commit into
mainfrom
fix/639-iam-member-lists
Aug 14, 2026
Merged

scttfrdmn merged 1 commit into
mainfrom
fix/639-iam-member-lists

Conversation

@scttfrdmn

Copy link
Copy Markdown
Owner

Closes #639.

The defect

IAM speaks the AWS query protocol, in which a list travels as numbered form
parameters:

Tags.member.1.Key=env&Tags.member.1.Value=prod&Tags.member.2.Key=team&Tags.member.2.Value=infra

Nothing decoded that encoding. ParseAWSRequest flattens a form body into
AWSRequest.Params, a map[string]string (emulator/parser.go:44), and
server.go:583-589 rebuilds req.Body for the query-protocol services as
json.Marshal(req.Params) — so a handler field declared Tags []IAMTag was
matched by a JSON key literally named "Tags.member.1.Key" and unmarshaled to
nil.

Six operations were affected, all answering 200 OK and storing nothing:
TagUser, UntagUser, TagRole, UntagRole, and the create-time Tags on
CreateUser/CreateRole (the last two are how CDK and Terraform tag, so they
matter as much as the explicit pair). A tag call that reports success and does
not happen is worse than a refusal: a consumer's assertion on its own tagging
silently becomes an assertion about an empty set.

The fix

New emulator/iam_query.go, following the pattern parseMemberList
(cloudwatch_plugin.go:464) already established, with two rules made explicit:

  • Indices are walked from 1 and the first gap ends the list. AWS numbers
    members contiguously; guessing at the intended length would invent members a
    client never sent.
  • A present-but-empty value is a member holding "", not the end of the
    list — the same present-vs-absent distinction parser.go:37-56 is careful
    about for ImageId (RunInstances: validate required parameters (ImageId) like AWS does #412), because a required-member check has to be able to
    see what was sent.

A member map keeps its suffix verbatim, so a list nested inside a struct member
(ContextEntries.member.1.ContextKeyValues.member.1, which
SimulatePrincipalPolicy needs — #579) decodes by applying the flat decoder to
the map.

Each handler reads req.Params and falls back to its JSON body when no member
list was sent. That dual read is deliberate and commented: the JSON path is how
a unit test drives the plugin, the params path is how every real client does.

Why the suite shipped green over it

iamRequest (iam_plugin_test.go:40) hand-marshals a body containing real JSON
arrays — a shape no AWS client produces — and no e2e journey drove a list-valued
IAM parameter. Same structural blind spot as #561 / #610 / #636: an operation no
client can reach, with passing tests over it.

Both new test files close it:

  • test/e2e/journey_iam_tags_test.go — the SDK level, with two-element lists so
    a decoder reading only index 1 would fail. This fails before the fix.
  • emulator/iam_query_wire_test.go — a genuine application/x-www-form-urlencoded
    body one layer down, so a decode regression is reported by the package that
    owns the decoder rather than only by the separate e2e module.

Verification

  • gofmt -l ., go build ./..., go vet ./..., golangci-lint run ./... — 0 issues
  • make test (race detector) green; test/e2e green
  • make coverage — 81.6% total, 82.3% for emulator
  • Live against substrate server --address :4678 with AWS_MAX_ATTEMPTS=1:
    tag-user + list-user-tags returns both tags, untag-user removes the named
    one, and create-user --tags keeps them. This is where the defect was visible
    and every unit test was not.
  • Mutation testing, 6 applied, 6 CAUGHT: flat walk starting at 0; empty value
    treated as end-of-list; struct walk starting at 0; nested suffix truncated at
    the first dot; a wholly-empty tag member kept rather than dropped; the params
    read removed from tagUser only (the asymmetric-fix case). No survivors.

IAM speaks the AWS query protocol, in which a list travels as numbered form
parameters — Tags.member.1.Key=env&Tags.member.1.Value=prod. Nothing decoded
that encoding. ParseAWSRequest flattens a form body into AWSRequest.Params, a
map[string]string, and server.go rebuilds req.Body for the query-protocol
services as json.Marshal(req.Params), so a handler field declared
`Tags []IAMTag` was matched by a JSON key literally named "Tags.member.1.Key"
and unmarshaled to nil.

TagUser, UntagUser, TagRole, UntagRole and the create-time Tags on
CreateUser/CreateRole all answered 200 OK and stored nothing — a tag call that
reported success and did not happen.

The new emulator/iam_query.go follows the pattern parseMemberList already
established, with two rules made explicit: indices are walked from 1 and the
first gap ends the list, because AWS numbers members contiguously and guessing
at the intended length would invent members; and a present-but-empty value is a
member holding "" rather than the end of the list, the same present-vs-absent
distinction the parser is careful about for ImageId (#412). A member map keeps
its suffix verbatim, so a list nested inside a struct member — the
ContextEntries shape SimulatePrincipalPolicy needs — decodes by applying the
flat decoder to the map.

Each handler reads req.Params and falls back to its JSON body when no member
list was sent. The JSON path is how a unit test drives the plugin, the params
path is how every real client does, and only the first was ever exercised:
iamRequest hand-marshals real JSON arrays, a shape no AWS client produces, and
no e2e journey drove a list-valued IAM parameter. That is the #561/#610/#636
blind spot again. Both new test files close it — journey_iam_tags_test.go at the
SDK level and iam_query_wire_test.go posting a genuine urlencoded form body one
layer down.

Verified live against `substrate server` with the AWS CLI, which is where the
defect was visible and every unit test was not.
@codecov

codecov Bot commented Aug 14, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@scttfrdmn
scttfrdmn merged commit e17be85 into main Aug 14, 2026
13 checks passed
@scttfrdmn
scttfrdmn deleted the fix/639-iam-member-lists branch August 14, 2026 22:53
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.

IAM query-protocol list parameters never reach a handler, so TagUser/UntagUser/TagRole/UntagRole silently discard what an SDK sends

1 participant