chadtmiller.com/group-host
atmosphere group host
Membership
A group has no owner, so who may do what in it has to come from records the group keeps. Those records change as people join, leave and take on new jobs, and each change has to take effect at once everywhere, in the console and in every app a member signed in as the group.
Members and the members space
A space is a set of records that only the accounts its policy names may
read, unless the policy sets publicRead
(spaces). A member is anyone
with an org.atgrp.membership record, keyed by their DID, in the
group's members space (at:space/<group>/org.atgrp.members/self). Its
policy gives the member role read and write, and updateSpace refuses
to change that or make it public. So every member's tools can read the
roster and no outsider can.
A membership lists the member's roles by ID (["member", "admin"]).
Every membership holds member (MemberRole otherwise), and putting
someone out means deleting their membership. The member keeps their own
side, an org.atgrp.confirmation in their own repo in the space, which
changes nothing they may do.
Roles and memberships are ordinary records written as the group. The
host has no methods of its own for changing them. It writes a
membership itself only when someone joins, and for the founder and
stewards when a group is made, and deletes one itself when someone
leaves. getGroup gives a member just
memberCount, so showing a group's size doesn't mean fetching the
roster.
Roles and what they grant
A role is an org.atgrp.role record in the members space, keyed by its
ID (lowercase letters and -). Besides a name and description, it holds
its grant: a list of permissions, in atproto's permission syntax
(permissions), and a list of the
roles its holders may assign (canAssign).
The host's methods ask about eleven actions, such as invite, eject
and group.configure, and a permission answers each. admit,
role.assign and eject are the create, update and delete of a
membership, so any permission that writes memberships carries them. A
permission set counts as
every permission it lists, so authManageMembers carries all four
member actions (invite, admit, role.assign and eject). A role
may also carry repo:<collection>, a
collection of the group's public repo its holders may write. The API
reference lists the actions and sets.
Roles add up. A member may do whatever any one of their roles grants, with no deny, precedence or hierarchy, so every "may they?" is a lookup.
canAssign limits a member's power over other members. It names the
roles a role's holders may give, take away, or eject holders of, and
* means every role, including ones made later. It counts only through
the role that carries the action. Whom you may assign comes from your
roles granting role.assign, whom you may eject from those granting
eject, and the roles you may admit someone with from those granting
admit.
A new group starts with two roles. admin may do everything: it carries
authManageAdmin, permissions over every space and the public repo, and
canAssign of *. member is the default role and carries nothing.
The founder and stewards hold both.
Writing roles and memberships
An app changes roles and memberships by writing records as the group
with com.atproto.space.createRecord, putRecord, deleteRecord or
applyWrites (spaces data),
and the token's scope must name each write. The console and atgrp use
a group token for the members space (signing in).
The member who signed the app in may have lost a role since, so at each
write the host checks that member's roles as they stand. A membership
takes admit to create, role.assign to change and eject to delete.
A role takes a permission that writes roles in the members space, which
authManageAdmin has. A group's writes are made one at a time
under a lock, so the roles a write was checked against still hold when
it's made.
Nobody may give away more than they hold. Changing a role's grant takes
the right to assign that role, unless the same batch makes it. A
permission added must be one the writer's roles hold, as written or
within one they hold (ScopeNotHeld). A role added to canAssign must
be one the writer may assign, and * only if they may assign every role
(NotAssignable). Taking something away just needs the right to change
that role. So a member may make a role and grant it what they hold, but
nobody can give it out until a role's canAssign names it.
Some member must always hold a role granting group.configure
(LastConfigurer), and a role goes only once nobody holds it
(RoleInUse). In one applyWrites, each write is checked against the
records as earlier writes left them, and against the writer's roles as
they were before any. The batch lands whole or not at all.
The change takes hold at once. A member whose roles no longer let them
write a space leaves its writers. An app grant whose member no longer
reads a space loses what it got there, its credentials revoked
(credentials). getGroup tells an
editor in advance which permissions and sets they hold enough of to give.
Joining
Someone asks to join with requestJoin, and the group's joinPolicy
(in its org.atgrp.config) decides what happens. With open, they get
in. With approval (the default), they wait for a member who holds
admit. With invite, only an invitation gets new people in. A request
left waiting from before the policy changed still waits, and an admitter
may still let that person in.
A request isn't a record, since the asker isn't a member and the members space is for members. The host keeps it in its own database, one per group and asker, and deletes it once it's decided. So a denial looks like no request, and the asker may ask again.
An admitter lets someone in by writing their membership as the group,
with the roles it names, and only someone with a waiting request can be
admitted that way (JoinRequestNotFound). Someone let in by
requestJoin itself gets the default roles: those marked default, or
member if none is, and always member. Getting in by any route ends a
waiting request. requestJoin takes 10 per person in 5 minutes, and 100
a day.
Invites
An invite means the group has already said yes. It has to reach someone
outside the group, so the group writes it where they already look, their
inbox (at:space/<invitee>/org.atgrp.inbox/self). That's a space under
their own DID at their own PDS. Their app makes it with
createSpace at their PDS (a permission authParticipate carries),
under a com.atproto.memberspace.policy that sets publicWrite and
names no members. So any group may write there and only its owner reads
it. The console never makes an inbox, and shows invites from the host's
list instead. The invite is an org.atgrp.invite
record in the group's repo in that inbox, with an optional message and
expiry.
An app invites by writing that record as the group, and takes it back by
deleting it. The member who signed the app in must hold invite at each
write. There's one invite per group and person at a time, so writing one
while another waits answers with the waiting one, unless it's written at
the same key and replaces it. The host tells the invitee's PDS of the
write through the same outbox as any write to a space another PDS keeps
(hearing of writes).
The inbox is the invitee's to read, so the host keeps its own list of
the invites it has sent, in step with each write. When the invitee
calls requestJoin, the host redeems their invite from that list,
whatever the join policy. It writes the membership first and takes the
invite back after, so a failed join leaves the invite waiting. The
invitee refuses with declineInvite, and the group may invite them
again. An expired invite admits nobody, and the host takes it back
within the hour, after which the group may invite them again. Some apps
can't read a person's inbox, so
getActorInvites lists the caller's waiting invites from groups here.
Leaving and being removed
A member leaves with leaveGroup. A holder of eject puts a member out
by deleting their membership as the group, if every role the member
holds is one the ejecter may assign.
Either way, the host revokes the space credentials the group issued
them, ends the OAuth grants they approved for the group and their MCP
clients' grants, with every session those began, and drops their app
passwords for the group. It takes them off the writers of each of the
group's spaces and tells each space's syncers. Leaving ends all of that
before the membership goes. An ejection revokes credentials before the
membership goes and ends the grants and app passwords after. Either way,
if revocation fails they're still in and it can be tried again.
Revocation is immediate for repos on this host, and writers on other
PDSes are sent com.atproto.space.notifyCredentialsRevoked
(space sync). With no roles, no
space's policy grants them anything.
What they wrote stays theirs, in their own repos at their own PDSes, though the group's index forgets it at once. An ejection is kept in the group's moderation queue with who removed them (the queue), and leaving keeps nothing.