Skip to content

feat(iam): the account authorization snapshot, and MaxItems refused rather than coerced (#848, #868) - #874

Merged
scttfrdmn merged 1 commit into
mainfrom
feat/848-account-authorization-details
Sep 15, 2026
Merged

scttfrdmn merged 1 commit into
mainfrom
feat/848-account-authorization-details

Conversation

@scttfrdmn

Copy link
Copy Markdown
Owner

Why

GetAccountAuthorizationDetails is the only operation that reports all four IAM entity shapes — user, group, role and managed policy — in one response, with their inline and attached policies. That makes it the only place AttachmentCount, PermissionsBoundaryUsageCount and RoleLastUsed can be observed beside the single-entity operations that also report them. #847, #815 and #816 were all defects of exactly that kind: a derived value diverging between two operations that report the same shape, with nothing in the tree putting the two derivations side by side. Until now the operation answered InvalidAction while already being authorizable — authzref/iam.json and authz_reference_gen.go both carry iam:GetAccountAuthorizationDetails with an empty resource list — so only a handler was needed.

The second half is the same release theme aimed at a request parameter. paginateIAMKeys rewrote any MaxItems outside 1–1000 to 100, so a caller who asked for 1001 items got 100 and a caller who asked for 0 got 100 — a page size no part of the request named, while AWS refuses both with a 400.

What changed

GetAccountAuthorizationDetails (#848) — new file emulator/iam_account_authorization_details.go, following iam_list_policies.go's convention, plus one dispatch arm. Three decisions are recorded in the file's preamble, in docs/services.md and in the CHANGELOG rather than left implied:

  • The embedded role is re-read from state, not rendered from IAMInstanceProfile.Roles. That field is a frozen copy written at AddRoleToInstanceProfile; STS writes RoleLastUsed onto the role record and never reaches it, and AWS's own sample renders <RoleLastUsed> inside InstanceProfileList. Rendering from the snapshot reports nil there for essentially every role. TestIAMAccountAuthorizationDetails_RoleLastUsedInsideInstanceProfile was verified to fail — with the exact "does not contain" diff — when the refresh loop is deleted.
  • MaxItems counts across the four lists combined, over one ordered composite key space (user/<name>, policy/<arn>, …) so a Marker is unambiguous. AWS documents neither reading. With 52 bundled managed policies against a default of 100, truncation is on the default path, not an edge case.
  • The detail shapes drop members their single-entity siblings carry. RoleDetail has no Description and no MaxSessionDuration; UserDetail has no PasswordLastUsed. The Role nested inside an instance profile does carry both, because InstanceProfile.Roles is an array of Role, not RoleDetail — two different shapes, asserted as two different member sets.

#848's fourth acceptance criterion is reversed, with the citation. The issue asks for every policy document to be URL-encoded. The operation page claims exactly that, and its own sample response renders every document as plain JSON; only PolicyVersion.Document's own type page repeats the RFC-3986 mandate, and PolicyDetail.PolicyDocument and RoleDetail's carry no such sentence. Substrate follows the per-shape pages: PolicyVersionList[].Document is percent-encoded via iamEscapeRFC3986 and matches GetPolicyVersion byte for byte, while AssumeRolePolicyDocument and the inline documents stay plain JSON and match GetRole/GetRolePolicy. Encoding everything would have been a breaking wire change to five shipped operations. Two conventions in one response is what AWS's model has, and TestIAMAccountAuthorizationDetails_PolicyDocumentEncodings asserts both in one body.

An unknown Filter value is refused with ValidationError naming the value and the five accepted ones. A store read that fails reaches the caller as a 500 — this operation's answer is the account, so a swallowed error reads as "the entity is gone" — while a record that does not decode is skipped, because it never will decode and failing the whole operation would let one bad key hide an account's authorization for good. Nine armed store-failure arms and one corrupt-record case cover the split.

An out-of-range MaxItems is refused (#868) — new emulator/iam_max_items.go. Validated before any work at all seventeen handlers, nineteen operations, that decode the parameter. The presence rule is read from the decoded form parameters, because a decoded int cannot distinguish an explicit MaxItems=0 (below the minimum) from an absent one (the documented default of 100). The coercion in paginateIAMKeys remains the defaulting path for an absent value; it is no longer reachable by a value the caller sent.

The code is ValidationError/400 at those nineteen and stays InvalidInput/400 at SimulatePrincipalPolicy and SimulateCustomPolicy — that split is AWS's, not substrate's: the simulate pair publish InvalidInput in their own Errors sections, while the nineteen publish only NoSuchEntity and ServiceFailure and so can only draw from CommonErrors, which does not list it. Those two now apply the same bounds and the same presence rule, closing a below-minimum hole at the one place that was already validating: an explicit MaxItems=0 had been taken as absent and served a page its nineteen siblings now refuse. Only the code differs across all twenty-one operations.

Corrected on the record. #868's inventory row for ListInstanceProfiles is stale (a line number that drifted). That operation decodes no request parameters at all — it ignores MaxItems, Marker and PathPrefix and hardcodes IsTruncated=false — so there is no decoded value for this guard to range-check. That is the accepted-and-ignored class rather than the silently-coerced one, and closing it means implementing pagination the operation has never had. Corrected in a comment on #868 and filed as #873.

Verification

The nine-command gate, all green:

  • gofmt -l . && go build ./... && go vet ./... — clean
  • golangci-lint run ./... — 0 issues
  • make test — exit 0
  • GOTOOLCHAIN=go1.26.6 make test — exit 0
  • GOTOOLCHAIN=go1.26.6 make coverage — 83.9% emulator / 83.3% total, holding the 83.9%/83.2% baseline
  • make docs-reference docs-reference-check docs-versions authz-reference-check — exit 0
  • npm --prefix docs run build — exit 0
  • go vet -C test/e2e ./... && go test -C test/e2e ./... — exit 0

Every assertion in emulator/iam_account_authorization_details_test.go is on raw XML, not a decoded struct: a struct cannot distinguish an absent member from an empty one, which is how iam_shape_members_test.go missed the boundary defect #807 fixed. Every entity is created through the API over the wire — no putTest* helper, per #765's rule that a helper writing state directly cannot prove a value is readable through the owning service's own call.

Compatibility

GetAccountAuthorizationDetails exists where it previously answered InvalidAction. MaxItems outside 1–1000 is refused at nineteen IAM operations that previously coerced it to 100, and an explicit MaxItems=0 is now refused at the two simulate operations that previously treated it as absent. A caller relying on the coercion was relying on a page size it did not ask for.

Closes #848
Closes #868

…ather than coerced (#848, #868)

GetAccountAuthorizationDetails is the one operation that reports all four
IAM entity shapes in one response, so it is the only place AttachmentCount,
PermissionsBoundaryUsageCount and RoleLastUsed can be seen beside the
single-entity operations that also report them. #847, #815 and #816 were all
defects of exactly that kind — a derived value diverging between two
operations — and nothing in the tree put the two derivations side by side.
The action was already authorizable, so only a handler was needed.

Three decisions are recorded rather than implied. An instance profile's
embedded role is re-read from state instead of rendered from the profile's
frozen copy, because STS writes RoleLastUsed onto the role record and AWS's
own sample renders that member inside InstanceProfileList. MaxItems counts
across the four lists combined over one ordered composite key space, which
AWS does not document either way, and with 52 bundled policies against a
default of 100 truncation is on the default path rather than an edge case.
The detail shapes drop members their single-entity siblings carry —
RoleDetail has no Description or MaxSessionDuration, UserDetail no
PasswordLastUsed — while the Role nested inside an instance profile does
carry them, because those are two different shapes.

The issue's fourth acceptance criterion is reversed with its citation: the
operation page claims every policy document is RFC 3986 URL-encoded, while
its own sample response renders all of them as plain JSON, and only
PolicyVersion.Document's own type page repeats the mandate. Substrate
follows the per-shape pages, so PolicyVersionList[].Document is
percent-encoded and matches GetPolicyVersion byte for byte while
AssumeRolePolicyDocument and the inline documents stay plain JSON and match
GetRole and GetRolePolicy — two conventions in one response, which is what
AWS's model has.

An unknown Filter value is refused with ValidationError naming the value and
the five accepted ones. A store read that fails reaches the caller as a 500,
because this operation's answer is the account and a swallowed error reads
as "the entity is gone"; a record that does not decode is skipped, because
it never will decode and failing the whole operation would let one bad key
hide an account's authorization for good.

MaxItems outside 1-1000 was silently rewritten to 100 by the shared
paginator, so a caller who asked for 1001 got 100 — a page size no part of
the request named, the release's theme applied to a request parameter. It is
now refused before any work at all seventeen handlers, nineteen operations,
that decode the parameter, with the presence rule read from the decoded form
parameters so an explicit MaxItems=0 is below the minimum rather than
absent. The code is ValidationError/400 there and stays InvalidInput/400 at
SimulatePrincipalPolicy and SimulateCustomPolicy, which publish that code in
their own Errors sections; that split is AWS's. Those two now apply the same
bounds and the same presence rule, where an explicit zero had been taken as
absent at the one place already validating.

ListInstanceProfiles is a stale row in #868's inventory rather than a site
this fix reaches: it decodes no request parameters at all, so there is no
value to range-check. Corrected on that issue and filed as #873.

Closes #848
Closes #868
@scttfrdmn scttfrdmn added this to the v0.116.0 milestone Sep 15, 2026
@scttfrdmn
scttfrdmn merged commit 3503416 into main Sep 15, 2026
16 checks passed
@scttfrdmn
scttfrdmn deleted the feat/848-account-authorization-details branch September 15, 2026 04:34
@codecov

codecov Bot commented Sep 15, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 89.36170% with 40 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
emulator/iam_account_authorization_details.go 90.10% 27 Missing ⚠️
emulator/iam_plugin.go 70.37% 8 Missing ⚠️
emulator/iam_groups.go 60.00% 2 Missing ⚠️
emulator/iam_tagging.go 60.00% 2 Missing ⚠️
emulator/iam_policy_versions.go 50.00% 1 Missing ⚠️

📢 Thoughts on this report? Let us know!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

1 participant