Repository navigation
fix(iam): decode query-protocol list parameters (#639) - #640
Merged
Merged
Conversation
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 Report✅ All modified and coverable lines are covered by tests. 📢 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 #639.
The defect
IAM speaks the AWS query protocol, in which a list travels as numbered form
parameters:
Nothing decoded that encoding.
ParseAWSRequestflattens a form body intoAWSRequest.Params, amap[string]string(emulator/parser.go:44), andserver.go:583-589rebuildsreq.Bodyfor the query-protocol services asjson.Marshal(req.Params)— so a handler field declaredTags []IAMTagwasmatched by a JSON key literally named
"Tags.member.1.Key"and unmarshaled tonil.
Six operations were affected, all answering
200 OKand storing nothing:TagUser,UntagUser,TagRole,UntagRole, and the create-timeTagsonCreateUser/CreateRole(the last two are how CDK and Terraform tag, so theymatter 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 patternparseMemberList(
cloudwatch_plugin.go:464) already established, with two rules made explicit:members contiguously; guessing at the intended length would invent members a
client never sent.
"", not the end of thelist — the same present-vs-absent distinction
parser.go:37-56is carefulabout for
ImageId(RunInstances: validate required parameters (ImageId) like AWS does #412), because a required-member check has to be able tosee what was sent.
A member map keeps its suffix verbatim, so a list nested inside a struct member
(
ContextEntries.member.1.ContextKeyValues.member.1, whichSimulatePrincipalPolicyneeds — #579) decodes by applying the flat decoder tothe map.
Each handler reads
req.Paramsand falls back to its JSON body when no memberlist 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 JSONarrays — 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 soa decoder reading only index 1 would fail. This fails before the fix.
emulator/iam_query_wire_test.go— a genuineapplication/x-www-form-urlencodedbody 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 issuesmake test(race detector) green;test/e2egreenmake coverage— 81.6% total, 82.3% foremulatorsubstrate server --address :4678withAWS_MAX_ATTEMPTS=1:tag-user+list-user-tagsreturns both tags,untag-userremoves the namedone, and
create-user --tagskeeps them. This is where the defect was visibleand every unit test was not.
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
tagUseronly (the asymmetric-fix case). No survivors.