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

The host resolves identities and asks others' hosts with atproto-client

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

What changes

Guarded requests. guard.rs (pinned_client, public, Host::pinned, Host::at_pds) is gone. Host holds one atproto_client::guard::Guarded, built in Host::open (Guard::allowing_private() where PUBLIC_URL is http, Guard::strict() otherwise). It serves every call to a host others' data names: notifyRepoUpdate and notifyCredentialsRevoked to a PDS, the index's reads, getSpaceBlob, a group's own domain, OAuth client metadata (and so lexicons and logos), syncer endpoints, the proxy, an account's server while it moves, the console's sign-in posts. Each call is held to the same rules as before, and the connections now pool instead of a new client per request.

Identity. identity.rs is gone. Host::identity is the crate's Resolver with its default Memory cache (five minutes, 10 000 entries, as KEPT_FOR/KEPT_AT_MOST were). lib::resolver builds it from config: DID_WEB_HOSTS goes to reading_at (as <DID_WEB_SCHEME>://<address>), DID_WEB_SCHEME=http turns on on_http, and HANDLE_RESOLVERS becomes HandleResolver::WellKnown / Xrpc in the order given. Every place that read a document now (document) calls document_now; the space outbox, which read the kept document first, calls pds. Handle resolution in actors, api, console sign-in, group handle and import moves to resolve_handle.

Tokens. A space's delegation tokens are checked with service_auth::verify_delegation, and then their sub against the space asked for. A group's token for moving here is checked with service_auth::verify (aud SERVICE_DID, lxm migrateReceive).

Telemetry. The workspace moves to atproto 0.4.3 and atproto-client 0.2.0. observe::Calls is the Sender the resolver uses, so every identity read and service-token check goes through it. On each attempt it adds a traceparent naming the trace of the request being answered (held in a task-local set by observe) and logs one call line with the host, path, status or error, resend and duration_ms. It logs each XrpcError the client returns as refused. group-host has no identity::heard to send those to. docs/reference/api.md describes both lines.

atgrp. Client calls hosts and its own PDS through xrpc::Xrpc: sign-in, call, query, and own_query/own_call/own_bytes, which replace own. It gets its service tokens from service_auth::token. Errors read as they did before: <what>: <status> <error> <message>, or reaching <url>.

Config. HANDLE_RESOLVERS names the /.well-known resolver as well-known, where it used to take well-known:<scheme>. The scheme now follows DID_WEB_SCHEME. The old form stops the host at startup with an error. With DID_WEB_SCHEME=http, any name counts as a handle, so 127.0.0.1:<port> works. Handles are cached for five minutes, but the group-domain check and import's names call forget first, so those two still ask fresh.

Why

Each app had its own copy of the guard, the resolver and the token checks. atproto-client 0.1 is a single shared, tested copy of that code, and building the guarded client once lets its connections pool.

How it was checked

cargo clippy --workspace --all-targets -D warnings passes. Ran locally: the config, group_handle, authority and addresses tests. The tests that checked the old guard and resolver (tests/identity.rs) now live in the crate. The store-backfill test that was in that file moved to tests/addresses.rs. The full gate and e2e are left to CI.

Shortcomings

  • A client_id URL with a fragment used to be refused by the old guard. The crate's Guard::may_ask does not refuse fragments, so the host now fetches the URL without its fragment. Small crate fix: refuse a fragment in may_ask.
  • The host's direct Guarded calls (proxy, notify, syncers, getSpaceBlob, index reads) do not go through Calls: Guarded has no Sender hook of its own. The crate could add Guarded::sending.
  • Resolver::forget does not lowercase its key, but resolve_handle does. The host only passes lowercase handles.
  • account_move's getServiceAuth still goes through the move's OAuth session (DPoP, nonce, renewing on invalid_token). That is session code. service_auth::token takes a fixed Auth, so moving this call would mean writing the renewal again.
  • Some incoming service tokens still go through Resolver::with_key and are not checked by service_auth::verify: service_caller, and the token for importing an account. Those routes accept more than one audience (the host's DID or DID#service, a space's authority or its host aud) and name each refusal separately. The crate's verify takes exactly one aud.
  • atgrp's send (a raw-body procedure with query params) and GroupSession (a DPoP proof whose htu is the host's public URL, not the address it is reached at, and a bearer token with a proof for getGroupAuth) are still written by hand. The crate's Xrpc has neither.
Approved

This moves the host's outbound guarding, identity resolution and service-token checks, and atgrp's calls, onto atproto-client. I read the changed source files in the host and atgrp, but not Cargo.lock, the tests, the docs or the changeset. The test, e2e and docs checks were still queued or running, so I could not see them pass.

I found nothing that must change. The guarded call sites keep the old rules: each URL goes through guarded.get, post or request, or may_ask where DPoP signs the URL first. The forget calls before resolve_handle in names and group_handle::named keep those two checks fresh, as the body says.

One thing to confirm, which I can't check without the crate's source: delegated in authority_api.rs used to require aud == space_host_aud(space.authority). It now checks only sub against the space. This is safe only if verify_delegation itself requires the aud derived from the token's sub authority. If it doesn't, a delegation token minted for another audience would now pass. A test that a delegation token with a wrong aud is refused would settle it, in the crate or here.

The shortcomings listed in the body are fair. I have no objection to leaving them for later.

Approved

I read what changed since my approval at 0d58c58. It bumps atproto-client to 0.2 and atproto to 0.4.3. It also adds observe::Calls, a Sender that the resolver now uses. Calls logs each identity or token call as a call line, and a refusal as refused. When the call is made while answering a request, Calls also sends a traceparent for that request's trace. The tests, docs and changeset are updated to match.

What I approved stands. The test changes only follow the crate's new error wording. The fragment case now expects answered 404, which follows from a URL fragment never being sent.

Two small notes, neither blocking:

  • The traceparent carries a trace id that the original caller may have chosen. The host passes that id on to the PLC directory and to handle and DID hosts. This is harmless, and it is documented as a trace the caller names.
  • My earlier question about verify_delegation and the aud was not answered in this round. I still can't check it without the crate's source. A test that a delegation token with a wrong aud is refused would settle it.
Approved

I read what changed since my approval at 8a633bd, and what I approved stands. The change is small. oauth_clients.rs now includes the error's causes when a document fetch fails ({:#}), so a refusal from the guard shows its reason. The oauth_clients and proxy tests change to match the crate's wording ("public address", "not on https"). It touches only error text, not the guard rules. My earlier question about verify_delegation and the aud is still open. A test that a delegation token with a wrong aud is refused would settle it, but I'm not blocking on it.

Approved

I read what changed since my approval at 12ad354, and what I approved stands. The changes are small refactors that keep behavior:

  • atgrp now returns Ok(None) for RepoNotFound with then_some/ok_or_else.
  • The syncer delivery and the group-domain reaches check now use OptionFuture. A refused URL still counts as a failed delivery (Retry) or as not reached.
  • A rustfmt change in oauth_clients.rs.

The change in tests/authority.rs adds a case where a delegation token for another space of the same authority is refused. That partly answers my earlier question about verify_delegation and the aud. It covers a wrong space, not a wrong aud, but I'm not blocking on that.

Approved

I read what changed since my approval at 65628d5, and what I approved stands.

  • console_post: the removed may_ask pre-check was redundant. The call still goes through self.guarded.post(url), which applies the guard rules. The new ftp:// test case shows a refusal ("is not on https").
  • atgrp: a said helper replaces the repeated map_err(failed…) calls. own_bytes still returns Ok(None) for RepoNotFound and reports other errors as before.

Nothing needs to change.

Merged as 4943b9a