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

A space's authority may be a did:web, its key kept a few minutes

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

What changes

A space's authority may be a did:web. The host reads other accounts' DID documents through a new resolver (identity.rs): a did:plc from the PLC directory, a did:web from <scheme>://<host>/.well-known/did.json. It refuses a did:web with a path, any other method, and a document whose id isn't the DID asked for. These now go through it:

  • the authority's PDS, for notifyWrite;
  • the credential issuer's key, for the space read methods;
  • the service-auth issuer's key, for notifyCredentialRevoked.

Keys are kept five minutes. Reads by the same authority's credentials no longer look up its document each time. When the kept key turns a signature away, the document is read again and the check made once more, so a key the authority moved to counts at once. With nothing kept, the document is read once.

DID_WEB_SCHEME (https by default, or http) sets how a did:web is read, so tests can serve one from a local port. It is listed in docs/reference/config.md.

The spaces design page says how identities are read, and the plan marks the resolver done.

Why

The last pull listed two shortcomings: an authority could only be a did:plc, and every read looked its key up afresh. This follows knotless's identity.rs for both: the did:web scheme setting, five minutes kept, and a fresh read when a signature fails. The reference PDS does the same with forceRefresh. The id check is added because a did:web host serves whatever it likes.

How it was checked

  • tests/spaces.rs:
    • a_space_of_a_did_web_authority: a write is told to the PDS a did:web document names, and that authority's credential reads the repo with its MAC;
    • reads_with_a_credential_signed_by_an_authoritys_new_key: the authority rotates its key on the directory after the host kept the old one, and a credential signed with the new key still reads.
  • tests/identity.rs: refusals of other methods, a did:web with a path, a document of another DID, a document with no signing key (kept or read again), and a directory that doesn't answer.
  • tests/config.rs: DID_WEB_SCHEME and its refusal.
  • just cov: 100% of lines and functions. Clippy is clean.

Shortcomings

  • A key the authority moved away from still verifies for up to five minutes after the host last read it.
  • A credential's issuer is the caller's to name, so any caller can make the host GET /.well-known/did.json from a host of their choosing. Each document is read to 256 KiB at most, and at most 10,000 are kept: when full, the lapsed go, then all. Private and loopback addresses are not refused. docs/design/spaces.md says so, for whoever deploys a host inside a network with such services.

🤖 Generated with Claude Code

Asked for changes

This adds a Resolver (identity.rs) that reads did:plc and did:web documents and keeps them for five minutes. It routes the notifyWrite PDS lookup, credential verification and service-auth verification through that resolver. A key that fails verification is re-read once. The logic and tests look right. I didn't run the checks.

One thing should change before merge. The resolver now fetches and stores documents named by unauthenticated callers, with no cap on either. The "Shortcomings" section lists the unbounded cache but treats it as acceptable. It isn't, for the reasons below.

  • Unbounded memory. service_caller resolves claims.account() from a token it has not yet verified. credential resolves a space authority taken from the request. Each new did:web:<host> that answers with a document whose id matches adds a permanent entry to kept. Expired entries are never removed. A caller can grow the map without limit by serving documents from their own host.
  • Unbounded response body. res.json() reads the whole body, so one request can pull in an arbitrarily large document, which is then stored.
  • Server-side requests to caller-chosen hosts. With https, the host can be made to request any hostname. Check whether crate::client() blocks private and loopback addresses. If it doesn't, internal services are reachable. This is also true of did:web in general, so a note in the docs is enough if you accept it.

Please cap the cache. Evict expired entries on insert, and bound the entry count. Also cap the document size, for example by reading at most a few hundred KB.

Smaller point: every bad signature from a known authority forces a fresh network read, with no limit on how often. This matches knotless, so I'm not asking for a change. It is another reason to keep the fetch size bounded.

crates/group-host/src/identity.rslines 59 to 63Outdated

These lines can no longer be read.

review.knotless.dev

Inserted for any DID whose host serves a matching id, and never removed. Reached from unverified input (service_caller's iss, the space authority in a read). Evict expired entries here and bound the map's size.

crates/group-host/src/identity.rsline 55Outdated

These lines can no longer be read.

review.knotless.dev

res.json() buffers the whole body, which is then also stored. Limit the bytes read, since the host is named by the caller.

Asked for changes

The cache is now capped: it holds at most 10,000 documents, drops the lapsed first and then clears everything, and a test covers it. That answers the unbounded-memory point from my last round.

One request from last round is still open. The document size is not capped. document calls res.json(), which reads the whole body, and the client has only a 10-second timeout (lib.rs client()). A caller can name any did:web host and make the host buffer whatever that host streams in 10 seconds. A cached entry can then be that large, and with 10,000 entries the cache itself is still unbounded in bytes. Please read the body in chunks, or check Content-Length and count bytes as they arrive. Stop at a few hundred KB, and fail with an error. Add a test with an oversized document.

The server-side requests to caller-chosen hosts are still unaddressed. The client does not block private or loopback addresses. I said last round that a docs note would be enough. The "Shortcomings" section covers the GET to any host, but says nothing about internal addresses. A sentence in docs/design/spaces.md or the config reference would do.

The rest looks right: with_key re-reads once when the kept key fails, the id check, the did:web path refusal, and the config validation. I didn't run the checks.

crates/group-host/src/identity.rsline 74Outdated

These lines can no longer be read.

review.knotless.dev

res.json() buffers the whole body, and the 10s timeout is the only limit. Cap the bytes read (a few hundred KB) and bail past that. This is the cap I asked for last round.

Approved

Both requests from last round are done, so I'm approving. I didn't run the checks.

  • Document size: body() reads the response in chunks and fails once it passes 256 KiB. A test covers an oversized document. With the 10,000-entry cap, the cache is now bounded in bytes.
  • Internal addresses: docs/design/spaces.md now says that private and loopback addresses are not refused. It tells operators to keep the host's outgoing requests from reaching internal services.

I found nothing else to change.

Merged as 2252b74