From 9bf334bedbc4b0cc3ce32fcd3baef27d3072f194 Mon Sep 17 00:00:00 2001 From: tv Date: Thu, 19 Nov 2026 20:11:05 +0000 Subject: federated nodes: a party's keys log in as the party, for federation work A party's people work with the federation by signing as the party, with a key of its set; what they need of a node is to read and to put events, which a node's users, its operators, may do with every power besides. POST /auth/login/party takes a challenge (POST /auth/challenge) signed with one of the keys that sign for the party (fold::State::signing_keys: those its current version names, and its key set as it counts), for the namespace continuum-login, armored or as the federation spells a signature (keys::signer, keys::verifies_in: the federation's checks, but for the namespace), and answers a token as the party. Logins by key are counted per party as per user (challenge::take_with, shared with logging in by a registry's keys). The token names the key (Claims::party). Such a session does federation work alone (api::access::federated): what --store-readers do, and POST /events; anything else is 403. Every request checks that the key still signs for the party: once a version or the party's key set drops it, 401. A build from before reads no token naming a key, as its claims deny fields they don't know, so never takes a party's session for a user's; and only the node that issued it takes it, as every token in a federated swarm. --- src/api/access.rs | 62 ++++++++++++++++++++++++++++++++++++++++--------------- 1 file changed, 45 insertions(+), 17 deletions(-) (limited to 'src/api/access.rs') diff --git a/src/api/access.rs b/src/api/access.rs index 47e24ba..339d9de 100644 --- a/src/api/access.rs +++ b/src/api/access.rs @@ -394,33 +394,61 @@ pub(crate) async fn authorize( } /// On a node holding a federated store, what its users who aren't its operators may do: a -/// user of `--store-readers` reads the federation (`federation_work`), and nothing else. -/// Its other users are its operators, who may do everything. The answer refusing the -/// request, where it is refused. +/// party's session (a token from a party's key, `login::login_party`) does federation work +/// (`federation_work`), putting events too, while the key it logged in with signs for +/// the party (`fold::State::signing_keys`); a user of `--store-readers` reads the +/// federation; and neither does anything else. Its other users are its operators, who may +/// do everything. The answer refusing the request, where it is refused. #[cfg(feature = "federation")] fn federated(state: &AppState, request: &Request, user: &str) -> Option { - if !state.store_readers.contains(user) { + let party_key = request + .extensions() + .get::() + .and_then(|token| token.claims.party.clone()); + if party_key.is_none() && !state.store_readers.contains(user) { return None; } - if state.holding.with(|_| ()).is_none() { - return Some(error_response( - StatusCode::FORBIDDEN, - format!("{user} reads a federated store here alone, and this node holds none"), - None, - )); + let signs = state.holding.with(|store| { + let read = store.state(); + party_key + .as_ref() + .is_none_or(|key| read.signing_keys(user, read.current()).contains(key)) + }); + let refused = |status: StatusCode, why: String| { + debug!(user = %user, method = %request.method(), path = %request.uri().path(), reason = %why, "Refused a request of a party or a reader"); + Some(error_response(status, why, None)) + }; + match signs { + None => { + return refused( + StatusCode::FORBIDDEN, + format!("{user} works with a federated store here alone, and this node holds none"), + ); + } + Some(false) => { + return refused( + StatusCode::UNAUTHORIZED, + format!("the key {user} logged in with signs for it no more: log in again"), + ); + } + Some(true) => {} } - if federation_work(request.method(), request.uri().path(), false) { + let puts = party_key.is_some(); + if federation_work(request.method(), request.uri().path(), puts) { return None; } - debug!(user = %user, method = %request.method(), path = %request.uri().path(), "Refused a reader's request that doesn't read the federation"); - Some(error_response( - StatusCode::FORBIDDEN, + let why = if puts { + format!( + "a session of {user}, a party, does federation work alone: reading and putting \ + events (docs/guides/federation/running-a-node.md, Its API)" + ) + } else { format!( "{user} reads the federation here, and does nothing else (--store-readers; \ docs/guides/federation/running-a-node.md, Its API)" - ), - None, - )) + ) + }; + refused(StatusCode::FORBIDDEN, why) } /// Whether a request is federation work: reading the events API (`GET` and `HEAD` of -- cgit v1.3.1