Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

ADR 0007 — Peer brokers: QUIC + mTLS, read-only upstream

Status: accepted · 2026-10-20 · “read-only upstream” reversed by ADR 0018 (2026-10-24: commands from above on devices, flows and storage; sys with allow_config) · trust and admission amended by ADR 0015 (2026-10-23): downstream brokers hold certificates from the upstream’s CA; peer-trust.pem, peers.downstream[].ca and sys/downstream are gone, and the accepted peer-CA risk below no longer applies. The text below records the design before that

Context

Iteration 4 connects brokers of different sites (plant → central, edge → cloud). Each site has its own CA (wyrm-admin PKI) and its own ACL (ADR 0006). An upstream site must see a downstream site’s tree and values without becoming able to command its devices, and a peer CA must not be able to mint identities that the local ACL treats as links or operators. Full site names are used everywhere (spec 01), so routing needs no prefix rewriting.

Decision

  • Config. wyrmd.json5 gets a peers section (PeersSection in crates/wyrmd/src/lib.rs):
    peers: {
      listen: "quic/0.0.0.0:7448",                  // only with downstream
      downstream: [{ site: "edge", ca: "edge-ca.pem" }],
      upstream: [{ site: "central", endpoint: "quic/central.example:7448", ca: "central-ca.pem" }],
      upstream_val_hz: 1.0,                         // optional
    }
    
    Validation: sites are valid segments, unique and not our own; endpoints are quic/<host>:<port> without #/?; CA paths are UTF-8 without ;#? (they become endpoint parameters); listen and downstream come together; upstream_val_hz > 0.
  • Transport: QUIC + mTLS. Any non-empty peers turns on broker certificates. The broker has CN broker:<site> for both its server certificate (SANs = tls_names) and its client certificate, both issued by its own CA.
  • Per-endpoint trust. The global transport/link/tls/root_ca_certificate stays our own CA alone. Peer CAs are trusted only on the QUIC broker endpoints, through the endpoint parameter #root_ca_certificate_file=. Zenoh merges endpoint config over the global link config, and the endpoint wins:
    • the peers.listen endpoint gets data_dir/pki/peer-trust.pem (a bundle of all downstream CAs, written by Control::configure_zenoh on every broker build);
    • each upstream connect endpoint gets that site’s ca file. The main tls/ listener for links and operators therefore never trusts a peer CA.
  • ACL (access_control_with_peers in crates/wyrm-admin/src/acl.rs). Peer subjects match cert_common_names: ["broker:<site>"] and link_protocols: ["quic"]; link and operator subjects are tls only. The two cannot overlap.
    • Upstream sites are read-only on our wy/<site>/{downstream,dataflows}/**: ingress declare_subscriber, declare_liveliness_subscriber, liveliness_query; ingress query only on …/**/{~meta,~val,~def,~state}; egress put, delete, reply, liveliness_token, declare_queryable, declare_subscriber. No ~set/~act query passes, and nothing under sys/** is visible.
    • Downstream sites serve their own wy/<d>/**: all messages, both directions, on that key space only.
    • Our requesters may read downstream sites. The user gateway does too (GatewayConfig.read_sites = peers.downstream): meta, children, list and subscribe on wy/<d>/**, checked under the user’s roles for the own site (wy/<d>/x as wy/<site>/x) and sent without a ptok, which the downstream links would not trust; set/invoke there are refused by the gateway (test read_sites_map_to_own_roles_without_a_token).
    • Requesters (direct Zenoh sessions): Loopback and operator requester rules extend to wy/<d>/** (and wy/<d>/**/@adv/sub/**). The downstream broker’s own ACL keeps them read-only there.
  • Peer nodes in the tree (spec 01 0.1.5). Downstream is what connects to a broker, so a downstream site is a node beside the links: wy/<site>/downstream/<d>. An upstream site, which this broker connects to, is wy/<site>/upstream/<u>. Each is a reference node served by the admin (wyrm_admin::peers): wy:broker, @site, @root = wy/<peer> and a bool point connected, fed by the peer’s liveliness token wy/<peer>/sys/broker. The ACL lets only that liveliness pass between peers, split by direction: a peer may watch our sys/broker token and declare its own, never ours (per upstream site: presence-<u>-token-in on wy/<u>/sys/broker only; per downstream site: presence-<d>-watch-in, presence-<d>-token-out). Links get the same split (broker-watch ingress, broker-token egress). sys/** data stays closed. Test: presence_tokens_by_direction. A client follows @root to open a peer site inside the tree of the broker it is connected to; the peer’s keys keep their one name. A link id may not be a downstream site name (wyrmd config and install refuse it). Test: two_brokers_over_quic.
  • Egress downsampling. With upstream_val_hz, the router config gets one Zenoh downsampling item (link_protocols: ["quic"], flows: ["egress"], messages: ["put"]) with one rule per link: key_expr: wy/<site>/downstream/<link>/**/~val, freq: upstream_val_hz (wyrmd::upstream_downsampling). Amended 2026-10-21 (owner decision): before, one rule for wy/<site>/downstream/**/~val gave all links one shared budget. With upstream_val_hz set, installing or removing any link (also embedded) rebuilds the broker, so the rules follow the registry.
  • Peers at runtime (2026-10-22, owner decision, as DSA’s /sys/upstream that edits server.json). sys/upstream/~act/add {name, url, ca, enabled} and sys/downstream/~act/add {name, ca} (level config) store a peer in the registry (Op::AddPeer, SCHEMA 6) with that site’s CA certificate as PEM; upstream/<site>/enabled (writable) and remove change or drop it. Peers from wyrmd.json5 are shown read-only (origin: config). Every consumer uses the merged list (Control::peers): the ACL, the peer nodes, the router’s connect endpoints (Control::upstream_endpoints), peer-trust.pem (runtime CAs are written to data_dir/pki/peers/<site>.pem; the bundle file is deleted when no downstream CA is left), the link-id checks and the gateway’s readable sites. A disabled upstream is out of all of them. peers.listen may now stand alone in wyrmd.json5; the QUIC listener opens only while a downstream site exists. A CA must parse as one PEM certificate with the CA basic constraint (16 KiB max). Each change is audited (peer_add, peer_remove, peer_enable) and rebuilds the router. Test: runtime_peers_over_quic (no peers in either json5; central adds the edge’s CA, the edge adds central as upstream and sees it connected, central reads the edge tree; disabling the upstream drops it).
  • Upstream reads sys and upstream; chains of brokers (2026-10-22, owner decision, as a DSA upstream that browses its downstream broker whole). The upstream may also read wy/<site>/sys/** and wy/<site>/upstream/**: queries, subscriptions and the data sent up (put, delete, reply) cover only **/~meta and **/~val there (upstream-sub, upstream-data), so nothing else published under sys, such as the audit records of sys/audit/<link>, leaves the site; declarations and liveliness cover the sections whole. ~set and ~act stay closed everywhere, so no sys action (Get Log, Install, Purge, …) runs from above. A chain plant → edge → central works through via: a downstream entry lists the sites that broker relays from further down (downstream: [{ site: "edge", ca, via: ["plant"] }], also sys/downstream/~act/add {via}, PeerDef::via, registry SCHEMA 13). The upstream’s site-<d> rule then covers wy/<d>/** and wy/<via>/**, its requesters and gateway (read_sites) may read them, and the middle broker lets its own upstream read the sites below it with the same read-only rules (acl::Peers::reachable). Each upstream decides by configuration which sites a downstream may serve; a site name appears once among all peers and their via lists (wyrmd.json5 validation, sys/downstream Add and the registry refuse a peer named like a relayed site, and a site relayed twice). wy/<site>/upstream is always served (empty without upstream), so a client opening a site finds its four sections. Tests: peer_brokers, chains_of_brokers (ACL), chain_of_three_brokers (e2e: central lists plant’s links through edge, reads sys/upstream below, receives plant samples; set and a sys action below fail).
  • Test. two_brokers_over_quic in crates/wyrmd/tests/e2e.rs: central (downstream edge) and edge (upstream central, mock link, upstream_val_hz: 50). A client on central lists wy/edge/downstream, receives samples of wy/edge/downstream/mock/g0/p0, and its set on that point fails at the edge ACL.

Consequences

  • No write across sites. An upstream site cannot set/invoke on a downstream site, even with a valid ptok: the edge ACL drops the query before it reaches the SDK. Reading is open on downstream, dataflows, sys and upstream (2026-10-22): the upstream’s administrators see the downstream’s links, packages, peers, history settings and status values, as in DSA. Cross-site commands need a later design (e.g. a relay on the downstream site that re-signs with a local token).
  • Downsampling selects by link protocol, not by peer CN. Zenoh downsampling has no certificate subject. Any quic/ session (also a link or operator if listen ever contains quic/) gets the same rate limit on our ~val.
  • The rate is per rule, so per link, not per key. Zenoh 1.10.1 keeps one timestamp per rule per transport (TimeState in interceptor/downsampling.rs) and picks one matching rule per key (so the rules must not overlap). Each link gets upstream_val_hz samples/s towards each peer: a busy link cannot starve another link, but a busy point can still starve a slow point of the same link. Keys of a link that is not in the registry (dev profile only) are not limited. Per-key limits would need a WYRM-side relay. Test: two_brokers_over_quic (a 160 samples/s link and a 2 samples/s link under upstream_val_hz: 5; the slow one gets its samples).
  • Trusting a peer CA means trusting that site not to impersonate others. All downstream CAs share one peer-trust.pem, and ACL subjects match the CN, not the issuer. A trusted downstream CA can mint broker:<other-downstream> (and receive that site’s site-<d> rule) or broker:<upstream> (and read our downstream/** and dataflows/**). Zenoh 1.10 cannot bind a CN to a CA. Accepted (owner decision 2026-10-21): each site runs its own PKI and the operators exchange CA certificates on purpose; adding a downstream CA is a trust decision about that site’s administrators. A federation CA and certificate pinning were considered and rejected as more operational work than the risk warrants. Note: quarantine does not cover this case, because an impersonating certificate carries a CN that is already configured (broker:<site>).
  • The e2e tests use tcp/ main listeners, so the isolation of peer CAs from a tls/ main listener is not covered by a test yet. two_brokers_isolation covers the rest between real brokers: no upstream read of sys/**, no upstream invoke, no downstream put or query outside its wy/<d>/**, and no peer from an untrusted CA.
  • A change of peers needs a broker restart (the section is read at Daemon::open); peer CA files are re-read on every broker build.

Alternatives

  • Broker links on a separate tls/…:7448 listener (the wiki’s design). Rejected: link, operator and broker subjects would all be tls, so a peer CA could mint a CN that matches a link rule. QUIC keeps the subjects apart by link_protocols, and suits WAN/4G better.
  • Add peer CAs to the global root. Rejected: every peer CA could then authenticate on the link listener.
  • Upstream gets write with ptok checks only. Rejected for now: when sites share an admin key (as in the e2e test), a valid token would pass the SDK check. The ACL is a boundary that does not depend on how keys are distributed.
  • Prefix rewriting (virtual site names). Rejected by spec 01: full site names everywhere.