Repository navigation
fix(iam): a boundary an SDK can read, and a count something wrote (#852, #847, #846) - #854
Merged
Merged
Conversation
…, #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.
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.
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
iamPermissionsBoundaryXMLemitted<PolicyArn>and<PolicyName>, and neither name exists on AWS's shape. ThePermissionsBoundarymember ofUser,Role,UserDetailandRoleDetailis anAttachedPermissionsBoundary, whose Contents section lists exactlyPermissionsBoundaryArnandPermissionsBoundaryType. So a consumer readingrole.PermissionsBoundary.PermissionsBoundaryArngot""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.PermissionsBoundaryTyperendersPermissionsBoundaryPolicy. AWS's page contradicts itself — the prose says the type "can only have a value ofPolicy" 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
PolicyNamecome from the resolved policy, and the boundary shape has noPolicyNamemember for a better-sourced name to go in. The name stays on the stored record, whereListAttachedRolePoliciesrenders it and AWS'sAttachedPolicyshape does have the member.A count nothing writes
Nothing assigns
IAMPolicy.AttachmentCount.CreatePolicynever set it, the bundled catalog carries no value for it, and an attach records only the ARN on the entity's own list — soGetPolicyreported 0 for every policy in every state whileListPolicies, which derives the count, reported the truth. A policy attached to three entities read as 3 in a listing and 0 on its own.getPolicynow 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 theuser:androle: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 —
GetManagedPolicyhands 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 withInvalidInput/400 through the sameiamValidatePolicyARNthe three attach operations use, and refuses a service-linked role withUnmodifiableEntity/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 carriesUnmodifiableEntityon its error list, and neither appears onPutUserPermissionsBoundary. Recognition reuses the two helpersdeleteRolealready 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
NoSuchEntitycontradicts #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:
loadPermissionBoundaryreturns 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
PolicyNotAttachableis 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.ValidationErroris kept for a missing required member. The plan hadInvalidInputreplacing it on the grounds thatValidationErroris on neither operation's error list — which is true, but it is on IAM'sCommonErrorspage: "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 lineattachRolePolicyalready 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; theInvalidInputtable 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 thatGetPolicyandListPoliciesagree — 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 aNotContainson<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:
deletePolicyhas noDeleteConflictcheck 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.