Skip to content

feat(iam): groups have an observable effect (#579) - #641

Merged
scttfrdmn merged 2 commits into
mainfrom
feat/iam-groups
Aug 14, 2026
Merged

scttfrdmn merged 2 commits into
mainfrom
feat/iam-groups

Conversation

@scttfrdmn

Copy link
Copy Markdown
Owner

Why

SimulatePrincipalPolicy (#579) cannot be built without this. AWS is explicit: "If you
specify 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, DeleteGroup and
ListGroups were routed, and GetGroup passed iamUserListXML(nil) unconditionally: a
group 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. GetGroup reports real members, sorted and
paginated by Marker/MaxItems.

Membership is stored on both sides — group_users:<group> and user_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 saveAccount lesson applied
before it could bite. Both writes are idempotent, matching the reference, which declares
NoSuchEntity for 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 same loadPolicyList/savePolicyList pair; inline
documents go through the already entity-type-parameterized putInlinePolicy family.
Nothing invents a second way to store a policy — that is what lets
loadPoliciesForPrincipal read a group's policies with the code it already had.

Referential integrity on both sides of the index. DeleteGroup refuses with
DeleteConflict 409 while members or attached policies remain ("The group must not contain
any users or have any attached policies"); DeleteUser refuses while the user belongs to a
group, 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.authorize loads its own document set independently of
AuthController.loadPoliciesForPrincipal. Teaching only one about groups would have
recreated #411 exactly: one ARN, two loaders, two opposite answers. Both learned the arm,
and TestGroupPolicy_BothLoadersAgree asserts they answer the same on the same input, so
they cannot drift apart later.

Fixed as fallout

All four inline-policy handlers branched on entityType == "role" with a default: arm
that read role: state for the existence check while emitting UserName in 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_PutGroupPolicyRefusesUnknownGroup pins it by creating a
role named devs and asserting a group policy on devs is still NoSuchEntity.

Verification

  • gofmt -l ., go build ./..., go vet ./..., golangci-lint run ./... → 0 issues
  • make test (race) green; make coverage — emulator 82.3%, total 81.6%
  • go vet -C test/e2e ./... && go test -C test/e2e ./... green
  • 16 new tests: emulator/iam_groups_test.go (API shapes + a query-protocol wire test),
    emulator/authz_groups_test.go (the authorization half), and
    test/e2e/journey_iam_groups_test.go driving 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.
  • Mutation testing, 6 applied / 6 caught / no survivors: the group arm removed from each
    loader in turn, a one-sided membership write, the "group" arm dropped from the inline
    entity helper, the DeleteGroup member check disabled, and GetGroup's pagination
    bypassed.

Compatibility

A group's policies now apply to its members' requests through CheckAccess, so a fixture
whose 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.

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

codecov Bot commented Aug 14, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 74.00000% with 104 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
emulator/iam_groups.go 70.09% 32 Missing and 32 partials ⚠️
emulator/iam_plugin.go 81.81% 12 Missing and 10 partials ⚠️
emulator/authz.go 72.30% 8 Missing and 10 partials ⚠️

📢 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.
@scttfrdmn
scttfrdmn merged commit 5042992 into main Aug 14, 2026
12 of 13 checks passed
@scttfrdmn
scttfrdmn deleted the feat/iam-groups branch August 14, 2026 23:36
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.

1 participant