# Day 2 — via-core: roads and the compiler Written before the tests and the code, on 2026-11-25. Where this page and the code later disagree, the code wins and the handover says so. ## Why Every access in Via is a **road**: a subject, a verb, an object and conditions — *Jana — can reach — Photos — until Sunday*. One pure compiler turns the roads into exactly the peers, allowed IPs and firewall rules each device needs. Nothing else grants access. Mark's judgment on risk is the reason this day exists: *a wrong rule compiler silently opens a subnet to the wrong person.* So the compiler is small, pure and deterministic, it denies by default, and every grant path has a test. ## What | Piece | Crate | What it does | |:--|:--|:--| | Road files | `roads` | one file per road, Pensum's strict header subset, unknown keys are errors, ids are random | | Snapshots | `roads` | `directory.json` (people and groups) and `devices.json` (devices, owners, addresses, routes, services) | | Validator | `roads` | every problem as `:: : `, with a rule code | | Compiler | `roads` | roads + directory + devices + `now` → one `Plan` per device | | `explain` | `roads` | which roads let this device reach that place; nothing when access is denied | | Control messages | `proto` | versioned CBOR envelope: plan request, plan, ack, refusal | | `via` | `via-cli` | `via check`, `via compile --device `, `via explain ` | Out of scope (the roadmap says so): tunnels, UI, mobile, exits in practice. Also out of this day: signing plans (Day 3, with Tessera), the classic WireGuard export (Day 5), multi-hop exits (Day 6). ## How ### The ids, read from the code that owns them | Id | Format | Source | |:--|:--|:--| | Road id | 6 characters of lowercase Crockford base32 `0123456789abcdefghjkmnpqrstvwxyz`, random; file `-.md` | Pensum: `F:\Akce\Fabrica\core\crates\pensum\src\id.rs:5-12`, `core\docs\FORMATS.md:85-97` | | Problem line | `:: : ` | Pensum: `core\crates\pensum\src\problem.rs:3-34`, `core\docs\FORMATS.md:161-165` | | Unknown keys | an error per key | Pensum: `core\crates\pensum\src\ticket.rs:11-12, 372-375` | | Header subset | YAML subset, refused constructs named | Pensum: `core\docs\FORMATS.md:14-42` | | Device key | the Tessera **device subkey**: an Ed25519 public key, 32 bytes, base64url without padding (43 characters) | `F:\Akce\Fundamentum\docs\TESSERA.md:29, 53-55` (`app_id` `"device"` is reserved for device subkeys) | | App id | 1–32 of `[a-z0-9-]`, not starting or ending with `-` | Tessera: `F:\Akce\Fundamentum\crates\tessera\src\id.rs:5-20` | | Service | an Ianitor host: its hostname, the file `hosts/.toml` | `F:\Akce\Ianitor\crates\core\src\routes.rs:5-16, 41-42`; hostname rules `crates\core\src\validate.rs:693-730` | | Person id, group id | **does not exist yet** — an opaque newtype, 1–64 of `[A-Za-z0-9_-]` | Fundamentum has no people directory (`F:\Akce\Liber\Liber\docs\05_together.md:13`: "`fundamentum.person.pick` does not exist at `canalis-v1.1.0`"); Liber keeps an `Option` id (`Liber-public\crates\liber-library\src\library.rs:8-13`) | The person id grammar was chosen wide enough to hold a base64url Tessera root public key (43 characters), in case the directory keys people by their root. When the directory exists, `PersonId::new` is the one place to change. ### The road model | Verb | Subject | Object | Conditions | Grants | |:--|:--|:--|:--|:--| | `can-reach` | person, group, device | device, subnet, service | `until`, `ports`, `via`, `classic` | peers both ways, allowed IPs, an inbound or forward firewall rule on the far side, DNS for a service | | `exits-through` | person, group, device | exit | `until`, `classic` | a peer with `0.0.0.0/0, ::/0`, a forward rule to the internet on the exit | | `goes-direct` | person, group, device, app | subnet | `until` | nothing: the subnet (or the app) bypasses the tunnel | | `never-online-without` | person, group, device | exit | `until` | nothing: the kill switch | | `custom` | device | — | `until`, `classic` | nothing the compiler checks: the raw block is carried, verbatim and labelled | - A person's grant covers **every device whose owner is that person** in `devices.json`; a group's covers every member's devices. Removing a device from a person removes its access on the next compile. - `classic` must be `true` on any road that would create a peer with a classic (not post-quantum) device. It is the road saying out loud that this path is not post-quantum. Without it the road grants nothing. - `until` is exclusive and compared with `now`, which is a parameter. Each plan carries `expires`, the earliest `until` of the roads it was built from, so the engine knows when to compile again. ### The compiler ``` roads/*.md ─┐ directory.json ─┼─► load ─► validate ─► expand to grants ─► one Plan per device ─► JSON / CBOR devices.json ─┘ │ │ now ──────────────────────────┘ └─► explain(device, place) = the grants' roads ``` - **Deny by default.** A road with any error grants nothing. A road that is valid but expired, or whose subject has no devices, grants nothing and is reported as *inactive* with its reason. If `directory.json` or `devices.json` has an error, **no plan is produced at all**. - **Allowed IPs** are cryptokey routing, not permission. The permission is the firewall rule on the far side: a road from Jana's phone to the home server gives the phone a peer for the server's address, gives the server a peer for the phone's address (so replies are accepted), and gives the server one inbound rule from the phone's address on the road's ports. Every firewall table is default-deny. - **Exits** route `0.0.0.0/0` and `::/0` to the exit; the exit gets a forward rule to `internet`, which means everything except private, link-local, loopback, CGNAT and ULA ranges, so an exit user does not reach the exit's LAN. A device with active exit roads to two different exits gets neither, and both are reported. - **Kill switch fails closed.** Two kill-switch roads naming different exits on one device give a kill switch through no exit at all (only the mesh), never none. - **Deterministic.** Every collection is a `BTreeMap`/`BTreeSet` or a sorted `Vec`; road files are read in file name order; the same input gives byte-identical JSON and CBOR. ## Risks | Risk | Consequence | Mitigation | |:--|:--|:--| | The compiler grants more than the roads say | a subnet open to the wrong person | the least-privilege property test against an independent oracle; every grant path has a fixture | | An invalid road is half applied | access nobody approved | validation is all-or-nothing per road; a failing road contributes to no plan (property test) | | An expired road stays in force because nobody recompiles | access after "until Sunday" | `Plan.expires`; the engine (Day 3) must recompile by then — a Day 3 test | | A custom raw block widens access | an `AllowedIPs` line the compiler never checked | raw blocks are never merged into peers; they sit in `Plan.custom`, labelled; Day 3 must not apply them without an expert's confirmation | | Non-determinism (hash order, file order, locale) | two compiles disagree; signatures do not match | no `HashMap` on any output path; byte-identical test with shuffled input; golden files | | The YAML subset parser accepts a construct it should refuse | a road file means something other than it reads | Pensum's subset, refused constructs each have a fixture | | A kill switch road with an error turns the kill switch off | traffic leaks when the tunnel drops | conflicting kill switches fail closed; an *invalid* kill-switch road is an open question below | | The people directory format changes | person ids no longer match | `PersonId` is one opaque newtype; changing it is one function | ## Gaps (what this day does not do) - 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. 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. ## 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; 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 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 1. Should an *invalid* `never-online-without` road fail closed (kill switch on through no exit), since "grants nothing" turns the protection off? This build reports it and does not apply it. 2. Does the people directory key people by a Tessera root key, a random id, or a name? `PersonId` waits. 3. Where does a service's hosting device come from: Ianitor's upstreams name hosts and ports, not Tessera keys. 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?