Repository navigation
fix(iam): decode MaxItems, Marker and PathPrefix on ListInstanceProfiles (#873) - #901
Merged
Merged
Conversation
…les (#873) The operation had no parseIAMBody call and no params struct, so it returned every instance profile in the account with IsTruncated hardcoded false. PathPrefix is applied before the page is cut, unlike ListUsers and ListRoles, which slice first and filter while rendering — an order that under-fills a page whenever the entities outside the prefix outnumber it. PathPrefix is validated against the pattern and length API_ListInstanceProfiles publishes, which is not policyPathType: this operation accepts a prefix with no trailing slash.
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.
ListInstanceProfileshad noparseIAMBodycall and no params struct. It authorized, listed the account's instance-profile keys, decoded each record, and returned every one withIsTruncatedhardcodedfalse— whichever ofMaxItems,MarkerandPathPrefixthe caller sent.It now decodes all three, refuses an out-of-range
MaxItemsthroughiamValidateMaxItems, pages throughpaginateIAMKeys, and reports the realIsTruncated/Marker.PathPrefixis applied before the page is cutThe issue's fourth criterion, and the one design point worth stating rather than inferring from the diff.
listUsersandlistRolesslice withpaginateIAMKeysfirst and check the prefix inside the loop that renders the page (iam_plugin.go:437,:747). That under-fills a page whenever the entities outside the prefix outnumber it. Concretely, and this is the new test:listRoles)aaa-one/,aaa-two/,zzz-target/service-role/MaxItems=1,PathPrefix=/service-role/IsTruncated=truezzz-target,IsTruncated=falseThe caller cannot tell that empty page from an account with nothing under
/service-role/, which is the same accepted-and-ignored failure the issue is about.listPolicies(iam_list_policies.go:120filters,:143paginates) already gets the order right, so this follows it rather than the two adjacent listings. ThelistUsers/listRolesorder is a separate defect and is not fixed here.The cost is recorded rather than hidden: every profile in the account is decoded on each call, not one page's worth, because
PathPrefixmatches onPath, which lives inside the record rather than in its state key. That is the tradelistPoliciesalready makes. A page that under-fills is wrong in a way a caller cannot detect; an extra state read is only slower.PathPrefixis validated, and not againstpolicyPathTypeThe issue asked for the pattern to be validated or for the decision not to be recorded explicitly. It is validated, and the pattern is a new one rather than the existing
iamPathPrefixPattern.iamPathPrefixPattern(iam_list_policies.go:33) ispolicyPathType,^((/[A-Za-z0-9.,+@=_-]+)*)/$— it requires a trailing slash.API_ListInstanceProfilespublishes\u002F[\u0021-\u007F]*, which does not. Sharing the stricter one would refuse/service-role, a prefix IAM accepts, and failing a call that succeeds against AWS is the worse of the two errors. A test asserts/teamselects the profiles under/team/infra/and/team/ops/.Enforcing the leading slash is still worth doing:
service-role/matches no profile at all, so a silent empty result is indistinguishable from "nothing is under that path" — the accepted-and-ignored failure moved from the parameter to its value.An empty
PathPrefixis taken as absent rather than refused against the published minimum length of 1, matchingiamValidateMaxItems' rule for a present-but-empty parameter: a form body carryingPathPrefix=expressed no filter, so it takes the documented default of/. The two parameters must not disagree about what an empty value means in one request.Provenance
API_ListInstanceProfilesfetched, not recalled. Everything below is from that page:MaxItems— "Valid Range: Minimum value of 1. Maximum value of 1000", "If you do not include this parameter, the number of items defaults to 100."PathPrefix— "Length Constraints: Minimum length of 1. Maximum length of 512.", Pattern\u002F[\u0021-\u007F]*, "If it is not included, it defaults to a slash (/), listing all instance profiles."Marker— "Length Constraints: Minimum length of 1.", Pattern[ -ÿ]+. The page publishes no maximum, so the issue body's "1-320" is not sourced from it; nothing in this PR relies on either bound, since the marker is substrate's own base64 of a state key.ServiceFailure/500 only. SoValidationError/400 for both refusals comes fromCommonErrors, which is the same reasoningiam_max_items.goalready records for the nineteen operations iam: paginateIAMKeys silently rewrites an out-of-range MaxItems to 100 at eight operations AWS refuses #868 guarded.Files
New
emulator/iam_list_instance_profiles.go, followingiam_list_policies.go's convention (file-level why preamble, validation vars, handler). The handler is removed fromiam_plugin.goand a pointer left in its place; the dispatch arm at:215is unchanged.Tests
New
emulator/iam_list_instance_profiles_test.go. Every call goes over the query protocol, both because it is the path a real SDK client takes and becauseiamValidateMaxItemsreads presence from the decoded form values. Profiles are created throughCreateInstanceProfilerather than written into state, per #765 — a helper writing the record directly cannot show thatPathsurvives the owning operation, which is the valuePathPrefixfilters on.MaxItemsPagesAndTheMarkerRoundTrips— walks aMaxItems=1listing to the end; the walk is the assertion, since a marker that did not resume where the last page stopped would repeat or skip while every individual response still looked well-formed. Also asserts the final page carries noMarker.RefusesAnOutOfRangeMaxItems—0,-1,1001on this operation and onListUsers, so the two cannot drift apart on the bounds; plus1/1000accepted and present-but-empty accepted.AnAbsentMaxItemsTakesTheDocumentedDefault— 101 profiles, which is the smallest count that tells the fix from the old behaviour: at 100 or fewer, ignoringMaxItemsgives the same answer.PathPrefixFiltersBeforeThePageIsCut— the table above.PathPrefixSelectsOnlyItsPath— absent,/, a full path, a parent path, no trailing slash, and a path nothing is under.RefusesAMalformedPathPrefix— no leading slash, a bare name, a space (U+0020, one below the published lower bound), a non-ASCII character, 513 characters; plus 512 accepted, so the bound cannot be off by one in the direction that fails a call IAM accepts.PathPrefixIsRefusedBeforeMaxItems— a doubly-invalid request reports one problem, not whichever check happened to run first.AProfileKeepsItsRolesUnderAFilteredPage— the page is now built from a map keyed by state key, so a mis-keyed lookup would render an empty member and still produce a well-formed response of the right length.Verified the tests catch the defect: reverting only the filter order — moving the
HasPrefixcheck from beforepaginateIAMKeysto inside the render loop, i.e.listRoles' order — failsPathPrefixFiltersBeforeThePageIsCutandAProfileKeepsItsRolesUnderAFilteredPage. Restoring it passes.Verification
All nine gate commands, from the repo root:
Coverage: 83.9% emulator, 83.4% total — baseline held. No existing test needed relaxing;
TestIAMPlugin_ListInstanceProfiles_Emptyand_ReflectsCreatedpass unchanged, which is the useful signal that the default path did not move.Compatibility
A caller that sent
MaxItemsorPathPrefixand relied on receiving everything anyway now receives a page or a filtered set — it was relying on substrate ignoring a parameter AWS applies. An out-of-rangeMaxItemsnow answersValidationError/400 at this operation as it already does at the nineteen others, and a malformedPathPrefixanswersValidationError/400 where it was previously accepted and matched nothing. A caller sending none of the three sees no change while the account holds 100 profiles or fewer; beyond that it now gets 100 withIsTruncated=true, which is what AWS answers.Closes #873.