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/access/token.rs | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) (limited to 'src/access/token.rs') diff --git a/src/access/token.rs b/src/access/token.rs index 0920410..650a5c4 100644 --- a/src/access/token.rs +++ b/src/access/token.rs @@ -58,6 +58,13 @@ pub(crate) struct Claims { /// Less than the user may do: only what these allow too. #[serde(default, skip_serializing_if = "Option::is_none")] pub(crate) limit: Option>, + /// Of a party's session, on a node holding a federated store: the key, as the + /// federation spells it, that `user`, the party, logged in with + /// (`api::login::login_party`). Such a token does federation work alone, while that + /// key signs for the party (`api::access::federated`); a build from before it reads + /// none (`deny_unknown_fields`), so never takes it for its user's. + #[serde(default, skip_serializing_if = "Option::is_none")] + pub(crate) party: Option, } /// `claims`, signed by `key`, as a token. @@ -243,6 +250,7 @@ mod tests { session_exp: 10_000, login_exp: 10_000, limit: None, + party: None, } } @@ -251,6 +259,36 @@ mod tests { change(doc, |tx| store::write_path(tx, &path, &json!({})).unwrap()); } + /// A party's session names the key it logged in with, which a token of a user's + /// leaves out: a build from before it reads none (its claims deny fields it doesn't + /// know), so never takes it for its user's. + #[test] + fn a_partys_session_names_its_key() { + let key = NodeKey::from_seed([1; 32]); + let mut doc = Document::new(); + member(&mut doc, &key); + let party = Claims { + user: "tv".to_owned(), + login: "party".to_owned(), + party: Some("ssh-ed25519 AAAA".to_owned()), + ..claims(&key) + }; + let token = issue(&key, &party); + assert_eq!(verify(&doc, &token, "s", 1_500), Ok(party)); + let (_, payload) = token.split_once('.').unwrap(); + let (payload, _) = payload.split_once('.').unwrap(); + let payload = String::from_utf8(BASE64URL.decode(payload).unwrap()).unwrap(); + assert!( + payload.contains(r#""party":"ssh-ed25519 AAAA""#), + "{payload}" + ); + let user = issue(&key, &claims(&key)); + let (_, payload) = user.split_once('.').unwrap(); + let (payload, _) = payload.split_once('.').unwrap(); + let payload = String::from_utf8(BASE64URL.decode(payload).unwrap()).unwrap(); + assert!(!payload.contains("party"), "{payload}"); + } + #[test] fn issued_and_taken() { let key = NodeKey::from_seed([1; 32]); -- cgit v1.3.1