diff options
| -rw-r--r-- | docs/access.md | 50 | ||||
| -rw-r--r-- | src/access/rules.rs | 32 |
2 files changed, 57 insertions, 25 deletions
diff --git a/docs/access.md b/docs/access.md index ee48b8d..75f8db2 100644 --- a/docs/access.md +++ b/docs/access.md @@ -461,30 +461,32 @@ curl -u alice -X POST -H 'Content-Type: application/json' \ Under a strict policy, the same, as part of bob's entry, signed (`continuum-signed put _continuum/users/bob '{…}'`). -A node takes one only from that user, for that path, replacing what is there, by one -of the user's keys, and if the user may write there ([`api.md`](api.md), Signed values); -it writes nothing else there, nor within or above such a value (`409`), and the users -API changes nothing (`409`). Values there before the policy stay as they are until -replaced: a registry whose entries hold the users' keys turns strict as it is. As it is -means trusted as it is: whatever entries, policy and bans it holds then count, plain -values and envelopes alike, checked or not, whoever wrote them before (under a policy -that isn't strict, a member may write as any user). So a swarm is best strict from its -start (`--bootstrap-policy`, A new swarm, above); one already running turns strict -through a remake (Turning a swarm strict, below), which keeps only what an operator -looked over. Writing the strict policy into it directly trusts it as it is: look it -over first (`continuum-signed verify` on each entry). From then on nothing is added to -the time before: a change written under a policy that isn't strict is refused, received -or held, where the change that turned the swarm strict (that wrote the strict policy -under one that wasn't) is neither in its history nor built on it, so a member can't -plant at that time what nobody could follow; a node that took one beside that change -drops it once a peer tells it so (Changes judged on every node, below). The policy -written again later doesn't change which change that is. One written beside it is -refused like any other, even one turning the swarm strict too, so a change made later -to look as old can't take its place: two members turning a swarm strict at once split -the nodes that took one from those that took the other, so it is turned from one. A -value there that isn't an envelope starts its chain anew: any envelope its user once -signed for that path replacing nothing (`prev` empty) can be put there again. Without -the policy, signed values may be written all the same, and plain ones too. +A node takes one only from that user, for that path, replacing what is there, by one of +the user's keys, and if the user may write there ([`api.md`](api.md), Signed values); it +writes nothing else there, nor within or above such a value (`409`), and the users API +changes nothing (`409`). Values there before the policy stay as they are until replaced: +a registry whose entries hold the users' keys turns strict as it is. As it is means +trusted as it is: whatever entries, policy and bans it holds then count, plain values +and envelopes alike, checked or not, whoever wrote them before (under a policy that +isn't strict, a member may write as any user). So a swarm is best strict from its start +(`--bootstrap-policy`, A new swarm, above); one already running turns strict through a +remake (Turning a swarm strict, below), which keeps only what an operator looked over. +Writing the strict policy into it directly trusts it as it is: look it over first +(`continuum-signed verify` on each entry). From then on nothing is added to the time +before: a change written under a policy that isn't strict is refused, received or held, +where the change that turned the swarm strict (that wrote the strict policy under one +that wasn't) is neither in its history nor built on it, so a member can't plant at that +time what nobody could follow; a node that took one beside that change drops it once a +peer tells it so (Changes judged on every node, below). A strict swarm stays strict: its +policy is written again only as strict, never relaxed nor deleted, so which change +turned it doesn't change either; to leave it, start a new swarm from its content (A new +swarm, above). A change beside that one is refused like any other, even one turning the +swarm strict too, so a change made later to look as old can't take its place: two +members turning a swarm strict at once split the nodes that took one from those that +took the other, so it is turned from one. A value there that isn't an envelope starts +its chain anew: any envelope its user once signed for that path replacing nothing +(`prev` empty) can be put there again. Without the policy, signed values may be written +all the same, and plain ones too. Keep two users who may manage users, or two keys each: under a strict policy, a registry whose only manager lost its keys changes no more (the protocol writers do 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 |
