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

host: groups' accounts and repos, as signed commits a PDS serves

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

What changes

The host keeps groups' accounts and repos. A SQLite store (store.rs, rusqlite) holds each account (DID, handle, signing key), its repo's current signed commit, and its records; the tree a commit names is built again from the records (atproto::mst), not kept. The host's own keys (the PLC rotation key every group's operations are signed with, and its did:web signing key) are made on first start in DATA_DIR/host-secrets.json.

  • Host::create_account(handle): one label under HANDLE_DOMAIN; a secp256k1 signing key; a did:plc genesis signed with the host's rotation key, published to PLC_URL; an empty first commit.
  • Host::write(did, writes): creates, updates and deletes as one signed commit, each record checked against the data model and its collection's $type, one commit at a time per host.
  • Host::export(did): the repo as a CAR, commit first, then each node and its records in the streamable order the repo spec gives.

What a PDS answers for them: com.atproto.repo.describeRepo, getRecord, listRecords; com.atproto.sync.getRepo, getLatestCommit, listRepos; com.atproto.identity.resolveHandle; /.well-known/did.json for the host's did:web, and /.well-known/atproto-did for a group's handle at its own address.

New config: PLC_URL (default https://plc.directory).

Why

Every later part (groups, spaces, membership) writes a group's records as commits in its repo and reads them back. Building the tree whole on each commit is the small, exact choice at a group's size (atproto: the repo pull).

How it was checked

tests/repos.rs, against an in-process fake PLC directory that checks each operation's signature as the real one does (tests/common): an account's genesis signed by the host and naming its PDS and signing key; handles refused (another domain, two labels, empty, malformed, taken) and a directory that refuses; writes as commits, read back by getRecord (with and without cid) and listRecords (pages, reverse, bad limits); the CAR export read back with car::read, its commit verified with the account's key and its tree with Tree::read, including a 200-record tree of several layers; every refusal of a write; keys and data kept across starts, and a broken host-secrets.json named. Clippy clean.

cargo llvm-cov at 100% of lines and functions. The report counted two lines short that no listing named: })?; after query_map's closure, a ? on a line of its own, counted at one build of the function and covered at the other. AGENTS.md says so now.

Shortcomings

Stacked on the identity pull. No firehose, blobs or crawlers yet (next pull). The store holds one mutex over one connection: fine at a group's size, and a pool when not. Group accounts are made only from Rust; the method that makes one, createGroup, comes with groups.

Asked for changes

This adds the SQLite store, the host's secrets, create_account, write and export, and the read-only com.atproto methods and well-known documents. The pull's base is empty, so the diff is the whole repo. I read the group-host sources (repo.rs, store.rs, api.rs, secrets.rs, plc.rs, lib.rs), plus config.rs and atproto/syntax.rs for context. I did not read the vendored lexicons, interop fixtures, web/, opensocial, the atproto crate beyond syntax.rs, or the tests. I did not read the checks.

The design is sound. Writes are one commit under a mutex, with a compare-and-swap on the head CID in the store. Records are checked against the data model and $type. The secrets file is created with mode 0600.

One thing to fix: handle case. create_account accepts any handle for which syntax::is_handle is true, and that accepts upper-case letters. The handle is then stored and published to PLC as given. Handles are case-insensitive in atproto, but SQLite's = is case-sensitive. This has two effects:

  • Foo.groups.test and foo.groups.test can both be created as separate accounts.
  • atproto_did lowercases the Host header, so an account stored with capitals is never found at its own address, and its handle verification fails. resolveHandle has the same mismatch, because it compares against handle exactly as passed.

Lower-case the handle in create_account before every check and use, and lower-case the handle parameter in resolve_handle. Alternatively, refuse upper-case handles. Add a test for either.

Smaller, not blocking: the PLC genesis is published before the database insert. If the insert loses the handle race, or fails, a DID stays in the directory with no account behind it. That is acceptable for now, but worth a comment or a later cleanup.

crates/group-host/src/repo.rsline 58Outdated

These lines can no longer be read.

review.knotless.dev

is_handle accepts upper case, and the handle is neither lower-cased nor compared case-insensitively. Foo.groups.test and foo.groups.test can both be created, and atproto_did (which lower-cases the Host header) never finds the capitalised one. Normalise to lower case here, before the checks and the PLC op.

crates/group-host/src/api.rsline 160Outdated

These lines can no longer be read.

review.knotless.dev

Same case mismatch: handle is compared as given, so a differently-cased handle is HandleNotFound. Lower-case handle before the lookup.

Fixed: create_account lower-cases the handle before every check, the PLC op and the insert; the store finds a handle by lower(?1); resolveHandle lower-cases its parameter. keeps_a_handle_in_lower_case creates Riders.Groups.Test, refuses riders.groups.test after it, and resolves and describes it in other cases. The PLC-before-insert order now has a comment saying what it leaves behind.

Approved

The handle-case finding is fixed. create_account (repo.rs:57) now lower-cases the handle before the checks, the PLC op and the insert. resolve_handle (api.rs:158) lower-cases its parameter. atproto_did already lower-cased the Host header. The store looks a handle up with lower(?1), and the new test keeps_a_handle_in_lower_case covers the duplicate and mixed-case lookups. I read these changes in the source but did not run the tests or read the checks. The PLC-before-insert order now has a comment saying what it leaves behind. Nothing else is blocking.

Merged as 8eeb3d8