# via-core formats Field by field: the road store, the two snapshots, the compiled plan, and the control protocol. Every format is versioned; a change that an older build would misread bumps the version. ## The store ``` / directory.json the people directory snapshot devices.json the device list roads/-.md one file per road ``` `roads/` holds only regular files named `-.md`. Anything else in it — a folder, a symbolic link, a file with another name — is an error (`file.kind`), so the folder can never hold something the compiler does not read. Files are read in byte order of their names. At most 10,000 road files. A store without a `roads/` folder, or whose `roads/` is a file or a symbolic link, is `store.roads`: nothing is read, nothing is granted, and it is said out loud, because pointing `--store` one folder too high would otherwise revoke everything, kill switches included, without a word (QA F-07). ## Road files ### The file - **Encoding.** UTF-8, no BOM. Invalid UTF-8 or a BOM is an error (`file.encoding`). - **Size.** At most **256 KiB**, refused before it is parsed (`file.size`). - **Line endings.** LF or CRLF. - **Structure.** The first line is `---`, the header follows, the next `---` line closes it, everything after it is the body (`file.header` when there is no header or it is not closed). - **Name.** `-.md`. The slug is `[a-z0-9]+(-[a-z0-9]+)*`, at most 40 characters (`file.name`). ### The header subset The same strict subset of YAML as Pensum's tickets (Fabrica `core/docs/FORMATS.md`, "The header subset"): | Allowed | Example | |:--|:--| | a top-level `key: value`, the key `[A-Za-z][A-Za-z0-9]*` at column 0 | `verb: can-reach` | | a plain scalar, always a **string** (`true` is text; `classic` reads it) | `subject: person:jana` | | a double-quoted string with `\" \\ \n \t \r \uXXXX` | `subject: "person:jana"` | | a single-quoted string, `''` for a quote | `subject: 'person:jana'` | | a flow list of scalars | `ports: [tcp/443, udp/53]` | | a block list of scalars, indented under its key | `ports:` then ` - tcp/443` | | an empty value, meaning *absent*; for `until` and `ports` it is an error (`key.empty`) | `via:` | | comment lines, blank lines, a trailing ` # comment` after a plain value or list | `# moved from the router` | Refused, each with an error naming the file, the line and the field (`yaml.refused`): anchors (`&a`), aliases (`*a`), tags (`!x`), block scalars (`|`, `>`), flow mappings (`{}`), nested lists, indented keys, directives (`%YAML`), the document end marker `...`, and tab indentation. A duplicate key is `key.duplicate`; a line that is not `key: value`, or a bad quoted string, is `yaml.syntax`. ### Header fields | Key | Required | Value | Rules | |:--|:--|:--|:--| | `id` | yes | 6 characters of `0123456789abcdefghjkmnpqrstvwxyz` (no `i l o u`), random | `id.format`; must equal the file name's prefix (`id.file-name`); unique in the store (`id.duplicate`, both files grant nothing) | | `subject` | yes | a reference (below): `person:`, `group:`, `device:` or `app:` | `ref.format`, `subject.kind` (not allowed for the verb), `subject.unknown` (not in the snapshots) | | `on` | yes for an `app:` subject, not allowed otherwise | a reference: `person:`, `group:` or `device:`: whose devices the app road applies to | `key.missing`, `key.forbidden`, `ref.format`, `subject.kind`, `subject.unknown`. Without it an app road would change the tunnel of every device in the mesh, other people's included (QA B-3) | | `verb` | yes | `can-reach`, `exits-through`, `goes-direct`, `never-online-without`, `custom` | `verb.unknown` | | `object` | yes, except `custom` (where it is not allowed) | a reference: `device:`, `subnet:`, `service:` or `exit:` | `ref.format`, `object.kind`, `object.unknown`, `object.not-exit`, `subnet.not-canonical`, `subnet.unrouted`, `service.shared` (a service that shares its address and a port with another: its rule would open both, QA F-01); a `goes-direct` subnet other than `/0` that holds a mesh address is `direct.mesh` (mesh traffic never goes direct, QA F-02) | | `until` | no | RFC 3339 with an offset: `2026-11-29T23:59:59+01:00` or `…Z`; exclusive | `until.format`; `until <= now` makes the road *inactive* (`road.expired`) | | `ports` | no; only `can-reach` | a list of `tcp/443`, `udp/53`, `tcp/8000-8100`, `tcp`, `udp`, `icmp`; absent means all traffic | `ports.format`; for a service, every port must be one it serves (`ports.not-served`) | | `via` | no; only `can-reach` | `device:` of a device with `relay` or `exit` | `via.format`, `via.unknown`, `via.not-relay` | | `classic` | no; only `can-reach`, `exits-through`, `custom` | `true` or `false` (default) | `classic.format`; a road that would make a peer of a classic device needs `true` (`classic.unacknowledged`) | | `created` | yes | RFC 3339 with an offset | `created.format` | Any other key is `key.unknown`. A key that the verb does not take is `key.forbidden`. A list where a single value belongs, or a single value where a list belongs, is `key.type`. A required key that is missing or empty is `key.missing`. `until` and `ports` narrow a road, and absent is their widest value (no end, all traffic), so either key present with an empty value (`until:`, `until: # Sunday`, `ports:`) is `key.empty`: clearing a field never widens a road (QA F-09). `ports: []` is `ports.format`. ### References | Form | Meaning | Id rules | |:--|:--|:--| | `person:` | a person in `directory.json` | opaque: 1–64 of `[A-Za-z0-9_-]` (no people directory exists in Fundamentum yet) | | `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 the devices its road's `on` names (QA B-3) | 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`) 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 | ### The body 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). 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. ### Canonical form The form `via` writes, and which reads back byte for byte: `---`, then the keys in the order `id, subject, on, verb, object, until, ports, via, classic, created`, absent keys left out, scalars plain when they read back unchanged and double-quoted otherwise, `ports` as a flow list, LF line endings, `---`, then the body. A custom road's body is ```` ```raw\n ```` + raw + ```` ```\n ````. ``` --- id: k3f9q2 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. ``` ### Inactive roads Valid roads that grant nothing right now, reported with their reason (not errors for `via check`): | Code | When | |:--|:--| | `road.expired` | `until <= now` | | `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.tunnelled` | for one device: a `goes-direct` subnet inside a net its plan sends through the tunnel (a route it reaches, a peer's address); the tunnel wins and the entry is dropped (reported per road, naming the device, QA F-02) | | `road.family` | a `can-reach` road from devices whose mesh address is IPv4 to an IPv6 place, or the other way: those devices get nothing (a rule that could never match), reported naming them (QA F-06) | | `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 ```json { "format": 1, "people": [ { "id": "jana", "name": "Jana" } ], "groups": [ { "id": "household", "name": "Household", "members": ["mark", "jana"] } ] } ``` | Field | Rules | |:--|:--| | `format` | `1` (`snapshot.format`) | | `people[].id` | a person id (`directory.id`), unique (`directory.duplicate`) | | `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, no repeats (`directory.member`); a well-formed id that is not a person in `people` is left out of the group (`directory.member-unknown`) | Unknown fields, bad JSON and a missing file are `snapshot.json`. **Structural errors and dangling references (QA F-04).** Any error in either snapshot means no plan at all, with two exceptions: a group member and a device owner that are well-formed ids but not people in the directory. That is what deleting a person upstream leaves behind, before anybody edits `devices.json`. Each is still an error and is reported, but it removes only itself: the member leaves the group, and the device becomes ownerless, so only `device:` roads reach it. Everybody else keeps their plans. "No plans" is kept for what makes the snapshot unreadable: bad JSON, a wrong format, a malformed or duplicate id, key or address. ## `devices.json` — the device list ```json { "format": 1, "devices": [ { "key": "AgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgI", "name": "home-server", "owner": "mark", "address": "100.96.0.2", "classic": false, "exit": true, "relay": true, "routes": ["192.168.100.0/24"], "services": [ { "host": "photos.home.arpa", "ports": ["tcp/443"] } ] } ] } ``` | Field | Default | Rules | |:--|:--|:--| | `format` | — | `1` | | `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 (`devices.owner`). One that is not in the directory leaves the device ownerless (`devices.owner-unknown`, reported). 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, not loopback, link-local, multicast or IPv4-embedding IPv6, and never an internet address, so an exit's `internet` rule can never cover a mesh device (QA F-08): use `100.64.0.0/10` or a ULA (`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: 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`) | | `services[].address` | none | the service's own mesh address on this device, under the same rules as a device `address` and unique among all of them (`devices.address`). A firewall sees addresses and ports, not hostnames: a road to a service compiles to its own address when it has one, else to the device's, and a road to a service that shares that address **and** a port with another service is refused (`service.shared`, QA F-01), because its rule would open the other one too | ## The plan One per device, the compiler's output. JSON (pretty, two spaces, field order as below) for people and tests; CBOR inside the control protocol. Every list is sorted, every `roads` list is the sorted ids that caused the entry. | Field | Meaning | |:--|:--| | `format` | `1` | | `device`, `name`, `address`, `classic` | this device | | `services[]` | `{host, address}`: the services this device hosts on an address of their own; it must answer on each (QA F-01). A road to such a service reaches that address only; a `device:` road reaches the device's address and all of these | | `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}` or `null`. `through` is `null` (only the mesh) when two kill-switch roads disagree, or when a kill-switch road has an error: a restriction fails closed, it is never dropped (QA F-03). `roads` lists the erroneous road too | | `direct[]` | `{app, subnet, except, roads}`: traffic to `subnet` bypasses the tunnel (split tunnelling); `app` is `null` for all traffic, or the one app whose traffic goes direct. `except` lists the nets inside `subnet` that this plan sends through the tunnel (its peers' non-default allowed IPs): they stay in the tunnel, whatever the platform's route order. A platform that cannot keep them in (an app-level bypass) must not apply the entry (QA F-02) | | `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`, `172.16.0.0/12`, `192.168.0.0/16`, `::1/128`, `fc00::/7` and `fe80::/10`. ## The control protocol (`proto`) CBOR (RFC 8949), one message per frame, at most **1 MiB**. Framing and transport are Day 3. ``` Envelope = { "v": 1, "body": Body } Body = { "plan-request": { "device": key, "have": digest | null } } | { "plan": { "digest": digest, "plan": Plan } } | { "plan-ack": { "device": key, "digest": digest } } | { "refused": { "code": text, "message": text } } ``` | Field | Meaning | |:--|:--| | `v` | protocol version, `1`. Read **first**: any other version is `UnsupportedVersion(v)` before the body is looked at | | `device` | a device key, as in road files | | `digest` | SHA-256 of the plan's CBOR encoding, 64 lowercase hex characters; a `plan` whose digest does not match its plan is refused | | `have` | the digest the device already holds, so the server can answer "unchanged" (Day 3) | | `code` | `unknown-device`, `bad-request`, `unavailable` | | `Plan` | the plan above, the same field names, CBOR maps in that field order | Decoding refuses: more than 1 MiB, trailing bytes after the message, an unknown field anywhere, a missing field, a wrong version, and a malformed key or digest. Encoding is deterministic: the same value gives the same bytes. Signatures are **not** in version 1. Day 3 adds them with the device's Tessera key, as version 2.