Repository navigation
feat(iam): groups have an observable effect (#579) - #641
Merged
Merged
Conversation
Substrate routed CreateGroup/GetGroup/DeleteGroup/ListGroups and nothing else, so a group could be created and then did nothing: no user could join it, no policy could be put on it, and GetGroup passed iamUserListXML(nil) unconditionally. Eleven operations close that gap — AddUserToGroup, RemoveUserFromGroup, ListGroupsForUser, AttachGroupPolicy, DetachGroupPolicy, ListAttachedGroupPolicies, PutGroupPolicy, GetGroupPolicy, DeleteGroupPolicy, ListGroupPolicies — and GetGroup now reports real, sorted, paginated members. Membership is stored on both sides of the index because both directions are read by an API, and every write goes through one pair of functions so the two sides cannot disagree. DeleteGroup refuses with DeleteConflict while members or attached policies remain, and DeleteUser refuses while the user belongs to a group: a delete that skipped either check would leave a dangling membership that loadPoliciesForPrincipal reads on every request. Both policy loaders learned the group arm — AuthController's and IAMPlugin.authorize's, which loads its own documents independently. Teaching only one would have recreated #411: one ARN, two loaders, two opposite answers. A test asserts the two agree. Also fixes the inline-policy family's default arm, which read role state for the existence check while reporting UserName in the response, so any non-role type looked itself up under the wrong prefix.
Codecov Report❌ Patch coverage is 📢 Thoughts on this report? Let us know! |
Codecov flagged the patch. The new cases are the ones a consumer actually reaches: a detach that must leave the group's other policies alone, the ValidationError arm of every operation that takes a required member, ListGroupsForUser's Marker cursor (the index pages on both sides, so both sides need the assertion), and the authorization gate on all six new mutating and reading operations — an unauthorized AddUserToGroup would be a privilege escalation, not a fidelity gap. What remains uncovered is the error return on a state read, which an in-memory state manager cannot produce.
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.
Why
SimulatePrincipalPolicy(#579) cannot be built without this. AWS is explicit: "If youspecify a user, then the simulation also includes all of the policies that are attached to
groups that the user belongs to." Substrate had no way to attach a policy to a group, no
way to put a user in one, and no evaluation that read group state — so a user simulation
without this would be wrong rather than partial.
The gap was wider than #579 needed. Only
CreateGroup,GetGroup,DeleteGroupandListGroupswere routed, andGetGrouppassediamUserListXML(nil)unconditionally: agroup was observably always empty no matter what state held.
What ships
Eleven operations, each mirroring the user/role handler that already existed:
AddUserToGroup,RemoveUserFromGroup,ListGroupsForUser,AttachGroupPolicy,DetachGroupPolicy,ListAttachedGroupPolicies,PutGroupPolicy,GetGroupPolicy,DeleteGroupPolicy,ListGroupPolicies.GetGroupreports real members, sorted andpaginated by
Marker/MaxItems.Membership is stored on both sides —
group_users:<group>anduser_groups:<user>—because both directions are read by an API. Every write goes through one pair of functions
so the two sides cannot come to disagree; that is the v0.99.0
saveAccountlesson appliedbefore it could bite. Both writes are idempotent, matching the reference, which declares
NoSuchEntityfor the group and the user but nothing for the membership itself.Group policies reuse the existing storage exactly. Managed attachments go to
group_policies:<name>through the sameloadPolicyList/savePolicyListpair; inlinedocuments go through the already entity-type-parameterized
putInlinePolicyfamily.Nothing invents a second way to store a policy — that is what lets
loadPoliciesForPrincipalread a group's policies with the code it already had.Referential integrity on both sides of the index.
DeleteGrouprefuses withDeleteConflict409 while members or attached policies remain ("The group must not containany users or have any attached policies");
DeleteUserrefuses while the user belongs to agroup, naming which one. A delete that skipped either check would leave one side of the
index naming an entity that no longer exists, and that dangling membership is read on
every request.
The two-loader trap
IAMPlugin.authorizeloads its own document set independently ofAuthController.loadPoliciesForPrincipal. Teaching only one about groups would haverecreated #411 exactly: one ARN, two loaders, two opposite answers. Both learned the arm,
and
TestGroupPolicy_BothLoadersAgreeasserts they answer the same on the same input, sothey cannot drift apart later.
Fixed as fallout
All four inline-policy handlers branched on
entityType == "role"with adefault:armthat read
role:state for the existence check while emittingUserNamein the response.Any third entity type would have looked itself up under the wrong prefix and answered with
the wrong element name. One helper now maps type → (entity name, operation suffix), and an
unrecognized type yields an empty name, which every caller already refuses with
ValidationError.TestIAMGroups_PutGroupPolicyRefusesUnknownGrouppins it by creating arole named
devsand asserting a group policy ondevsis stillNoSuchEntity.Verification
gofmt -l .,go build ./...,go vet ./...,golangci-lint run ./...→ 0 issuesmake test(race) green;make coverage— emulator 82.3%, total 81.6%go vet -C test/e2e ./... && go test -C test/e2e ./...greenemulator/iam_groups_test.go(API shapes + a query-protocol wire test),emulator/authz_groups_test.go(the authorization half), andtest/e2e/journey_iam_groups_test.godriving the whole sequence through the real SDK —the level that catches an unroutable operation, which is what Service Quotas: the increase-history operation is unreachable from any SDK #636 was.
loader in turn, a one-sided membership write, the
"group"arm dropped from the inlineentity helper, the
DeleteGroupmember check disabled, andGetGroup's paginationbypassed.
Compatibility
A group's policies now apply to its members' requests through
CheckAccess, so a fixturewhose user belongs to a group carrying a policy starts being allowed — or denied — by it.
In practice nothing existing moves: before this release no operation could put a policy on
a group, so a fixture can only be affected if it wrote group policy state directly.
Prerequisite for #579; does not close it — the simulator itself lands next.