~ knotless Search/
↑↓ move↵ open⇧↵ all results
0
0

Roles, permissions and memberships are written as the group

Merged
Merged chadtmiller.com asked to merge into main from chadtmiller.com/group-host:proposal/writes-members

What changes

Roles, grants and memberships are records written as the group. An app with a session for the group writes fyi.opensocial.role, the fyi.opensocial.permissions record and fyi.opensocial.membership in the members space through com.atproto.space.createRecord, putRecord, deleteRecord and applyWrites. putRole, deleteRole, assignRoles, admitMember and ejectMember are gone: their routes, handlers, lexicons and MCP tools. requestJoin, cancelJoinRequest, getJoinRequest, leaveGroup, listJoinRequests and denyJoinRequest stay.

What a write needs. The session's scope must name each write, and the member who signed the app in must hold, at the time of the write, group.configure for roles and the permissions record, and admit, role.assign or eject to create, change or delete a membership. Those three actions are now space scopes on memberships in the members space (space:fyi.opensocial.members?skey=self&collection=fyi.opensocial.membership&action=create|update|delete). A scope over every collection, and include:fyi.opensocial.manageMembers, carry all three. The host checks each write in member_writes.rs, keeping every rule the methods had:

  • A role's key is 64 characters at most. A role goes only once nobody holds it and no grant names it (RoleInUse). An app deletes the role and writes the permissions record without its grant in one applyWrites.
  • The permissions record stays at self and is never deleted, with one grant per role. A writer changes only the grants of roles they may assign, or of a new role that nobody holds and no grant names (NotAssignable). A scope they add must be one their own roles hold, as written or within one they hold, with our permission sets read as the scopes they list (ScopeNotHeld). A role they add to an assignable list must be one they may assign, or a new one. Each named role must be defined.
  • A membership is kept at its member's DID and holds member (MemberRole). It names only defined roles.
    • Creating one admits someone waiting to join, and decides their request. Its roles must be ones the writer's admit grants may give. Nobody who has not asked is made a member this way (JoinRequestNotFound).
    • Updating one changes a member's roles, each role added or taken away one the writer's role.assign grants may give. It also ends any stale request.
    • Deleting one puts the member out, if the writer's eject grants may give each of their roles. Their space credentials are revoked before the delete commits, so if revoking fails they stay a member and the write can be sent again. Once it commits, their OAuth and assistant grants end, their app passwords go, the index forgets them, and an ejectEvent naming who did it goes to the moderation queue.
  • Whatever is written, someone is still left holding a role that configures the group (LastConfigurer).

The writes of one applyWrites are each checked against the records as the writes before them left them, under the commit's lock.

Shapes. The permissions record's grants are now the proposal's defs#groupGrant: scopes and assignable are lists of strings. role takes the proposal's 2,000-grapheme description. getGroup's roleView gains default. The founding admin may now assign admin and member, as the proposal's creator role "can assign every role".

Tokens for the members space. At approval, the members space counts what the member's grants let them write there, so a narrow scope such as eject's alone is kept. getGroupAuth for the members space gives a space scope for each of those collections, and no repo scope.

The console writes as the group with a group token for the members space. On a group's page, admitting, giving roles and putting someone out each write the membership. On the settings page, defining a role writes the role and the permissions record at once, with the role added to what the definer's configuring roles may give. Taking a role away deletes the role and its grant. web/src/lib/actions.ts maps each action to its scope, and asGroup.ts gains applyAsGroup and membersOf.

MCP. The removed tools are replaced by putRole, deleteRole, putPermissions, putMembership and deleteMembership, entries in the RECORDS list of record tools (Kind::Record), with schemas from the record lexicons. A put takes the record's own fields, createdAt included, and an rkey: a role's id, or a membership's member DID. The permissions record is always at self. A delete takes the rkey. Each makes the write the member's own group session for the members space would make (record_as, then write_as), with the scope group_scope gives the member's roles now, under the same rules.

The command. membership assign and eject write the membership as the group, with GroupSession. --reason is gone. seed makes its moderator role with one applyWrites.

Why

The host follows the opensocial proposal, in which apps write the group's records through com.atproto.space.* and the host enforces each record type's meaning ("Writing a requester's membership approves their request", "deleting one ejects the member"). These are the members space's records. The proposal requires the checks against granting more than one holds. The exception for a new role is what lets anyone set up a role at all: under the proposal's rule alone, a role made after the group exists could never be granted or given by anyone. A role nobody holds and no grant names gives nobody anything, so letting its creator grant it what they hold themselves escalates nothing. The host still refuses a membership for someone who has not asked, so that, as before, nobody becomes a member without asking or an invite.

How it was checked

  • members: a revocation that fails leaves the membership and the queue as they were. Each rule of the old putRole, deleteRole, assignRoles and ejectMember tests, now as record writes: keys, lexicon limits, RoleInUse, LastConfigurer (giving up configure, last admin stripped or put out, a configuring role nobody holds), NotAssignable for grants, roles given and roles listed, ScopeNotHeld, a new role made and granted in one batch, a writer whose roles shrank (403), and a put-out member's credentials revoked, apps ended, index forgotten and ejection queued. covers is checked over repo, space, manage, rpc and blob scopes.
  • joining: admitting by writing a membership, with refusals, a stale request, and a gatekeeper who may admit but not give roles.
  • group_tokens: a members-space token's scope and collections, and refusal for a member with no grant there. assistants: each record tool, and their refusals. rbac, oauth, oauth_scope, tokens and moderation follow the new scopes. The command's tests on the reference PDS: assign, eject, LastConfigurer, and an outsider's 403.
  • cargo test --workspace (with the reference PDS), clippy, fmt, node harness/lexicons.mjs, layers.mjs, docs.mjs and npm run check, all run here. The e2e flows (admit, give roles, put out) and the coverage gate are left to CI.

