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

Roles are defined and given; members are put out or leave, and read no more

Merged
Merged chadtmiller.com asked to merge into main from chadtmiller.com/group-host:host/membership

What changes

Roles are defined and given; members are put out, or leave. These are new methods in group_members.rs:

  • fyi.opensocial.putRole (needs group.configure) defines or changes a role:
    • its name and words, and whether its people are bots;
    • whether every new member gets it (kept when not said);
    • what it may do, written as the scopes of its actions beside any other scope it held;
    • its public-repo collections (kept when not said), and the roles its holders may give.
  • fyi.opensocial.deleteRole (needs group.configure) takes away a role nobody holds, else RoleInUse.
  • fyi.opensocial.assignRoles (needs role.assign) gives a member the roles named:
    • Each role added or removed must be one the caller may give (NotAssignable), and each must be defined.
    • The member must be one (NotAMember).
    • member goes only by ejecting or leaving (MemberRole).
  • fyi.opensocial.ejectMember (needs eject) puts out a member each of whose roles the caller may give or take.
  • fyi.opensocial.leaveGroup: anyone but the last member able to configure the group may leave.
  • The last role that configures a group keeps that, and its last holder stays (LastConfigurer).

Out is out. A member put out, or leaving, reads the group's spaces no more:

  • The authority now keeps each credential it issues (issued_credential), to whom, until it lapses.
  • When someone loses their membership, their credentials are revoked at once for the repos here. The host of each other writer in those spaces gets notifyCredentialRevoked, signed by the group, best effort.
  • The index forgets what they wrote, and keeps only writers the space still lets write.

The lexicons gain the errors these methods return. docs/design/membership.md is new, and the plan marks this part of step 5 done.

Why

This is step 5's first part, following the prototype's methods/roles.ts, methods/membership.ts and leaveGroup. It changes these:

  • assignRoles refuses a non-member. The prototype wrote them a membership, which admitted them past any admit.
  • Roles given must be defined.
  • deleteRole refuses a held role, as the lexicon's RoleInUse says.
  • Leaving or being put out revokes credentials, which the prototype left to lapse within the hour. I'd noted this as owed since the authority pull.

How it was checked

tests/members.rs covers:

  • Defining roles:
    • the record and grant;
    • kept scopes, collections and the default flag;
    • collections replaced when named;
    • every refusal, including LastConfigurer.
  • Deleting roles:
    • one nobody holds, and one with only a grant;
    • RoleInUse, LastConfigurer, a non-configurer, no role.
  • Giving roles:
    • bounded until the admin's grant may give more;
    • MemberRole, NotAMember, an undefined role, Forbidden, missing fields.
  • Putting out:
    • a moderator may put out only those it may;
    • the membership gone, the credential revoked here, the index state gone;
    • another writer's host told, and a writer with no host holding nothing up;
    • a resync keeping them out;
    • each refusal.
  • Leaving:
    • a member leaves;
    • NotAMember twice;
    • the last admin refused, then allowed once another admin exists.

The address backfill test now finds its migration by what it does, as more migrations come after it. just cov is at 100% of lines and functions, and clippy and just lex are clean.

Shortcomings

  • Revocation reaches other writers' hosts best effort and once. A host that misses it keeps honouring the credential until it lapses, within the hour.
  • A role's grant is still about the host's actions alone. App tokens (revokeMemberTokens in the prototype) come with signing in.

🤖 Generated with Claude Code

Asked for changes

This adds role definition, role assignment, eject and leave. It also records issued credentials, revokes them when someone is put out or leaves, and makes the index drop writers the space no longer lets write. The structure follows the prototype and the revocation flow reads sensibly. I read only the Rust sources, store.rs, authority_api.rs and the eject_member test calls in tests/members.rs. I did not read the rest of tests/, the lexicon JSON or the docs.

Must fix: eject_member has no LastConfigurer check, although the PR says the last configuring role's last holder stays. If the caller's eject grant lists a configuring role as assignable (the usual admin setup), the only admin can eject themselves. The target is then a role the caller "may give", so the NotAssignable check passes and put_out runs. That leaves a group nobody can configure, which is the state leave_group is written to prevent. The tests cover a moderator being refused and ejecting others, but not self-eject or ejecting the last configurer. Apply the same "no other holder of a configuring role" check as in leave_group before put_out, and add a test.

assign_roles has the same gap in a milder form. A sole admin whose role.assign covers admin can remove admin from themselves, or from the last other holder, and leave the configuring role with no holders. The same check would cover it.

Smaller: put_out deletes the membership before it revokes credentials. If revoke_credentials fails, the call returns an error but the member is already out, and their credentials stay live until they lapse. A retry then gets NotAMember. Consider revoking first, or logging and continuing, so the outcome doesn't depend on that error.

crates/group-host/src/group_members.rsline 430Outdated

These lines can no longer be read.

review.knotless.dev

No last-configurer guard here: the only admin can eject themselves when their grant makes admin assignable for eject. Check that another member holds a configuring role, as leave_group does.

crates/group-host/src/group_members.rsline 397Outdated

These lines can no longer be read.

review.knotless.dev

The membership is already deleted when this can fail, so an error leaves the member out with live credentials and a retry gets NotAMember.

Changed:

  • ejectMember and assignRoles now run the same check as leaveGroup, through one helper (keeps_a_configurer): after the change, someone must still hold a role that configures the group. A sole admin can no longer eject themselves or strip admin from the last holder. A test covers both refusals, and both succeeding once a second admin exists.
  • put_out revokes credentials before it deletes the membership. A failed revocation leaves the member in, and the call can be made again.
Approved

Both items from my earlier review are addressed. I read only the Rust in group_members.rs, not the new tests.

  • Last configurer: keeps_a_configurer is now called from assign_roles, eject_member and leave_group. It passes if the affected member keeps a configuring role, or if some other member holds one. A sole admin can no longer eject themselves or strip admin from the last holder.
  • Revoke order: put_out now revokes credentials before it deletes the membership. If revocation fails, the member stays in and the call can be retried.

One small leftover: if space_write for the delete fails after revocation, the member stays in with revoked credentials. That is harmless and a retry works.

Merged as 548cc07