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

Apps signed in as a group call other services through the host

Merged
Merged chadtmiller.com asked to merge into main from chadtmiller.com/group-host:pds/service-proxy

What changes

Proxying. An app signed in as a group (OAuth token or app-password session) can now call other services through the host, as through any account's PDS. A call to a method the host doesn't serve, carrying atproto-proxy: <did>#<service>, is sent on to the endpoint that service id names in the DID's document. The host signs service auth with the group's key (iss the group, aud the service's bare DID, lxm the method, lapsing in a minute) and streams the answer back. It forwards the method, path, query, a POST's body (up to BLOB_UPLOAD_LIMIT), and the headers the reference PDS forwards (accept-encoding, accept-language, atproto-accept-labelers, x-bsky-topics, x-atproto-*, and a body's content-type/content-encoding). It passes back the status, the content-* headers, atproto-repo-rev, atproto-content-labelers and retry-after. Failures come back as the reference PDS gives them: the service's error name and message, with a 500 turned into 502 UpstreamFailure. Each call is logged with its method, service and status, never a token or a body. Without the header, an unknown method still gets 501 MethodNotImplemented. A method the host serves is always answered by the host.

getServiceAuth. com.atproto.server.getServiceAuth takes aud (a DID or did#service, used as given), lxm and exp, with the reference PDS's limits (BadExpiration: within an hour for a method, a minute for none). It refuses protected methods.

Scope. A token needs rpc:<lxm>?aud=<did>#<svc> (with * for either, but not both), transition:generic (anything but chat.bsky.*) or transition:chat.bsky (chat). Without it the call fails 403 ScopeMissingError Missing required scope "rpc:…", as the reference PDS answers. The approving member must still hold repo:* at each call (Forbidden). An app-password session follows the reference PDS's access-token rules: it may call anything but chat and createAccount, unless the password may use chat (InvalidToken "Bad token method"). Methods for managing an account directly (getSession, createAppPassword, updateHandle, … and every com.atproto.admin.*) are never proxied (InvalidToken) and never get service auth (InvalidRequest). The host refuses its own DID and any endpoint at PUBLIC_URL, such as a group's own #atproto_pds. Unresolvable DIDs and unknown service ids get InvalidRequest. A service gets the same public-address pinning as client metadata, so a private address or a non-https URL is refused with 502 UpstreamFailure.

Narrowing. For roles holding repo:* (the same rule as making an app password), approval now keeps transition:generic and transition:chat.bsky. It also keeps other apps' permission sets (include:<nsid>?aud=…, such as social.grain.authFull). A set is resolved as atproto publishes lexicons: the _lexicon.<authority> TXT record is read from the new DNS_OVER_HTTPS (Cloudflare's JSON endpoint by default), then the DID it names gives the PDS that holds com.atproto.lexicon.schema/<nsid>. That record is read at a public address and kept for ten minutes. A set's repo and rpc permissions within its namespace are kept as repo:C and rpc:M are. rpc takes the include's aud through inheritAud. The set is kept whole when the roles grant every part, and is otherwise cut down to the parts they grant. Tokens stay concrete: the set becomes its scopes at approval. The approval page labels another app's set with its lexicon's title and detail. CORS now allows atproto-proxy and atproto-accept-labelers.

Docs: signing-in.md (new "Calling other services as the group", narrowing, app passwords), api.md, config.md, design README.

Why

A group on groups.grain.social could sign in to next.grain.social, but every social.grain.* call came back 501 MethodNotImplemented (production, 01:31:58Z). The host was a PDS that couldn't proxy. Grain's apps ask for transition:generic or include:social.grain.authFull?aud=did:web:grain.social%23grain_appview, and the host withheld both, so proxying also needed narrowing to keep them.

On proxying, I followed the reference PDS's current behaviour. The scope check sees did#service, the outbound JWT's aud is the bare DID, local routes take precedence over the header, and the protected/privileged method lists match. A missing scope is refused with the reference's ScopeMissingError rather than the host's own ScopeMissing, because apps written against a PDS read that name.

