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

Groups keep repos in spaces, read with an authority's credential

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

What changes

Each group has a KEM key. A group's did:plc document now names a P-256 #atproto_kem key beside its signing key. A space's syncer agrees a secret with that key, and the host vouches for what it serves under that secret. The key is kept with the account. The first migration gains the column instead of adding a new migration, because no host has run yet.

Groups keep repos in spaces. Host::space_write writes a group's records into a space as one revision. It runs the same checks as the public repo: the data model, $type, blobs uploaded to the group. Records go in the store's new space_repo, space_record, space_op and space_record_blob tables. The commit is the digest of the records' LtHash, updated element by element. A blob is forgotten once no record references it, in the public repo or any space.

Each write is told to the space's authority. After a write, the host sends com.atproto.space.notifyWrite to the authority's PDS, with service auth signed by the group for <authority>#atproto_pds. If the authority doesn't hear of it, the write still stands.

The space read methods, for a credential's holder.

  • com.atproto.space.{getRecord, listRecords, getRepo, getLatestCommit, listRepoOps, getBlob, listBlobs} answer only a request that brings a space credential. The credential must be issued by the space's authority, for that space, unexpired and unrevoked. The request must name the repo as its audience and be HTTP-signed with the credential's key.
  • The reader's Atproto-Space-Want-Mac key share agrees a secret against the group's KEM key. The answer carries the commit's MAC, or the record's.
  • com.atproto.space.notifyCredentialRevoked, with service auth from the authority, revokes credentials until they would have lapsed.

atproto gains space::SpaceRef, the space alpha's at://<did>/space/<type>/<skey>.

docs/design/spaces.md explains the repo host's side. The plan marks this step done.

Why

This is the next part of step 4: being the repo host for a group's repos in spaces. A group writes into its own spaces and others', so this side comes before the authority side. The authority side (4c) and the groups (4d) build on it.

Compared with the prototype's pds/api/space.ts:

  • The repo-host methods come over as they are, less what needs signing in. That means writes over XRPC, an account reading its own repo, listSpaces and clearRecords; they come with step 6.
  • notifySpaceDeleted is left out: this host syncs no other authority's spaces, so it has nothing to do with it.
  • Ops are kept by path in one table, rather than by URI as the reference does. A path orders as a URI does within one repo.

How it was checked

crates/group-host/tests/spaces.rs ports the cases the prototype's and the reference's space tests hold. It uses a fake authority: a DID on the fake PLC whose PDS records each notifyWrite.

  • Writes:
    • the commit is the records' set hash;
    • the authority hears of each write, signed as the group, for its #atproto_pds;
    • a write stands when the authority refuses, has no PDS, or isn't on the directory.
  • Reads:
    • getRepo is the STAR archive the vectors check, with its commit MAC;
    • getLatestCommit and getRecord carry their MACs;
    • listRecords pages in path order, with collection, reverse and excludeValues;
    • listRepoOps pages with a cursor and since, leaves the value off a superseded op, and puts the commit only on its last page;
    • blobs are this space's only, and gone with their record.
  • Refusals, one by one:
    • a missing, malformed or expired credential;
    • one for another space or issued by someone else;
    • an unknown authority, or a key that isn't the authority's;
    • another audience, a request signed by another key or unsigned, or no key share;
    • a revoked credential, and every refusal of notifyCredentialRevoked.
  • just cov: 100% of lines and functions. Clippy is clean.

tests/interop.rs adds a_groups_repo_in_a_space_of_the_reference_pds, against the alpha at 11c5d98 in CI:

  1. Bob makes a memberspace on the reference PDS and adds the group as a writer.
  2. The group writes there.
  3. The reference's listRepos shows the group's revision and digest as the host computed them.
  4. A credential the reference issued to Bob reads the repo from the host, and the MAC and archive match.

This test runs only in CI. The local alpha checkout is older than 11c5d98 and has no createSpace.

Shortcomings

  • A notifyWrite the authority doesn't get is not retried. The reference PDS retries for a day.
  • An authority must be a did:plc: the host resolves DIDs only through the PLC directory.
  • The authority's key is read from the directory on every read; nothing is cached.
  • No reader may write over XRPC yet, and a group can't read its own repo through an app. Both come with signing in.

Review

Start with crates/group-host/src/space_api.rs's credential: that check decides who reads a group's records.

🤖 Generated with Claude Code

Approved

I read only crates/group-host/src/space_api.rs. I did not read the other files in the diff, so the rest of the pull is unreviewed: the store migrations and tables, space_write, the notifyWrite call, the atproto additions, the docs and the tests.

credential holds up. It checks these in order:

  • iss must equal the authority named in the credential's sub.
  • The signature is checked against the PLC directory's key for that issuer.
  • sub must match the requested space.
  • The atproto-space-audience header must equal the repo parameter.
  • The request must be signed with the key the credential is bound to (cnf).
  • The credential's jti must not be revoked.

asked then confirms the repo is hosted here. notify_credential_revoked requires service auth from the space's authority and a hosted audience, and it caps a batch at 100 credentials.

I found nothing that needs changing. I did not run the tests or look at CI results.

Approved

This is round 2. The only change since my last review is the final commit, which edits the plan. Nothing I raised earlier is outstanding. The test and check workflows were still queued when I looked, so I haven't seen their results. I did not run anything.

Last round I read only space_api.rs. This round I also read space.rs, store.rs, repo.rs, lib.rs and api.rs, and found nothing that must change:

  • check was pulled out of repo.rs without changing the public repo's behaviour.
  • space_commit serialises writes with the writing lock and moves the head with a compare-and-set on rev. A raced write fails and changes nothing.
  • The set hash is updated element by element, removing the old CID on an update or delete.
  • FORGET_ORPHAN now also checks space_record_blob, so a blob that a space still references survives a public-repo delete.

I did not read the other files in the diff: the atproto crate additions, tests/spaces.rs, tests/interop.rs, the test helpers and the docs. They are unreviewed.

One thing to fix, though I'm not blocking on it. Host.http is a bare reqwest::Client::new() with no timeout. space_write awaits notify_write before it returns. An authority PDS that accepts the connection and never answers will hang the caller indefinitely, even though the write is already committed. Give that request a timeout, for example .timeout(Duration::from_secs(10)) on the notifyWrite call. The new Host.http use and the directory lookups on every read have the same exposure.

crates/group-host/src/space.rslines 140 to 146Outdated

These lines can no longer be read.

review.knotless.dev

No timeout here. A hung authority PDS blocks space_write after the commit is already stored. Add a per-request timeout; the failure is already logged and ignored.

Approved

Round 3. The only change since my last review is the last commit. It answers my timeout comment: Host.http and the PLC Directory now use a shared client() with a 10-second OUTGOING_TIMEOUT. A test with a PDS that accepts the connection and never answers checks that space_write returns after about the timeout. The design doc now says the same.

I found nothing that must change. I did not run the tests or look at CI results. One small note: that test sleeps about 10 seconds in real time, which makes the suite slower. That is acceptable.

I have not read the atproto crate additions, the rest of tests/spaces.rs, tests/interop.rs or the other test helpers. They remain unreviewed.

Merged as d258675