Skip to content

fix(iam): a boundary an SDK can read, and a count something wrote (#852, #847, #846) - #854

Merged
scttfrdmn merged 1 commit into
mainfrom
fix/iam-boundary-shape-and-attachment-count
Sep 14, 2026
Merged

scttfrdmn merged 1 commit into
mainfrom
fix/iam-boundary-shape-and-attachment-count

Conversation

@scttfrdmn

Copy link
Copy Markdown
Owner

Two defects of one kind: IAM reported a value nothing on the receiving end could read, and a value nothing had written.

A boundary an SDK decodes as an empty object

iamPermissionsBoundaryXML emitted <PolicyArn> and <PolicyName>, and neither name exists on AWS's shape. The PermissionsBoundary member of User, Role, UserDetail and RoleDetail is an AttachedPermissionsBoundary, whose Contents section lists exactly PermissionsBoundaryArn and PermissionsBoundaryType. So a consumer reading role.PermissionsBoundary.PermissionsBoundaryArn got "" for a boundary substrate had stored and was reporting.

Nothing in the tree had ever emitted either AWS name, and the one test covering the element asserted only that the <PermissionsBoundary> tag was present — which is exactly the assertion a decoded struct can make and cannot distinguish from an empty one. The fix is asserted both ways: raw XML for member presence, and a typed decode through AWS's names for the thing an SDK actually does.

PermissionsBoundaryType renders PermissionsBoundaryPolicy. AWS's page contradicts itself — the prose says the type "can only have a value of Policy" while the same page's enumeration says "Valid Values: PermissionsBoundaryPolicy", and the CLI v2 reference, generated from the service model, lists only the latter — so under #671's binding rule, only what the API model states, the wire value is the enum's, with the prose recorded rather than silently resolved. It is a named constant so that a shape rendering a boundary later (GetAccountAuthorizationDetails, #848) cannot pick the other spelling.

This is what makes #846's second acceptance criterion moot rather than deferred: it asked that the stored PolicyName come from the resolved policy, and the boundary shape has no PolicyName member for a better-sourced name to go in. The name stays on the stored record, where ListAttachedRolePolicies renders it and AWS's AttachedPolicy shape does have the member.

A count nothing writes

Nothing assigns IAMPolicy.AttachmentCount. CreatePolicy never set it, the bundled catalog carries no value for it, and an attach records only the ARN on the entity's own list — so GetPolicy reported 0 for every policy in every state while ListPolicies, which derives the count, reported the truth. A policy attached to three entities read as 3 in a listing and 0 on its own.

getPolicy now derives it from the same three <kind>_policies: prefixes, hoisted once per request alongside the existing boundary-usage scan. The two scans are not collapsed: attachment counts are read without loading a single entity record, while boundary usage has to walk the user: and role: records.

Correcting the issue on one point: it describes one call and one assignment. There are two success arms, and only the catalog arm needs a local copy — GetManagedPolicy hands back the catalog's shared pointer, and the catalog is package-level, so writing the count through it would leak one request's number into every later read of that policy including reads from a different emulator in the same process. That is asserted as a test rather than left to the comment.

Validation on the boundary path, following #499 rather than reversing it

putPermissionsBoundary — one body serving both operations — tested the boundary for emptiness only. It now refuses a malformed ARN with InvalidInput/400 through the same iamValidatePolicyARN the three attach operations use, and refuses a service-linked role with UnmodifiableEntity/400 on the role path.

That asymmetry is AWS's own, not a structural inference: PutRolePermissionsBoundary's prose says "You cannot set the boundary for a service-linked role" and carries UnmodifiableEntity on its error list, and neither appears on PutUserPermissionsBoundary. Recognition reuses the two helpers deleteRole already uses, so there is one definition of a reserved path.

#846's first acceptance criterion is deliberately reversed. Refusing a boundary ARN that names no policy with NoSuchEntity contradicts #499's recorded rationale: substrate bundles 52 of roughly 1,200 managed policies, AWS says a boundary may be "an AWS managed policy or a customer managed policy", and neither operation's page states what a nonexistent boundary policy produces — so the refusal would be substrate's inference presented as AWS's behaviour, and it would fail the ~1,150 calls that succeed against AWS. An unbundled managed ARN succeeding is asserted as a test, so the reversal cannot be quietly undone.

It warns instead, on its own line rather than the attach path's, because the consequence runs the other way. An unresolvable attached policy grants nothing, so a decision that needed it is denied — fail-closed. An unresolvable boundary restricts nothing: loadPermissionBoundary returns nil when the ARN loads nowhere, a nil boundary is indistinguishable from no boundary, and the entity keeps every permission its attached policies grant where AWS would have clamped them. Saying "contributes no statements" there would have been misleading in the direction that matters.

Two things not taken, with reasons

  • PolicyNotAttachable is published on both operation pages and is not modelled. Substrate does not record which managed policies are AWS service-role policies, so it cannot tell the case apart, and refusing on a guess would be a refusal AWS's own description does not cover.
  • ValidationError is kept for a missing required member. The plan had InvalidInput replacing it on the grounds that ValidationError is on neither operation's error list — which is true, but it is on IAM's CommonErrors page: "The input doesn't meet the required format or constraints. Check that all required parameters are included and that values are valid", HTTP 400. That is where a framework-level refusal belongs and what every other IAM handler answers for an absent member, so the two codes divide on the same line attachRolePolicy already draws. Verified by fetching the page rather than from recollection.

Tests

New emulator/iam_boundary_shape_test.go, nine tests, all over the wire. The pairs are the point: the boundary decode test has a negative twin asserting a deleted boundary omits the member, so it cannot pass against a renderer that emits the names unconditionally; the InvalidInput table asserts the entity is left without a boundary after each refusal; and the count test walks a policy onto a user, a group and a role and back off, asserting after every step that GetPolicy and ListPolicies agree — a test that would have failed 3-against-0 before this change. Two existing tests asserted the old member names and are updated, one of them (iam_shape_members_test.go) also gaining a NotContains on <PolicyName>.

Verification

All nine gate commands green. Coverage holds at the baseline: emulator 83.8%, total 83.2%.

Closes #852.
Closes #847.
Closes #846.

One finding is filed separately rather than fixed here: deletePolicy has no DeleteConflict check at all while seven other IAM delete paths do, so an attached policy deletes silently and every entity keeps an ARN pointing at nothing — #853, on v0.116.0. #847 is what makes it observable through the API rather than only in state, which is why it reads better after this lands than before.

…, #847, #846)

Two defects of one kind: IAM reported a value nothing on the receiving end
could read, and a value nothing had written.

GetRole and GetUser rendered an entity's permissions boundary as <PolicyArn>
and <PolicyName>, and neither name exists on AWS's shape — the
PermissionsBoundary member of User, Role, UserDetail and RoleDetail is an
AttachedPermissionsBoundary, whose two members are PermissionsBoundaryArn and
PermissionsBoundaryType. So an SDK decoded the element into an empty struct: a
consumer reading role.PermissionsBoundary.PermissionsBoundaryArn got "" for a
boundary substrate had stored and was reporting. The type renders the enum's
PermissionsBoundaryPolicy rather than the prose's Policy, per #671.

Nothing writes IAMPolicy.AttachmentCount, so GetPolicy reported 0 for every
policy in every state while ListPolicies, which derives the count, reported the
truth. GetPolicy now derives it too, from the same three <kind>_policies:
prefixes, onto a copy of a bundled policy's record so a count cannot leak
through the catalog's shared pointers.

putPermissionsBoundary gains InvalidInput/400 for a malformed ARN and
UnmodifiableEntity/400 for a service-linked role on the role path only, which is
AWS's own asymmetry rather than an inference. Its first acceptance criterion is
reversed with the reason recorded: refusing an unresolvable boundary ARN
contradicts #499 and would fail the ~1,150 managed policies substrate does not
bundle, so it warns instead — on its own line, because an unresolvable boundary
restricts nothing where an unresolvable attached policy grants nothing.
@scttfrdmn scttfrdmn added this to the v0.115.0 milestone Sep 14, 2026
@codecov

codecov Bot commented Sep 14, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 87.50000% with 5 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
emulator/iam_policy_arn.go 78.94% 4 Missing ⚠️
emulator/iam_plugin.go 94.44% 1 Missing ⚠️

📢 Thoughts on this report? Let us know!

@scttfrdmn
scttfrdmn merged commit 34124ee into main Sep 14, 2026
17 checks passed
@scttfrdmn
scttfrdmn deleted the fix/iam-boundary-shape-and-attachment-count branch September 14, 2026 19:00
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