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/login.rs | 81 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 81 insertions(+) (limited to 'src/api/login.rs') diff --git a/src/api/login.rs b/src/api/login.rs index 0658a69..ffcf9b8 100644 --- a/src/api/login.rs +++ b/src/api/login.rs @@ -8,6 +8,9 @@ //! * `POST /auth/challenge` and `POST /auth/login/key`, without a password: a challenge //! to sign with one of the user's keys, then the same token for it, signed //! (`access::challenge`). +//! * `POST /auth/login/party`, without a password, on a node holding a federated store: a +//! token as a party, for a challenge signed with one of the keys that sign for it there, +//! which does federation work alone (`login_party`). //! * `POST /auth/refresh`, with a token: a new one for the same login, signed by this //! node, optionally narrower still (`limit`, within the token's). //! * `POST /auth/logout`: every token of the user, of every login, no longer taken @@ -279,6 +282,7 @@ fn new_login( session_exp, login_exp: session_exp, limit, + party: None, } } @@ -322,6 +326,82 @@ pub(crate) struct KeyLogin { limit: Option>, } +/// A party's login by one of its keys (`POST /auth/login/party`). +#[cfg(feature = "federation")] +#[derive(Deserialize)] +pub(crate) struct PartyLogin { + party: String, + challenge: String, + /// Armored, as `ssh-keygen -Y sign -n continuum-login` writes it, or its blob in base64. + signature: String, +} + +/// `POST /auth/login/party`: on a node holding a federated store, a token as `party` for a +/// challenge signed with one of the keys that sign for it there, as its current version +/// and its key set say (`fold::State::signing_keys`), as `ssh-keygen -Y sign -n +/// continuum-login` signs, an ECDSA signature's `s` low (`401` if not, saying why): a +/// party's session, which does federation work alone, while that key signs for the +/// party (`api::access::federated`). `409` on a node holding none. +#[cfg(feature = "federation")] +pub(crate) async fn login_party( + State(state): State, + Json(request): Json, +) -> Result { + let (swarm, now) = issuing(&state).await?; + let key = state + .node_key + .as_ref() + .ok_or(ApiError(StatusCode::SERVICE_UNAVAILABLE, None))?; + let party = request.party.as_str(); + let keys = state + .holding + .with(|store| { + let read = store.state(); + read.signing_keys(party, read.current()) + }) + .ok_or_else(|| { + ApiError( + StatusCode::CONFLICT, + Some("no federated store here, whose parties' keys log in".to_owned()), + ) + })?; + let signer = { + let mut used = state.challenges.lock_or_recover(); + let mut signer = None; + challenge::take_with( + key, + &request.challenge, + &format!("party {party}"), + now, + &mut used, + state.key_logins_per_user, + |challenge| { + if keys.is_empty() { + return Err(format!("{party} is no party of the current version")); + } + let found = crate::federation::keys::signer( + &keys, + challenge::NAMESPACE, + &request.signature, + challenge.as_bytes(), + ) + .ok_or_else(|| format!("signed by none of the keys that sign for {party}"))?; + signer = Some(found.to_owned()); + Ok(()) + }, + ) + .map_err(|why| { + debug!(party = %party, reason = %why, "Refused a party's login"); + ApiError(StatusCode::UNAUTHORIZED, Some(why)) + })?; + signer + }; + let mut claims = new_login(&state, swarm, now, party, "party", None, None); + claims.party = signer; + info!(party = %party, login = "party", session = %claims.session, "A party logged in"); + answer(&state, &claims) +} + /// `POST /auth/login/key`: a token, as `POST /auth/login` gives one, for a challenge /// signed by one of the user's keys (`401` if not, saying why); `409` in a swarm without /// a registry, which holds no keys. @@ -745,6 +825,7 @@ pub(crate) async fn whoami( "session": token.claims.session, "sessionExpiresAt": token.claims.session_exp, "limit": token.claims.limit, + "party": token.claims.party, }) }); Json(json!({ -- cgit v1.3.1