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

Scopes are read by atproto's scope module, as the reference reads them

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

What changes

One grammar. The host reads OAuth scopes, roles' permissions and space policies' permissions with atproto 0.4.4's atproto::scope (Scope, Scopes, resolve_self, the allows_* and manages_space checks), which reads them as the permission spec and @atproto/oauth-scopes do. Its own grammar goes: scopes.rs's decoded, repo_collections, is_blob, named, query, actions, mime_matches and the action tables, the parsing half of oauth_scope.rs (SpaceScope::parse is now a view of the crate's Space), rbac.rs's own query/query_of and string matching in actions_of and repo_collections_for, and permission_sets::include's reading. The host's policy stays its own: Permissions (now a wrapper over Scopes), covers, narrowing to the roles, permission sets, and making a token's scope concrete.

Behaviour. Following the reference where the host differed:

  • A scope the grammar doesn't take is no scope: an action there's none of (repo:C?action=upsert, whose unknown action was dropped before), a parameter its resource doesn't take, a value it takes once named twice, a collection that isn't an NSID, an rpc: audience with no #service. Approval withholds it; createSpace and updateSpace refuse such a policy permission.
  • blob:a,b is no scope (it was read as both); an upload's type is compared as written (IMAGE/png no longer passes blob:image/*). A token now keeps each blob scope as one scope per type, lowercase, as atproto writes it (concrete, via scopes::blob_scopes).
  • An rpc: scope for the host's own methods names <host DID>#atgrp or *; the bare DID it took before is no audience.
  • space?spaceType=T is kept at approval as space:T is (space?type= was already not read).

Tokens already issued. A migration rewrites each oauth_token and oauth_request scope once through scopes::upgraded, which Store::open hands SQLite as upgraded_scope (rusqlite's functions feature): blob lists split and lowercased, unknown actions and parameters and repeated single values dropped, the host's own methods' bare audience given #atgrp. A scope that granted nothing before is left as written and still grants nothing.

Docs. docs/design/signing-in.md gains "Reading a scope", and its own-method audience reads <host DID>#atgrp. Change file: patch.

Why

Group-host, pds.js and the reference each read scopes a little differently; one implementation, held by atproto to the reference's fixtures, ends that. The reference's verdicts are taken where they differ, and existing grants are migrated rather than read with the old grammar forever: the old reading survives only as the one-time legacy rewrite.

How it was checked

  • A unit test (scopes::tests::reads_every_scope_the_host_writes) collects every form the host writes, into tokens and roles' records: each action's scope (rbac::scope_of), each of its five permission sets' scopes and concrete form, a group session's (scopes_for, own_scopes), an invite's, another app's set (included), an app password's, and narrowing's own space forms. Each parses as a scope of its kind, and the migration leaves it as it is. The forms earlier versions wrote (from the git history of concrete, scopes_of, group_tokens) are the same shapes, with NSIDs and DIDs as values; none used type= or a bare audience.
  • a_token_from_before_keeps_what_its_scope_granted (tests/tokens.rs) rewinds a database to before the migration with a token holding every legacy form, upgrades it, and checks the rewritten scope and what it grants.
  • Tests updated for the new reading: reads_a_scope_as_atproto_has_it, reads_a_scope_as_covered_by_those_held (rpc audiences with #svc; patterns, transition:generic), reads_a_space_scope, unions_a_roles_writes, rbac fixtures' two-segment collections made NSIDs, and the own-method audience test now names #atgrp.
  • Locally: cargo clippy -p group-host --all-targets -D warnings, cargo fmt --check, and the lib, tokens, oauth_scope, members, rbac, proxy, group_tokens and group_spaces tests. The full suite, the coverage gate and e2e are left to CI.
  • Merged main (atproto-client 0.7.1).

Shortcomings

  • Roles and space policies already written are records and aren't rewritten: a permission in one that the grammar doesn't take now grants nothing. The console and atgrp write only forms that read the same.
  • A legacy space scope naming only actions there are none of, alongside manage=, managed spaces before; it's left as written and now grants nothing, as atproto can't write a space scope with no action.
  • Another app's set naming a repo action there's none of gives a repo: scope that is no scope (it gave the known actions before).
  • The reference writes a % in a value bare, so an audience on a did:web with a port (localhost%3A…) only reads back if escaped twice; real hosts have none.

Review

The design of covers over typed scopes (scopes.rs) and the migration's legacy rewrite are where to look.

Approved

This moves scope reading onto atproto::scope. Permissions now wraps Scopes, covers, own_method, actions_of and SpaceScope::parse use typed scopes, and a migration rewrites stored token and request scopes through scopes::upgraded. I found nothing that must change.

  • Reading the code: I read the changes to scopes.rs, oauth_scope.rs, rbac.rs, permission_sets.rs, group_tokens.rs and store.rs. The typed covers and the legacy rewrite hold together. The migration runs inside the migration transaction, and upgraded_scope is registered before it. The oauth_request update skips NULL scopes. oauth_token.scope is NOT NULL, so the SQL function never sees a NULL.
  • Not read: I did not read the test files (members, oauth_scope, rbac and tokens), .changeset or docs/design/signing-in.md, or the Cargo.toml bump. I took the tests and docs on your description. The check and test checks were still queued when I looked, so CI is the real verdict on them.
  • Assumption to confirm: SpaceScope::parse computes read_only as manage.is_empty() && actions.all(reads). It lost the old !actions.is_empty() guard, and membership_actions now uses scope.actions.contains(..) directly. Both are right only if the crate fills Space.actions with the defaults when none are named. Your tests likely cover this. If any scope with no action ever parsed to an empty list, it would become read-only here and would grant no memberships.
  • Shortcomings you listed: I agree with them. Stored role records and space policies are not rewritten, and a permission in one that the grammar doesn't take now grants nothing. If you have deployed groups with such records, a note in the changelog would help.
Approved

Since my approval at 560d179, the only change is a test addition in tests/oauth_scope.rs. It adds a role c that has a bare repo:a.b.q permission, and it asserts that this permission isn't read as a space write, so writes for c holds only a.b.z. This doesn't touch the earlier reading of covers or the migration, so my approval stands. I didn't re-run the tests.

Merged as f0f6666