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

pds-server: OAuth tokens on the space methods, by their space: scopes

Merged
Merged chadtmiller.com asked to merge into main from chadtmiller.com/monolith:oauth/space-scopes

OAuth apps can now use spaces on Monolith accounts: the space methods take OAuth access tokens and allow what their space: permissions allow, as the spaces alpha of the reference does, where before they refused every OAuth token. HUD and knotless's CLI and gateway ask for space: scopes and could not use a Monolith account's spaces.

Claude Opus 5.5 · high

What changes

Spec. OAUTH-SCOPES.md "Spaces" says what is, not what is for later: which space: permissions parse (positional spaceType, authority default self, skey default *, collection, action, manage); space type declarations (defs.main of type space with a key and collections), resolved as permission sets are, at the page and again at the code grant, never at PAR; the token's scope, where a space: token with no collection gets its declared collections, sorted, and authority=self the account's DID, written again as the alpha writes it; what a permission allows (read over read_self; writes by action and collection; manage); what each space method needs and at which point it is asked; and the 403 ScopeMissingError naming the space: scope that would allow the call. transition:generic allows nothing of a space. A space type that does not resolve sends the browser back to the client from the authorization page with invalid_scope "Unable to retrieve space declarations", ending the request. OAUTH.md keeps space permissions; SPACES-REPO.md, SPACES-POLICIES.md and SPACES-CREDENTIALS.md take OAuth tokens where they name who may call (getDelegationToken with a read grant; app passwords still refused it); SPACES.md gives the spaces run its lexicon authority.

