From 9ebdd9011d086bc74351c527f6626fe403ef3348 Mon Sep 17 00:00:00 2001 From: tv Date: Sun, 15 Nov 2026 20:18:07 +0000 Subject: rules: a strict swarm stays strict A strict policy could be written over with one that isn't, or deleted, by a user who may manage the policy. While the swarm was relaxed so, nothing was asked of the time before it turned strict: a change written beside that turn was taken, and once the swarm turned strict again, built on, a node judging that change while strict from the first turn (one back from away, a joiner) refused it, and every node it told dropped it with the second turn and everything after. Under a strict policy, the policy is now written again only as strict: an envelope there whose value isn't a strict policy, a signed `null` among them, is refused. So a strict swarm has one change that turned it, and the time before it stays closed; to leave it, start a new swarm from its content. A swarm that isn't strict writes its policy as it did. --- src/access/rules.rs | 32 +++++++++++++++++++++++++++++++- 1 file changed, 31 insertions(+), 1 deletion(-) (limited to 'src/access/rules.rs') diff --git a/src/access/rules.rs b/src/access/rules.rs index 745dd7e..c84adc9 100644 --- a/src/access/rules.rs +++ b/src/access/rules.rs @@ -533,8 +533,19 @@ fn signed_values(at: &At<'_>, ops: &[Op]) -> Result<(), String> { } _ => None, }; - super::envelope::check(at, envelope, path, previous.as_deref()) + let checked = super::envelope::check(at, envelope, path, previous.as_deref()) .map_err(|why| format!("{}: {why}", shown(path)))?; + // A strict swarm stays strict: its policy is written again only as strict, + // never relaxed nor deleted, so the time before it turned strict stays what + // it was (`before_strict`). + if *path == super::policy::path() + && !super::policy::read(&checked.payload.value).strict() + { + return Err(format!( + "{}: a strict policy is written again only as strict", + shown(path) + )); + } } else if super::envelope::signed_path(&signed, path).is_some() { return Err(format!("{} is within a value its user signs", shown(path))); } else if op.action != Action::Within @@ -1118,6 +1129,25 @@ mod tests { // Elsewhere: as without the policy. assert!(judged(&doc, vec![op("notes/x", Action::PutString("x".to_owned()))]).is_ok()); assert!(refused(judged(&doc, vec![op("", Action::Nowhere)]))); + // The policy itself: written again only as strict, never relaxed nor deleted. + let policy = |value: serde_json::Value| { + let payload = envelope::Payload { + value, + swarm: "s".to_owned(), + path: path("_continuum/access/policy"), + user: "alice".to_owned(), + at: 1, + seq: 0, + prev: String::new(), + }; + let bytes = payload.signed(); + let sealed = + envelope::seal(&bytes, &sshsig::sign(&key, envelope::NAMESPACE, &bytes)).unwrap(); + vec![op("_continuum/access/policy", Action::PutString(sealed))] + }; + assert!(judged(&doc, policy(json!({"version": 1, "values": "signed"}))).is_ok()); + assert!(refused(judged(&doc, policy(json!({"version": 1}))))); + assert!(refused(judged(&doc, policy(json!(null))))); } /// Where values are declared sealed: only sealed ones, as declared, with or without -- cgit v1.3.1