Skip to content

fix(iam): decode MaxItems, Marker and PathPrefix on ListInstanceProfiles (#873) - #901

Merged
scttfrdmn merged 1 commit into
mainfrom
fix/iam-list-instance-profiles-pagination
Sep 15, 2026
Merged

scttfrdmn merged 1 commit into
mainfrom
fix/iam-list-instance-profiles-pagination

Conversation

@scttfrdmn

Copy link
Copy Markdown
Owner

ListInstanceProfiles had no parseIAMBody call and no params struct. It authorized, listed the account's instance-profile keys, decoded each record, and returned every one with IsTruncated hardcoded false — whichever of MaxItems, Marker and PathPrefix the caller sent.

It now decodes all three, refuses an out-of-range MaxItems through iamValidateMaxItems, pages through paginateIAMKeys, and reports the real IsTruncated/Marker.

PathPrefix is applied before the page is cut

The issue's fourth criterion, and the one design point worth stating rather than inferring from the diff.

listUsers and listRoles slice with paginateIAMKeys first 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:

filter-after (listRoles) filter-first (this PR)
3 profiles: aaa-one /, aaa-two /, zzz-target /service-role/
MaxItems=1, PathPrefix=/service-role/ empty page, IsTruncated=true zzz-target, IsTruncated=false

The 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:120 filters, :143 paginates) already gets the order right, so this follows it rather than the two adjacent listings. The listUsers/listRoles order 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 PathPrefix matches on Path, which lives inside the record rather than in its state key. That is the trade listPolicies already makes. A page that under-fills is wrong in a way a caller cannot detect; an extra state read is only slower.

PathPrefix is validated, and not against policyPathType

The 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) is policyPathType, ^((/[A-Za-z0-9.,+@=_-]+)*)/$ — it requires a trailing slash. API_ListInstanceProfiles publishes \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 /team selects 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 PathPrefix is taken as absent rather than refused against the published minimum length of 1, matching iamValidateMaxItems' rule for a present-but-empty parameter: a form body carrying PathPrefix= 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_ListInstanceProfiles fetched, 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.
  • Errors — ServiceFailure/500 only. So ValidationError/400 for both refusals comes from CommonErrors, which is the same reasoning iam_max_items.go already 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, following iam_list_policies.go's convention (file-level why preamble, validation vars, handler). The handler is removed from iam_plugin.go and a pointer left in its place; the dispatch arm at :215 is 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 because iamValidateMaxItems reads presence from the decoded form values. Profiles are created through CreateInstanceProfile rather than written into state, per #765 — a helper writing the record directly cannot show that Path survives the owning operation, which is the value PathPrefix filters on.

  • MaxItemsPagesAndTheMarkerRoundTrips — walks a MaxItems=1 listing 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 no Marker.
  • RefusesAnOutOfRangeMaxItems — 0, -1, 1001 on this operation and on ListUsers, so the two cannot drift apart on the bounds; plus 1/1000 accepted 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, ignoring MaxItems gives 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 HasPrefix check from before paginateIAMKeys to inside the render loop, i.e. listRoles' order — fails PathPrefixFiltersBeforeThePageIsCut and AProfileKeepsItsRolesUnderAFilteredPage. Restoring it passes.

Verification

All nine gate commands, from the repo root:

gofmt -l . && go build ./... && go vet ./...          PASS
golangci-lint run ./...                                0 issues
make test                                              exit 0
GOTOOLCHAIN=go1.26.6 make test                         exit 0
GOTOOLCHAIN=go1.26.6 make coverage                     exit 0
make docs-reference docs-reference-check \
     docs-versions authz-reference-check               PASS
npm --prefix docs run build                            exit 0
go vet -C test/e2e ./... && go test -C test/e2e ./...  exit 0

Coverage: 83.9% emulator, 83.4% total — baseline held. No existing test needed relaxing; TestIAMPlugin_ListInstanceProfiles_Empty and _ReflectsCreated pass unchanged, which is the useful signal that the default path did not move.

Compatibility

A caller that sent MaxItems or PathPrefix and 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-range MaxItems now answers ValidationError/400 at this operation as it already does at the nineteen others, and a malformed PathPrefix answers ValidationError/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 with IsTruncated=true, which is what AWS answers.

Closes #873.

…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

codecov Bot commented Sep 15, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 92.72727% with 4 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
emulator/iam_list_instance_profiles.go 92.72% 4 Missing ⚠️

📢 Thoughts on this report? Let us know!

@scttfrdmn
scttfrdmn merged commit 5a16569 into main Sep 15, 2026
17 checks passed
@scttfrdmn
scttfrdmn deleted the fix/iam-list-instance-profiles-pagination branch September 15, 2026 22:31
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: ListInstanceProfiles ignores MaxItems, Marker and PathPrefix entirely

1 participant