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

Groups are the authority for their own spaces

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

What changes

Groups are the authority for their own spaces.

  • Host::create_space makes a space of a group here, which may be open to all readers.
  • Host::grant and ungrant say who else may read or write it. Host::may decides: the group itself may do anything, others what they're granted, and anyone may read an open space.
  • New tables: space, space_grant, space_writer, space_recipient, spent_token, outbox.

The authority's methods.

  • com.atproto.space.getSpaceCredential issues a credential, bound to the caller's P-256 key:
    • With a delegation token: the token's user gets one if the space lets them read. The token must be signed by that user, for <group>#atproto_pds and this space, and is spent once. A user the space doesn't let read is told there's no such space.
    • Without one: only for an open space.
  • com.atproto.space.notifyWrite is received from repo hosts. The writer's own account must send it, for this authority, with a revision no more than five minutes ahead, and the space must let them write. The writer set keeps each repo's latest revision and digest, and the space's revision when it heard.
  • com.atproto.space.listRepos answers the writer set to a credential's holder, a page at a time.
  • registerNotify and unregisterNotify sign a service up for a day of forwarded writes, at the endpoint its own DID document names. Each write is forwarded to it, signed by the group, best effort.

A write's word to an authority elsewhere is owed until it lands.

  • space_write now keeps an outbox entry and tries it at once.
  • A refusal that may pass (no answer, a 5xx, 408, 425 or 429) is tried again after 10s, then twice as long each time up to an hour, for a day. A loop in serve tries what's due every 10s.
  • A refusal for good is given up.
  • A newer write's notice replaces one still owed for the same repo and space.
  • A space whose authority is a group here hears of the write in the host, under the same write perimeter.

docs/design/spaces.md gains "Being the authority", and the plan marks this step done. The space tests' helpers move to tests/common/spaces.rs, shared by both test files.

Why

This is step 4c. Groups' spaces need an authority, and this host is it. The design follows pds.js's packages/spaces:

  • the outbox's backoff, retryable statuses and one-day deadline (outbox.js);
  • best-effort forwarding (notify.js);
  • single-use delegation tokens;
  • registerNotify resolving the endpoint from the service's own document;
  • a write to a space of its own handled in-process.

The checks on each method follow the alpha at 11c5d98.

It differs from the prototype in one place. The prototype gave every group space a managedspace policy naming the host itself, then answered checkUserAccess in process. Here the host's own grants decide, and there are no space policies or createSpace over XRPC, because a group's spaces are made by the host. The grants are what groups and roles (4d and 5) will maintain.

How it was checked

  • tests/authority.rs covers:

    • Spaces and grants, and what may decides for the group, a grantee, an open space and no user.
    • Credential issuing: issued, and read with. Every refusal: a missing or malformed field, a non-P-256 kid, no token on a closed space, a user not granted, a space not here, a malformed token, a token for another authority or space, one signed by another key or an unknown issuer, and a token spent twice. An open space issues without a token.
    • The writer set: from notifyWrite and from the group's own writes. A stale revision changes nothing. listRepos paging needs a credential. Every notifyWrite refusal is covered.
    • Forwarding: with spaceRev and prevSpaceRev, signed by the group for the service. A refusing syncer holds nothing up, and after unregistering nothing more is sent. Every registerNotify refusal is covered.
    • The outbox:
      • refused, then owed and not yet due; due, then delivered; a refusal for good given up;
      • a newer notice replacing an older one;
      • a day-old notice lapsing; notices that can never land;
      • retry_delay.
    • A group writing where it may not stays out of the writer set.
  • tests/interop.rs adds the_host_as_authority_for_a_member_on_the_reference_pds, against the alpha in CI:

    1. Alice writes into a group's space at the reference PDS, and her PDS's notifyWrite reaches the host.
    2. Her PDS's delegation token buys a credential from the host.
    3. Her PDS accepts that credential and serves her record with a MAC that checks.
    4. The host lists her repo to the same credential.

    start_reachable gives this test a host whose PUBLIC_URL is where it listens. It runs only in CI.

  • just cov: 100% of lines and functions. Clippy is clean.

Shortcomings

  • Deleting a space, and telling its syncers (notifySpaceDeleted), come with groups' deletion in 4d.
  • An account that loses its grant keeps any credential it holds until it lapses (an hour at most). Revoking it, and telling repo hosts, comes with membership in step 5.
  • App allow-lists and client attestations aren't checked: there is no per-space app policy yet.
  • Forwarding to syncers isn't retried, as in pds.js.

🤖 Generated with Claude Code

Approved

This makes the host the authority for its groups' spaces. It adds spaces, grants and may, the five com.atproto.space.* authority methods, a writer set, and an outbox with backoff for writes to authorities elsewhere. In-process handling covers a space whose authority is a group here. I read the source files, the store changes and the space_write rework, and found no blocking bugs. The checks logic looks right: the credential is bound to a P-256 key, delegation tokens are single-use, notifyWrite requires the writer's own issuer and this authority as audience, and a user who may not read gets "no such space". Outbox replacement by newer revision is safe, because delivered and retry match on rev.

I did not read tests/authority.rs, tests/common/*, tests/interop.rs, tests/spaces.rs or the docs diffs. The test and check workflows were still queued when I looked, so the 100% coverage gate and clippy are unconfirmed.

Two notes, neither blocking:

  • registerNotify and unregisterNotify accept any valid credential for the space (as_authority), and any reader can hold one, including on an open space. Any reader can therefore register or unregister other services' forwarding. Please confirm this matches pds.js. If it does not, restrict them to the group or to the service itself.
  • delegated spends the token before the space and read checks run. A request that is then refused with SpaceNotFound has still used up the token. Moving the spend after the may check would avoid that. It costs nothing, since a refused user could not get a credential anyway.
Merged as d8d015c