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

Apps write as the group with their tokens, within scope and the member's roles

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

What changes

Using a token (oauth_resource.rs). An app calls the group's PDS methods with Authorization: DPoP <token> and a proof that hashes the token (ath), signed by the key the token is bound to. A refusal is 401 with a WWW-Authenticate: DPoP error=… challenge and the nonce for the next proof, as RFC 9449 has it: invalid_token for an unknown, lapsed, refreshed-away or Bearer token, or one proved by another key; invalid_dpop_proof; use_dpop_nonce.

Writing as the group (token_writes.rs):

  • the group's repo: com.atproto.repo.createRecord, putRecord, deleteRecord, applyWrites (200 writes at most), as its repo: scope allows, with swapCommit and swapRecord; and uploadBlob, as its blob: scope allows;
  • its spaces: com.atproto.space.createRecord, putRecord, deleteRecord, applyWrites, as its space: scope allows;
  • com.atproto.server.getSession: which group, and whether it is switched on.

A put of what is there makes no commit, and a delete of what isn't there is done.

Scopes are read as atproto's permission spec reads them (scopes.rs, following pds.js's scope.js). repo:C, repo?collection=…, actions; blob: and blob?accept=…, MIME patterns; space:T and space?type=T. A space scope's authority is the group unless the scope names one, its skey any, and with no action it grants all but read_self, which read implies.

The member's roles are asked at each use, as the review of the OAuth pull asked. A grant keeps its approved scope through refreshes, so each write also checks the approving member's current roles, by the rules narrowing used: repo collections by the permissions record, the group's own spaces by group.configure, other spaces by their access records' credentialScopes, and spaces for chosen people only for those of them who hold repo:*. A member whose roles shrink gives the app less at once.

In the group's own meta and members spaces, a token writes only as the host's methods would (the prototype's groupWrites.ts):

  • the profile, with a name and a join policy the host knows, and the labeler: kept at self and never deleted;
  • rules;
  • roles: one is taken away only once no grant names it (RoleInUse).

Memberships, permissions, and any space's access record change only through the host's methods.

Why

Step 6's second part: the tokens the OAuth server issues now do what they were approved for. Group tokens, app passwords and connected apps come next, then provisioning.

What changed from the prototype:

  • What a token may write is asked of the member's roles at each use, not only at approval.
  • Records are checked against the data model and their $type, not their lexicons, so validationStatus is unknown, as a PDS answers for a lexicon it does not know.
  • getSession is answered for a token; the prototype's came with app passwords.

How it was checked

tests/tokens.rs:

  • each refusal and its challenge, the nonce handshake, refreshed and lapsed tokens, a thief's key;
  • getSession, and refusing writes for a switched-off group;
  • each repo method, including swaps, the scope's limits, bad bodies, and blobs by type;
  • each space method in a calendar, by a member with create-only grants and by an admin;
  • the guard on the meta and members spaces: profile, labeler, rules, roles, memberships, permissions and access;
  • a member whose admin role is taken away, after which their token is refused for each write;
  • a space for chosen people;
  • scope parsing over each form.

These port the prototype's pds.test.ts and groupWrites.test.ts cases for writes with a token, and authorization.test.ts's "works at the resource server".

Shortcomings

  • Reads with a token (com.atproto.space.getRecord and the like, for the group's own repo) still take a space credential only.
  • clearRecords is not taken yet.
Approved

This pull lets an app write as the group with a DPoP-bound token. It adds token verification (ath, key binding, nonce, 401 challenges), the repo and space write methods, getSession, and a scope parser. Each write also checks the approving member's current roles, and the guard on the meta and members spaces matches what the host's own methods allow.

I read the resource server, the write handlers, the guard, lib.rs, the DPoP change and the store query. I read only part of the 744-line tests/tokens.rs and did not read these files:

  • scopes.rs
  • oauth_scope.rs
  • oauth.rs
  • repo.rs
  • tests/common/oauth.rs
  • the docs changes

I found no defects. check, web and lexicons pass. test, which carries the 100% coverage gate, was still running at this commit, so I can't say whether it passes.

Two small things, neither blocking:

  • putRecord and space.putRecord check scope and roles only when the put changes something. A put of identical content succeeds for a token whose scope doesn't cover that collection. It leaks nothing beyond the caller's own input, but checking first would be more predictable.
  • swapCommit is checked before host.write rather than inside it, so two concurrent writers can both pass the check.
Merged as fa3eac2