diff --git a/docs/02_via-core.md b/docs/02_via-core.md index 0607b68..efb52e8 100644 --- a/docs/02_via-core.md +++ b/docs/02_via-core.md @@ -105,24 +105,69 @@ now ───────────────────────── - Plans are not signed: Day 3 signs them with Tessera; `proto` leaves room (a new message version). - No people directory exists in Fundamentum; `directory.json` is our own snapshot format until it does. +- Groups are **flat**: members are people, never groups, so there is no nesting to resolve and no cycle + (QA R-13 to R-15 do not arise; a group id among the members is `directory.member`). - Multi-hop exits (`via` on `exits-through`) are refused, not compiled: Day 6. - `via` on `can-reach` is a path hint (relay or exit) carried in the peer; the engine decides what it means. -- No `via export` of a classic WireGuard config: Day 5. +- No `via export` of a classic WireGuard config: Day 5. Its exporter must write no free text (road notes, + names) into the file; names here are already free of line breaks and hidden characters (QA R-42). - No Custos approval field on roads: approvals are Day 4, and a new key is an *unknown key* to this build. +- `explain` and `check` answer as an administrator. A web view (Day 5) must scope them to the asker (QA R-49, + R-51): today they name every road. +- Firewall rules are one per (source, destination, port range): a group of 1,000 people to 1,000 places is + 10⁶ rules, not grouped into sets (QA R-59). Measured instead (QA R-56): 10,000 roads, 2,000 devices → + 249,400 grants and 5,978 rules in 0.59 s (release) and 3.1 s (debug), `tests/attacks.rs`. - The road ports have no ICMP types, only `icmp` as a whole. +- IPv6 routes that reach the internet (a delegated global /64) are refused like IPv4 public routes. -## Tests (written before the code) +## What QA's attack plan changed (`Via/qa/02_roads_attacks.md`) + +QA wrote an adversarial plan before reading this code. The five it ranked most likely: + +| Case | Answer | Where | +|:--|:--|:--| +| **R-10** a client's allowed IPs on the receiving side are wider than its address, so it can spoof another person | A peer gets its own `/32` from every road where it is the client; anything wider is only ever a route *it* serves (its subnet, or `0/0` as an exit). Every firewall source is a device `/32` sitting on that device's own peer, and no device address may lie inside any route (`devices.address`), so WireGuard's longest-prefix match never accepts that source from another peer | property P-1 (`least_privilege.rs`) checks every rule's source on every plan; `attacks.rs::r10_*`; mutation-checked (a `/24` there fails the property) | +| **R-35** `untill` accepted silently through `serde(flatten)` | Road headers are not serde at all: every key is checked against the list, unknown keys are `key.unknown`. Fixtures `a00005-untill.md` and `a00006-until-capital.md`; a rung-1 guard fails if `serde(flatten` appears in any source | `validation.rs` | +| **R-26** the plan has no expiry | `Plan.expires`: the earliest `until` of every road the plan was built from, on the subject's and the serving device's plans alike | `revocation.rs::each_plan_carries_its_own_expiry_on_both_sides` | +| **R-42** a newline in a name injects a `[Peer]` into an exported config | Person and group names refuse controls (CR, LF, U+0085), U+2028/2029, zero-width and bidi controls; device names are `[a-z0-9-]` only | fixtures `name-newline.*`, `name-bidi`; `attacks.rs::r42_*` | +| **R-02** aggregation rounds two grants up to a supernet | There is no aggregation: an allowed IP or firewall destination is exactly a road's subnet. The property's oracle demands exact equality, and is mutation-checked (widening a subnet grant to its route fails it) | `least_privilege.rs` | + +Also taken from the plan: raw blocks refuse wg-quick hooks (`PreUp`, `PostUp`, `PreDown`, `PostDown`, +`SaveConfig`, `Table`, `FwMark`, any case and spacing; `body.raw-hook`, R-41); routes and addresses refuse +public, loopback, link-local, multicast and IPv4-embedding IPv6 ranges (R-05, R-07, R-08); a kill switch wins over +going direct to the internet (`direct.kill-switch`, R-47); `until` needs an offset and is exclusive (R-22, +R-23); timestamps at the extremes do not panic (R-25); symbolic links, folders and other files in `roads/` are +reported, never read (R-32); cross-process output is byte-identical (R-52, `via-cli/tests/cli.rs`). + +The property design is QA's: small universes (routes in `10.0.0.0/22`, road subnets /22 to /32 inside it), +`until` on the boundary, 10% custom roads carrying `AllowedIPs = 0.0.0.0/0`, 5% invalid roads, and an oracle +that reads the generated world with `u32` arithmetic and no `roads` code. Differences, and why: + +- the world is drawn from a byte string rather than composed strategies, so proptest still shrinks it; +- no IPv4-mapped forms in the generator: the parser refuses them outright (fixture `a00016-mapped-ipv6.md`); +- P-2 (completeness) is not a property: the oracle is an upper bound, and the compiler also refuses classic peers + without `classic: true`, which the oracle does not model. The fixtures check the positive cases instead; +- P-5 (permutations) and P-6 (revocation completeness) are fixture tests (`determinism.rs`, `revocation.rs`); +- P-3 and P-4 leave out exit rules: removing one of two conflicting exit roads is *meant* to let the other apply; +- R-55 (renaming every id gives an isomorphic plan) is not done. + +## Tests + +The doc came first; the tests and the code were then written together in one sitting, not as tests-then-code +commits, and the history shows that. | # | Mandatory test | File | |:--|:--|:--| -| 1 | Validation: every rule has a failing fixture naming the file and the field; a meta-test fails if a rule has none | `crates/roads/tests/validation.rs`, fixtures in `crates/roads/tests/fixtures/invalid/` | -| 2 | Revocation: deleting a road, expiring it, removing a device from a person (and a person from a group) removes the access | `crates/roads/tests/revocation.rs` | -| 3 | Least privilege: property test (proptest) — no plan contains an allowed IP or firewall rule that no active road grants; adding an invalid road changes no plan | `crates/roads/tests/least_privilege.rs` | -| 4 | Determinism: byte-identical JSON and CBOR twice and with shuffled input; golden plans | `crates/roads/tests/determinism.rs`, `crates/proto/tests/determinism.rs` | -| 5 | `explain` returns exactly the allowing roads, and nothing when denied | `crates/roads/tests/explain.rs` | -| 6 | Custom roads round-trip unchanged: file → render, and through the plan and CBOR | `crates/roads/tests/custom.rs`, `crates/proto/tests/roundtrip.rs` | +| 1 | Validation: every rule has a failing fixture naming the file and the field; a meta-test fails if a rule has none; a failing road changes no plan byte | `crates/roads/tests/validation.rs`, fixtures in `crates/roads/tests/fixtures/invalid/` (`expect.txt`) | +| 2 | Revocation: deleting a road, expiring it, moving or removing a device, or a person from a group, removes the access on both sides | `crates/roads/tests/revocation.rs` | +| 3 | Least privilege: proptest, 5,000 cases for P-1 and 500 each for the invalid/expired and P-3/P-4 properties | `crates/roads/tests/least_privilege.rs` | +| 4 | Determinism: byte-identical twice, with shuffled input, with CRLF files, against golden plans; CBOR twice and decode → encode, a pinned digest | `crates/roads/tests/determinism.rs`, `crates/proto/tests/roundtrip.rs` | +| 5 | `explain` returns exactly the allowing roads, each one enough alone, and nothing when denied | `crates/roads/tests/explain.rs` | +| 6 | Custom roads round-trip unchanged: file → render, through the plan and through CBOR | `crates/roads/tests/custom.rs`, `crates/proto/tests/roundtrip.rs` | -Plus the protocol's refusals (wrong version, unknown field, trailing bytes, oversize) and the CLI on fixtures. +Plus QA's cases in `crates/roads/tests/attacks.rs`, the protocol's refusals in `crates/proto/tests/roundtrip.rs`, +and the binary in `crates/via-cli/tests/cli.rs`. Dates use `jiff`: `chrono` is flagged unmaintained +(RUSTSEC-2026-0543), which `cargo deny` refuses. ## Open questions @@ -133,3 +178,7 @@ Plus the protocol's refusals (wrong version, unknown field, trailing bytes, over This build takes it from `devices.json`. 4. Is `classic: true` the right acknowledgement, or should classic devices be refused unless a separate expert switch is on? +5. Should raw blocks also refuse `Address` and `DNS` (they change the host; QA R-41 lists `Address`)? Refusing + them would make a router's full config fail to import on Day 5. +6. Should a global IPv6 /64 be routable into the mesh? Refused for now. +7. A road file with a BOM is refused (`file.encoding`) rather than read; QA R-39 would read it. Which? diff --git a/docs/FORMATS.md b/docs/FORMATS.md index 23eff6b..881c772 100644 --- a/docs/FORMATS.md +++ b/docs/FORMATS.md @@ -73,7 +73,7 @@ belongs, or a single value where a list belongs, is `key.type`. A required key t | `group:` | a group in `directory.json` | as a person id | | `device:` | a device in `devices.json` | the Tessera device subkey: 32-byte Ed25519 public key, base64url without padding, 43 characters, canonical | | `app:` | a Domi app on every device | the Tessera id: 1–32 of `[a-z0-9-]`, not starting or ending with `-` | -| `subnet:` | an IPv4 or IPv6 network | canonical: host bits zero (`192.168.100.0/24`, not `192.168.100.7/24`) | +| `subnet:` | an IPv4 or IPv6 network | canonical: host bits zero (`192.168.100.0/24`, not `192.168.100.7/24`) and in the usual text form; IPv6 that embeds IPv4 (`::ffff:0:0/96`, `::/96`, `64:ff9b::/96`, `64:ff9b:1::/48`, `2002::/16`) is `ref.format`: write the IPv4 subnet | | `service:` | an Ianitor host, served by a device in `devices.json` | Ianitor's hostname rules: lowercase, labels of `[a-z0-9-]` not starting or ending with `-`, at most 63 per label and 253 in all, no wildcard, no trailing dot, not an IP address | | `exit:` | a device with `exit: true` | a device key | @@ -84,7 +84,9 @@ Everything after the closing `---`. - For `custom`, the body is exactly one **raw block**: a line ```` ```raw ````, the raw lines, and a last line ```` ``` ````. The raw bytes between the two fence lines are kept byte for byte — unknown WireGuard keys, CR characters, trailing spaces, even ```` ``` ```` lines inside — and are never interpreted (`body.raw-missing` - when it is absent). + when it is absent). One thing is refused inside: a line whose key is a wg-quick hook or routing switch, in any case and + spacing — `PreUp`, `PostUp`, `PreDown`, `PostDown`, `SaveConfig`, `Table`, `FwMark` (`body.raw-hook`): wg-quick + runs the first four with bash as root. - For every other verb the body is a free-text note, kept and never interpreted. A raw block there is an error (`body.raw-outside-custom`), so nobody believes it applies. @@ -118,6 +120,7 @@ Valid roads that grant nothing right now, reported with their reason (not errors | `road.no-devices` | the subject has no devices | | `road.self` | every subject device is the object's own device | | `exit.conflict` | for one device: active `exits-through` roads to two different exits (that device gets neither; reported per road, naming the device) | +| `direct.kill-switch` | for one device with a kill switch: a `goes-direct` road to a subnet that reaches the internet; the kill switch wins and the subnet stays in the tunnel (reported per road, naming the device). Going direct to a private subnet stays allowed | ## `directory.json` — the people directory snapshot @@ -133,7 +136,7 @@ Valid roads that grant nothing right now, reported with their reason (not errors |:--|:--| | `format` | `1` (`snapshot.format`) | | `people[].id` | a person id (`directory.id`), unique (`directory.duplicate`) | -| `people[].name` | 1–100 characters, one line (`directory.name`) | +| `people[].name` | 1–100 characters, no leading or trailing space, and none of: control characters (CR, LF, U+0085 included), U+2028, U+2029, zero-width characters U+200B–U+200F and U+2060–U+2069, bidi controls U+202A–U+202E, U+FEFF (`directory.name`) — so a name can never carry a line into an exported config | | `groups[].id` | a group id, unique among groups | | `groups[].name` | as a person's name | | `groups[].members` | person ids that exist, no repeats (`directory.member`) | @@ -160,11 +163,11 @@ Unknown fields, bad JSON and a missing file are `snapshot.json`. | `key` | — | a device key (`devices.key`), unique (`devices.duplicate`) | | `name` | — | 1–64 characters of `[a-z0-9-]`, unique (`devices.name`) | | `owner` | none | a person id in the directory (`devices.owner`); a device with no owner is reached only by `device:` roads | -| `address` | — | the device's mesh address, one IPv4 or IPv6 address, unique, not inside any device's routes (`devices.address`) | +| `address` | — | the device's mesh address, one IPv4 or IPv6 address, unique, not inside any device's routes, not loopback, link-local, multicast or IPv4-embedding IPv6 (`devices.address`) | | `classic` | `false` | a classic WireGuard peer, **not post-quantum** | | `exit` | `false` | offers itself as an exit | | `relay` | `false` | may be named by `via` | -| `routes` | `[]` | canonical subnets this device routes for the mesh; not `/0`; no overlap with another device's (`devices.route`, `devices.overlap`) | +| `routes` | `[]` | canonical subnets this device routes for the mesh: private only, so not `/0`, nothing that reaches the internet (use an exit), nothing loopback, link-local, multicast, reserved or IPv4-embedding; no overlap with another device's (`devices.route`, `devices.overlap`). This is also why two peers of one device can never hold the same prefix | | `services[].host` | — | an Ianitor hostname, unique across devices (`devices.service`) | | `services[].ports` | — | a non-empty port list (`devices.ports`) | @@ -178,14 +181,14 @@ entry. |:--|:--| | `format` | `1` | | `device`, `name`, `address`, `classic` | this device | -| `expires` | the earliest `until` (UTC, `Z`) of the roads this plan was built from; compile again by then; `null` if none | +| `expires` | the earliest `until` (UTC, `Z`) of every road this plan was built from, on the subject's plan and on the serving device's alike; the engine must stop applying the plan at that instant even if nothing recompiles (QA R-26); `null` if none | | `peers[]` | `key`, `name`, `address`, `classic` (*not post-quantum* when true), `allowed_ips` (sorted CIDRs), `via` (a path hint or `null`), `roads` | | `firewall.default` | always `"deny"` | | `firewall.rules[]` | `direction` (`in`: to this device's address; `forward`: to a subnet it routes, or to the internet as an exit), `src` (CIDR), `dst` (CIDR or `"internet"`), `proto` (`any`, `tcp`, `udp`, `icmp`), `ports` (`[lo, hi]` or `null`), `roads` | | `dns[]` | `host`, `address`, `roads`: names this device may resolve to a mesh address | | `exit` | `{through, roads}` or `null` | | `kill_switch` | `{through, roads}` (`through` is `null` when two kill-switch roads disagree: only the mesh) or `null` | -| `direct[]` | `{subnet}` or `{app}` with `roads`: bypasses the tunnel (split tunnelling) | +| `direct[]` | `{app, subnet, roads}`: traffic to `subnet` bypasses the tunnel (split tunnelling); `app` is `null` for all traffic, or the one app whose traffic goes direct | | `custom[]` | `{road, classic, raw}`: the raw block verbatim, **never checked by the compiler** | `internet` is every address except `0.0.0.0/8`, `10.0.0.0/8`, `100.64.0.0/10`, `127.0.0.0/8`, `169.254.0.0/16`,