diff options
| author | tv <tv@krebsco.de> | 2026-11-30 14:59:37 +0000 |
|---|---|---|
| committer | tv <tv@krebsco.de> | 2026-11-30 14:59:37 +0000 |
| commit | bb860d2cf0adad80016edb7a7baed4df291b828c (patch) | |
| tree | 7e0bed9ff36df8c5b5432ddd2d7b544278d25f54 /src | |
| parent | 8017b0e69f0350c2a35629ae71d511ddf7a3aa9c (diff) | |
federation: what a set hands the node to read is as a store's document
Beside its members' entries, the policy of a swarm holding a store and
the swarm's ID (Holding::entries): what reads a document for them reads
the same of a node on a set. Tokens are checked against it (api::login):
their issuer's entry is there, and a node takes none another issued, as
the policy says; read of the empty Automerge document beside, every
token was refused.
Diffstat (limited to 'src')
| -rw-r--r-- | src/api/login.rs | 26 | ||||
| -rw-r--r-- | src/federation/held.rs | 27 | ||||
| -rw-r--r-- | src/state/mod.rs | 3 |
3 files changed, 39 insertions, 17 deletions
diff --git a/src/api/login.rs b/src/api/login.rs index e442ea2..a5bfde5 100644 --- a/src/api/login.rs +++ b/src/api/login.rs @@ -115,10 +115,12 @@ pub(crate) async fn bearer( let now = state.clock.now_millis().as_u64(); let verified = { let replica = state.doc.read().await; - let verified = token::verify(&replica.doc, &text, &swarm, now); + let entries = state.entries(); + let listed = crate::document::view::members_of(&entries, &replica.doc); + let verified = token::verify(listed, &text, &swarm, now); #[cfg(feature = "federation")] let verified = - verified.and_then(|claims| token::issued_here(&replica.doc, state.local_id(), claims)); + verified.and_then(|claims| token::issued_here(listed, state.local_id(), claims)); verified } .and_then(|claims| { @@ -559,17 +561,17 @@ async fn credentials_end( /// sessions. async fn refused_now(state: &AppState, who: &Credentials) -> Option<token::Refused> { let replica = state.doc.read().await; + let entries = state.entries(); + let listed = crate::document::view::members_of(&entries, &replica.doc); match who { - Credentials::Token(claims) => { - token::still_taken(&replica.doc, claims).err().or_else(|| { - state - .ended_sessions - .lock_or_recover() - .contains_key(&claims.session) - .then_some(token::Refused::Ended) - }) - } - Credentials::User(user) => token::user_taken(&replica.doc, user).err(), + Credentials::Token(claims) => token::still_taken(listed, claims).err().or_else(|| { + state + .ended_sessions + .lock_or_recover() + .contains_key(&claims.session) + .then_some(token::Refused::Ended) + }), + Credentials::User(user) => token::user_taken(listed, user).err(), } } diff --git a/src/federation/held.rs b/src/federation/held.rs index fd43062..bb34407 100644 --- a/src/federation/held.rs +++ b/src/federation/held.rs @@ -1108,13 +1108,23 @@ impl Holding { } } - /// The members' entries as the node reads them of a document, each at - /// `_continuum/members/<node ID>`, where a set of events carries the store: the - /// document's place for them, which a set keeps apart. + /// What the node reads of its document at paths, where a set of events carries the + /// store: what a document holding a store has there. The members' entries, each at + /// `_continuum/members/<node ID>`, which a set keeps apart; the policy of a swarm + /// holding a store; and the swarm's ID, the store's. pub(crate) fn entries(&self) -> Option<crate::document::view::Tree> { use crate::document::view::{Tree, Write}; self.with_set(|set| { let mut tree = Tree::new(); + // Into a tree of maps alone: nothing is in the way of any of it. + let _ = tree.write_path( + &crate::access::policy::path(), + &events::policy(Federation::NAME), + ); + let _ = tree.write_path( + &meta::path(&[meta::SWARM]), + &serde_json::Value::String(set.store().id().to_string()), + ); for entry in set.entries() { if let Some(value) = entry.value() { let path = [ @@ -1122,7 +1132,6 @@ impl Holding { meta::MEMBERS.to_owned(), entry.node(), ]; - // Into a tree of maps alone: nothing is in the way. let _ = tree.write_path(&path, &serde_json::Value::Object(value)); } } @@ -2966,6 +2975,16 @@ mod tests { Some("tv".to_owned()) ); assert!(holding.member(&key.id(), Some("tv")) == Some(true)); + // And the rest a document holding a store has for the node to read: the + // policy, by which a node takes no token another issued, and the swarm's ID. + assert!(matches!( + crate::access::policy::of(&tree), + crate::access::policy::Policy::Store(_) + )); + assert_eq!( + crate::document::view::read_path(&tree, &meta::path(&[meta::SWARM])).unwrap(), + Some(serde_json::Value::String(Id::of(&root).to_string())) + ); assert!(Holding::default().entries().is_none()); } } diff --git a/src/state/mod.rs b/src/state/mod.rs index d512b2b..21478de 100644 --- a/src/state/mod.rs +++ b/src/state/mod.rs @@ -404,7 +404,8 @@ impl AppState { } } - /// The members' entries as a document has them, where this node's document keeps + /// What the node reads of a document at paths (its members, the policy, the swarm's + /// ID), where this node's document keeps /// them apart (a set of events, `Holding::entries`): none, where they are in the /// document it holds. pub(crate) fn entries(&self) -> Option<crate::document::view::Tree> { |