Harness. harness/spaces/scopes.mjs, in the spaces run: a third PDS publishes space type declarations (with collections and a title, with none, of another key, with no key, with no collections, and a document of another type), and both sides resolve from it (PDS_LEXICON_AUTHORITY_DID, the alpha's lexicon.didAuthority). Loopback clients asking for 22 space: scopes sign in on both sides through the page's API, each step compared, the token answer's scope among them; then each session calls the space methods on its account's spaces, another's and spaces never made (createSpace with and without a key, another type, getSpace, listSpaces with each filter, create/put/delete/applyWrites in each case including records of another type and published collections, the reads, getDelegationToken, the memberspace methods, removeWriter, updateSpace, export and importSpaceMeta, clearRecords, deleteSpace), comparing status, error and a ScopeMissingError's message with DIDs named alike. The main run's check from 03290bc, that listSpaces refuses an OAuth token as 400 InvalidToken, is removed: the main run's reference keeps no space: permission, and the method now takes the token.

Server. oauth/space_scope.rs: a space permission read, written, matched and rewritten; oauth/scope.rs keeps it; oauth/sets.rs resolves declarations beside sets and expands a session's scope with them at the grant and each refresh; the page redirects with invalid_scope when one does not resolve. scopes.rs reads a DPoP token on each space method that takes an account's token, and may_space/may_in ask the scope; space_authority.rs, space_repo.rs and space_credentials.rs ask it where the spec says (an OAuth session counts as its account's, never an app password's).

Why

Monolith served the space methods to its own password sessions only. Apps sign in with OAuth, and the scope they ask for spaces is space:; without it a Monolith account could not use HUD's or knotless's spaces. The alpha is the reference, so its answers were probed and the spec written to them, with the harness comparing each.

A client such as HUD asks space:com.chadtmiller.hud.workspace?authority=*&manage=create&manage=update&manage=delete; with a declaration of com.chadtmiller.hud.workspace published, its token holds space:com.chadtmiller.hud.workspace?authority=*&collection=<each declared collection, sorted>&manage=create&manage=update&manage=delete. Without a declaration the sign-in is sent back invalid_scope.

How it was checked

  • scopes.mjs run alone against the alpha on both sides: agrees; against a server built from main (616c0b8, whose server is main's): fails at the first sign-in, the token's scope atproto where the alpha's is atproto space:com.example.workspace?authority=<did:1>&collection=com.example.note&collection=com.example.tile; against this branch: agrees, every case.
  • Planted: SpacePermission::allows taking a write's action without its collection. Failed at createRecord of com.example.zz with a bare space:com.example.workspace: the alpha 403 ScopeMissingError naming ...&collection=com.example.zz&action=create, the server 200. Put back.
  • cargo test -p pds-server of the changed modules (space_scope, oauth::scope, oauth::sets, scopes, space_authority, space_credentials, space_repo): pass. cargo fmt, clippy -D warnings, spec-coverage.mjs, code.mjs: pass.
  • The whole spaces run and the other gates: the gates workflow, on this pull.

Shortcomings

  • importRepo with an OAuth token is not called by any run; its need (create of each collection the archive names) is the spec's alone.
  • No declaration changes during a run, so a refresh widening with its declaration, and the code grant's refusal of one that no longer resolves, are not checked.
  • The authorization page shows a space: permission as its scope string (row 10 of OAUTH-PAGES.md), not in words, and its __authorizeData has no spaces/spaceHandles as the alpha's has: the server's pages follow the latest reference's, which the main and pages runs compare.
  • Permission sets granting space permissions are not expanded into space: scopes.
  • Where the spec settles what the harness cannot see (the order of checks with an input that fails twice), it was written to the alpha's answers seen in the run, not to its source; the space scope module's parsing and formatting, drafted before this pull's harness existed, were written with the alpha's @atproto/oauth-scopes package read, and are now held to the alpha only by the harness.

Review

The design and the risky part: where each method asks the scope relative to its other checks (OAUTH-SCOPES.md, "What each method needs", and space_repo.rs's record_scope and writes_scope). Start at spec/OAUTH-SCOPES.md "Spaces", then harness/spaces/scopes.mjs.

Approved

This pull makes the space methods take OAuth access tokens and allow what their space: permissions allow. It adds space_scope.rs for parsing, rewriting and matching, and it resolves space type declarations beside permission sets at the page, the code grant and each refresh. The space_authority.rs, space_repo.rs and space_credentials.rs handlers ask the scope at the points OAUTH-SCOPES.md gives. The pull also adds harness/spaces/scopes.mjs and rewrites the spec's "Spaces" section.

I read all 23 files. The code matches the spec's table of what each method needs and where it asks. That covers the order of the ScopeMissingError checks relative to RepoNotFound, the published-collection refusal and the missing-space cases. The transition:generic and app-password handling matches too. The earlier listSpaces check that refused OAuth tokens is removed from oauth-scopes.mjs. It is replaced by the comparison in scopes.mjs, which is stricter, because it checks every method against the alpha. The changeset is written for operators. The spec, README and OAUTH.md table are updated. The harness adds no atproto crates, and the server code takes nothing from the reference's source.

run_list shows no gates run on this pull, so I couldn't confirm the full spaces run passes. The compare suite's budget rose from 125 to 155 seconds for the third PDS, so check that the run fits.

Two things you may want to do, neither blocking:

  • docs/guide/comparing.md's "Spaces" section doesn't say that the run now starts a third PDS as lexicon authority, or that it uses PDS_LEXICON_AUTHORITY_DID. The review rules ask a change to how the server is checked to update its guide.
  • import_repo's OAuth need is untested. The pull's body and SPACES-EXPORT.md both say so.
docs/guide/comparing.mdline 218OutdatedResolved
```sh
cd harness/spaces && npm ci
node compare.mjs --seed 1 -- ../../target/release/pds serve
review.knotless.dev

Not in this pull's diff: the Spaces section here should mention the third PDS and PDS_LEXICON_AUTHORITY_DID that scopes.mjs adds to the run.

Approved

Since my approval at 81d6ffa, the only change is in docs/guide/comparing.md. Its "Spaces" section now says the run starts a third PDS as lexicon authority and sets PDS_LEXICON_AUTHORITY_DID. That was my earlier non-blocking note, and it is done. The approval stands. The untested importRepo OAuth need is still open, and the pull's body and SPACES-EXPORT.md both say so.

All checks have passed

3 passed, 1 skipped

Merged as 787d32b