For the _lexicon record, the host has no DNS resolver. A configurable DNS-over-HTTPS service follows HANDLE_RESOLVERS' precedent of asking an HTTP service for DNS. It adds no dependency, and tests can fake it.

How it was checked

tests/proxy.rs runs against a fake Grain AppView, a fake DoH service and a fake lexicon PDS:

  • A proxied GET and POST reach it with service auth that it verifies against the group's DID document from the PLC directory (signature, iss, aud, lxm, exp). The query, body and forwarded headers arrive, and the answer comes back with its headers.
  • Upstream failures are mapped (500→502 with retry-after, 404 non-JSON, 418).
  • Missing scope, transition:* and chat are checked, including a member who loses repo:*.
  • App-password sessions are checked, privileged and not.
  • Every header-parse refusal is covered, along with protected/admin methods, self (the host's DID and a group's #atproto_pds), an unresolvable DID, an unknown service, an unreachable service, and a private address and non-https URL on an https host.
  • The permission set is resolved (whole, partial, missing, a TXT naming two DIDs, a record that isn't a set, the host's own set) and kept. The approval page shows the set's label.
  • getServiceAuth issues a token the fake service accepts, and each refusal is checked.

The oauth_scope test now expects transition:generic for admins, and the config tests cover DNS_OVER_HTTPS. Locally, cargo test -p group-host passes, apart from the tests that need the harness's node packages (not installed in this worktree). cargo clippy -D warnings and just docs are clean. Coverage and the harness tests are left to CI.

Shortcomings

  • Another app's space permissions grant a group's session nothing yet.
  • A set that grows reaches a group's app only when it's approved again, because tokens are concrete and refreshing doesn't re-read the set.
  • A POST's body is read whole (up to BLOB_UPLOAD_LIMIT) before being sent on. Only the answer is streamed.
  • Proxied calls count only against the existing per-address limit, as on the reference PDS. There's no per-group limit.
  • Default DNS_OVER_HTTPS is Cloudflare's: operators who'd rather not depend on it set their own.

Review

Start at crates/group-host/src/proxy.rs, then permission_sets.rs and the narrowing change in oauth_scope.rs.

Approved

This pull adds atproto-proxy forwarding for apps signed in as a group, plus getServiceAuth and rpc: / transition:* scope checks. It also adds narrowing for other apps' permission sets, which are resolved over DNS-over-HTTPS and the publisher's PDS.

I read proxy.rs, permission_sets.rs, scopes.rs, oauth_scope.rs, authorization.rs and the routing change in lib.rs. I did not read the tests, docs, config.rs, oauth.rs, mcp.rs, provision.rs or rbac.rs. I ran no checks.

What I checked and found sound:

  • Local routes win over the proxy catch-all.
  • The scope and repo:* check runs before the DID is resolved or any service is contacted.
  • The outbound JWT's aud is the bare DID, and its lxm and one-minute expiry are right.
  • Authorization is never forwarded.
  • Self-proxying and the protected and admin method lists are refused.
  • Include scopes are limited to the publisher's own namespace, and a set that is not a permission-set is rejected.

Three minor notes, none blocking:

  • A failed DoH or PDS lookup is cached as "missing" for ten minutes (permission_set). A transient outage therefore withholds a set at approval until the cache entry lapses.
  • get_authorization resolves every include: scope in a request one after another. An unauthenticated caller can send many distinct NSIDs and trigger as many outbound lookups, bounded only by the 1000-entry cache. A cap on the number of includes resolved per request would help.
  • Permissions::rpc tests chat.bsky. case-sensitively, while privileged lowercases first. A scope named with different casing would behave differently on the two paths.
Approved

The change since my approval is small. It narrows Permissions::rpc in scopes.rs so each rpc: scope on a token names one method. The rpc:?lxm=… multi-method form is no longer matched there.

I think this is safe. Narrowing keeps each rpc:M as its own scope and tokens are concrete, so the multi-method form shouldn't reach a token. The new doc comment says so. The */* rule is unchanged: a wildcard audience with a wildcard method still doesn't match. My earlier approval stands.

I did not run any checks. My three earlier minor notes aren't addressed in this diff. They weren't blocking.

Merged as b6c4cc8