Shortcomings

  • An ejection keeps no reason now: deleteRecord has nowhere to carry one, and the proposal's ejectEvent has none.
  • Deleting a membership that is already gone answers 200 and does nothing, where ejectMember said NotAMember.
  • Taking a role away leaves it in other grants' assignable lists. Such a grant can still be changed, but a role of that name made again is not new.
  • listJoinRequests and denyJoinRequest still take the member's service auth, not a group session as the proposal has them.
  • The console's role editor offers only the host's actions. Scopes it does not show are kept as they were.

Review

Start at crates/group-host/src/member_writes.rs (members_rules, Writer::permissions, leaving), then token_writes.rs (may_space, write_as) and scopes.rs (covers).

🤖 Generated with Claude Code

Approved

This moves roles, the permissions record and memberships to com.atproto.space.* writes as the group. The host checks each write in member_writes.rs and does what it means: admitting, changing roles, or ejecting. The console, the MCP tools and the command follow.

I read member_writes.rs, the token_writes.rs and scopes.rs changes, and the console's settings/+page.server.ts, actions.ts and asGroup.ts. I did not read the other 48 files, the tests, docs and lexicons among them.

I found no logic hole in what I read:

  • The fresh exception only covers roles nobody holds and no grant names. A writer can only add scopes their own roles cover.
  • LastConfigurer and RoleInUse are checked against the end state of the batch.
  • Create requires a pending join request.

Needs your attention before merge:

  • e2e fails on defining a role (flows.spec.mjs:240). After "Define the role" with invite checked, no .roles li for "Ride leader" appears. The flows after it did not run, so the "signing an app in as her group", assistant and moderation flows are unverified. The cause is probably in the new role action in the settings page. Either the write is refused, or the form's response doesn't make the page reload.
  • test was still running when I looked, so the 100% coverage gate is unverified.
  • Check this against a refused update: in members_rules, an Update of a membership with no current record falls back to empty current roles (unwrap_or_default). Its admit and join-request check is skipped, and only role.assign is asked. I expect the repo layer to refuse an update of a record that isn't there, including through putRecord's create-or-update resolution. A test with a writer holding only role.assign would settle it.
crates/group-host/src/member_writes.rsline 382Outdated

These lines can no longer be read.

review.knotless.dev

If rkey has no membership, current is empty and only role.assign is checked, so the admit and JoinRequestNotFound rules are skipped. Please add a test that a writer holding role.assign but not admit cannot make a member this way, with putRecord and applyWrites.

Approved

This round adds a merge from main and a test for an assistant's refused method. I looked at what my last round raised.

  • e2e: it failed at f647fcd on defining a role. At f57a1d8 it passed, flows included, so that is fixed. At b8167bf the e2e run was still going when I looked.
  • Coverage: test at f57a1d8 failed the coverage gate. The only uncovered lines were assistants.rs 807-809 and 830-832. The latest commit is aimed at exactly those. The test run at b8167bf was still going when I looked, so the 100% gate is unconfirmed until it finishes. This is enforced by the check, so I'm not holding the approval for it.
  • Update with no current record: I couldn't find the test I asked for. Update in members_rules still falls back to empty current roles (member_writes.rs:382), so a writer holding only role.assign would skip the admit and JoinRequestNotFound checks. This is only a hole if the repo layer lets an update through for a record that isn't there. I couldn't confirm either way. The new JoinRequestNotFound cases in members.rs and joining.rs all go through create or put with an admit holder. A test with a role.assign-only writer using putRecord and applyWrites on a non-member would settle it. Please add one, or make Update of a missing membership an error in the rule itself.
crates/group-host/src/member_writes.rsline 382Outdated

These lines can no longer be read.

review.knotless.dev

Still falls back to empty current roles when there is no record. Please test that a writer with role.assign but not admit cannot make a member this way, through putRecord and applyWrites. Or refuse an update of a missing membership here.

Approved

This round's new commit makes ejection revoke the member's space credentials before the membership delete commits. I read leaving and members_written in member_writes.rs. A revoke failure returns an error before any write, so the member stays and the write can be sent again. The order is right.

Update with no current record: I withdraw this one. Repo::check in repo.rs refuses an Update when no record is at the path ("there is no record at …"), so the unwrap_or_default fallback at member_writes.rs:382 can't be reached with a missing membership. That holds for putRecord too, since it resolves to Create when no record exists, and Create needs a pending join request. A test for a writer holding only role.assign would still be nice, but I'm not asking for one.

Checks at d61104b:

  • check fails at rust-lint / fmt, so clippy was skipped. Run cargo fmt and push. The check enforces this, so I'm not holding approval for it.
  • e2e, docs and lexicons pass.
  • test and web were still running when I looked. The 100% coverage gate is unconfirmed.

I did not re-read the other files this round.

Approved

This round's only new commit is a formatting fix. I did not re-read the code, since my earlier rounds covered member_writes.rs, token_writes.rs, scopes.rs and the console files.

I asked for cargo fmt last round, and it is done. Every check at 53148a1 passes: check (fmt and clippy), test (coverage gate included), e2e (flows included), web, docs and lexicons. That settles the two things I couldn't confirm earlier, the 100% coverage gate and the e2e flows. The "update with no current record" concern I already withdrew, because Repo::check refuses an update when no record is at the path.

I have nothing further to ask for.

Merged as 425d1e0