~ knotless Search/
↑↓ move↵ open⇧↵ all results
0
0
171 lines · 8.5 KB Raw History

Spaces

A group's private records don't live in one place. Each member writes them on their own PDS, wherever that is. Yet someone has to decide who reads and writes, give readers credentials, and know what was written so a page can show it.

atproto's answer is a space, a non-public store of records whose authority DID decides who reads and writes. Each writer keeps their own repo in it on their own PDS (spaces), and a space is named at:space/<authority>/<type>/<skey> (space data). A space's type is any NSID, but a member's PDS grants an app a type only once it can read that type's published schema. The host is the authority of each group's spaces. It also keeps the group's own repo in each space the group writes in, as any PDS does.

A group's spaces

Creating a group makes two spaces that come and go with it. Meta (at:space/<group>/org.atgrp.meta/self) holds org.atgrp.about and org.atgrp.config. Members (.../org.atgrp.members/self) holds roles, memberships, the labeler and rules. A token writes only those collections there, plus labels, which are records in the space they label (moderating).

Apps find a group's other spaces in members, where each one not unlisted has an org.atgrp.space record in the group's repo. The host keeps that list. Nobody writes it or a com.atproto.space.policy as a record, so both change only through the space methods. While meta is publicRead, the group's public repo holds an empty org.atgrp.declaration.

Deciding who reads and writes

Members come and go, so a space's policy (org.atgrp.policy) speaks of roles, and a new member needs no policy change. It has publicRead, unlisted and one grant per role. A grant's read lets the role's holders read. Its write lets them write in their own repo and name, which makes them one of the space's writers. Its permissions are space scopes they hold acting as the group, in that space only. Someone reads if the space is publicRead or a role of theirs has read. The group itself may always read and write its own spaces. The host publishes each policy in its space as the group's com.atproto.space.policy record, so every reader sees the rules.

Meta is read by member and admin, and by anyone unless the creator sets metaPublicRead: false. Admins write there as the group, and nobody in their own name. The members space is read and written by member, which every member holds, so each member's confirmation syncs. That's fixed, with publicRead off, since nobody but members reads the roster. A new group's admin holds every space permission (membership). A space moved here keeps its per-account grants (moving). While a group is switched off, the host lets no one in, the group included.

Making, changing and ending a space

The group calls atproto's createSpace, updateSpace, deleteSpace and getSpace, through an app signed in as the group (signing in) or a token from getGroupAuth. The session's scope must hold the manage= operation, and the member's roles must allow it at that moment. Making a space needs space.create. Changing one needs space.configure or manage=update in its policy, and ending one space.delete or manage=delete. The API reference lists the methods.

Making a space is all or nothing, so if its policy can't be published, the host ends it again. updateSpace replaces the policy whole, then removes writers who may no longer write and stops apps whose member no longer reads. A caller can't grant more than they hold. They change grants only of roles they can assign, add only permissions they hold, and give read, write or publicRead only if they have it there.

Giving out credentials

A reader asks the authority with authorizeSpaceSync for a short-lived credential bound to its key, and shows it to each writer's PDS (space sync). Here it's a JWT the group signs for one space, lasting ten minutes. A person proves who they are with a delegation token their own key signs, and one token buys one credential. Without one, the host serves only publicRead spaces. A space the caller can't read answers SpaceNotFound, like a missing one, so its existence doesn't leak. The host ignores clientAttestation, since no space here admits by app.

The host records each credential it gives a person. Removing a member revokes every unexpired one they hold to the group's spaces, at once for repos here and by notifyCredentialsRevoked to other writers' PDSes, best effort. Each renewal is checked against the policy again, so a role or policy change that takes away read holds once the reader's current credential runs out, within ten minutes.

Hearing of writes

The host keeps each space's writer set, each writer's latest revision and digest. A writer's PDS reports a write with notifyRepoUpdate, by service auth from the writer's account. The host takes it only for a repo the space lets write, and each change gets a new space revision. A writer who loses write is removed at once, and being put out removes them from every space of the group.

A sync service reads a space for an app. It registers to hear of changes by passing notify to authorizeSpaceSync, and a new endpoint must echo a challenge through confirmRegistration first. Each authorization renews the registration. Each change goes to every live registration as notifySpaceUpdate, once, best effort, and a syncer that misses one reads on with listWriters. A lapsed registration is told so at the next change, retried for three days.

The group is a writer too, in its own spaces and in others, such as an invite in the invitee's inbox space (membership). Its repo there has records and a revision but no signed tree, and a set hash over the records names its state. For its own spaces the host records each write at once, internally. An authority elsewhere hears of it by notifyRepoUpdate, retried for a day.

Reading a space through the host

A page wants a space's records in one request, not one per member's PDS, so the host keeps an index of each group space. When the writer set's digest moves, the index re-reads each changed writer, and it checks every space each minute. It reads a remote writer with a credential the group gives itself. It reads on from the last revision with listRepoOps, or reads the whole repo with getRepo if that fails, and each record must match its CID.

listSpaceRecords brings the index up to date (waiting at most 5 seconds), then answers newest first. getSpaceBlob fetches a file only from a writer that may still write, so no caller can aim the host at a server of their choosing. The index never decides who reads. Both methods check the policy on every call.

An app signed in as the group gets a delegation token from getDelegationToken, then calls authorizeSpaceSync. Its scope must hold read on the space, and its member must read it at that moment. The credential is the group's, so it reads everything there, but only while the app's grant lasts and its member reads. When either ends, the host revokes its credentials and withdraws its registrations.

getRecord, getRepo, getLatestCommit and listRepoOps on the group's own repo sign their answer with a secret agreed against the group's #atproto_kem key, which proves to that reader alone that this host answered.

Reaching other servers

A member's DID document (DIDs) or a syncer can name any server. So the host reaches them all through a guard that allows only public addresses over https and follows no redirects, and no one can aim it at its own network. When PUBLIC_URL is http, for local work, the guard allows any address.

The host keeps a member's DID document 5 minutes, and fetches it again when a kept key rejects a signature. It reads a document up to 256 KiB and refuses a did:web with a path.

Ending a space or a group

deleteSpace unlists a space and ends it. The host forgets its index, writers, registrations, grants, credentials and the group's own repo there. It remembers only that the space was deleted, so authorizeSpaceSync answers SpaceDeleted until the address is made again. Every registration is told spaceDeleted, retried for three days. Members' repos in the space stay on their PDSes, since they're theirs. Deleting a group tells each registration once, best effort, and a syncer that misses it learns at its next authorization.