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/challenge.rs | 34 ++++++++++++++++++++++++++-------- 1 file changed, 26 insertions(+), 8 deletions(-) (limited to 'src/access/challenge.rs') diff --git a/src/access/challenge.rs b/src/access/challenge.rs index e61ea85..8df0f08 100644 --- a/src/access/challenge.rs +++ b/src/access/challenge.rs @@ -78,6 +78,31 @@ pub(crate) fn take( now: u64, used: &mut Used, per_user: usize, +) -> Result<(), String> { + take_with(key, challenge, user, now, used, per_user, |challenge| { + let signer = sshsig::verify(signature, NAMESPACE, challenge.as_bytes())?; + let entry = registry::user(doc, user).ok_or_else(|| format!("no user {user}"))?; + if entry.disabled { + return Err(format!("{user} is disabled")); + } + if !entry.keys.values().any(|known| *known == signer) { + return Err(format!("{user} has no key {}", signer.fingerprint())); + } + Ok(()) + }) +} + +/// Takes `challenge` as a login of `user`, where `check` says that `user` signed it: a +/// challenge of `key`'s node, unexpired at `now`, not used before (then used, in `used`), +/// with fewer than `per_user` of `user`'s own still remembered. Why not, if not. +pub(crate) fn take_with( + key: &NodeKey, + challenge: &str, + user: &str, + now: u64, + used: &mut Used, + per_user: usize, + check: impl FnOnce(&str) -> Result<(), String>, ) -> Result<(), String> { let mut parts = challenge.split('.'); let (Some(PREFIX), Some(payload), Some(signed), None) = @@ -116,14 +141,7 @@ pub(crate) fn take( if used.0.len() >= MAX_USED { return Err("too many logins by key at once: try again in a while".to_owned()); } - let signer = sshsig::verify(signature, NAMESPACE, challenge.as_bytes())?; - let entry = registry::user(doc, user).ok_or_else(|| format!("no user {user}"))?; - if entry.disabled { - return Err(format!("{user} is disabled")); - } - if !entry.keys.values().any(|known| *known == signer) { - return Err(format!("{user} has no key {}", signer.fingerprint())); - } + check(challenge)?; used.0.insert(payload.nonce, (payload.exp, user.to_owned())); Ok(()) } -- cgit v1.3.1