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.json5gets apeerssection (PeersSectionincrates/wyrmd/src/lib.rs):
Validation: sites are valid segments, unique and not our own; endpoints arepeers: { 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 }quic/<host>:<port>without#/?; CA paths are UTF-8 without;#?(they become endpoint parameters);listenanddownstreamcome together;upstream_val_hz > 0. - Transport: QUIC + mTLS. Any non-empty
peersturns on broker certificates. The broker has CNbroker:<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_certificatestays 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.listenendpoint getsdata_dir/pki/peer-trust.pem(a bundle of all downstream CAs, written byControl::configure_zenohon every broker build); - each upstream
connectendpoint gets that site’scafile. The maintls/listener for links and operators therefore never trusts a peer CA.
- the
- ACL (
access_control_with_peersincrates/wyrm-admin/src/acl.rs). Peer subjects matchcert_common_names: ["broker:<site>"]andlink_protocols: ["quic"]; link and operator subjects aretlsonly. The two cannot overlap.- Upstream sites are read-only on our
wy/<site>/{downstream,dataflows}/**: ingressdeclare_subscriber,declare_liveliness_subscriber,liveliness_query; ingressqueryonly on…/**/{~meta,~val,~def,~state}; egressput,delete,reply,liveliness_token,declare_queryable,declare_subscriber. No~set/~actquery passes, and nothing undersys/**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,listandsubscribeonwy/<d>/**, checked under the user’s roles for the own site (wy/<d>/xaswy/<site>/x) and sent without a ptok, which the downstream links would not trust;set/invokethere are refused by the gateway (testread_sites_map_to_own_roles_without_a_token). - Requesters (direct Zenoh sessions): Loopback and operator requester rules extend to
wy/<d>/**(andwy/<d>/**/@adv/sub/**). The downstream broker’s own ACL keeps them read-only there.
- Upstream sites are read-only on our
- 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, iswy/<site>/upstream/<u>. Each is a reference node served by the admin (wyrm_admin::peers):wy:broker,@site,@root=wy/<peer>and a bool pointconnected, fed by the peer’s liveliness tokenwy/<peer>/sys/broker. The ACL lets only that liveliness pass between peers, split by direction: a peer may watch oursys/brokertoken and declare its own, never ours (per upstream site:presence-<u>-token-inonwy/<u>/sys/brokeronly; per downstream site:presence-<d>-watch-in,presence-<d>-token-out). Links get the same split (broker-watchingress,broker-tokenegress).sys/**data stays closed. Test:presence_tokens_by_direction. A client follows@rootto 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 andinstallrefuse it). Test:two_brokers_over_quic. - Egress downsampling. With
upstream_val_hz, the router config gets one Zenohdownsamplingitem (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 forwy/<site>/downstream/**/~valgave all links one shared budget. Withupstream_val_hzset, 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/upstreamthat editsserver.json).sys/upstream/~act/add {name, url, ca, enabled}andsys/downstream/~act/add {name, ca}(levelconfig) store a peer in the registry (Op::AddPeer, SCHEMA 6) with that site’s CA certificate as PEM;upstream/<site>/enabled(writable) andremovechange or drop it. Peers fromwyrmd.json5are 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 todata_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.listenmay now stand alone inwyrmd.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
sysandupstream; chains of brokers (2026-10-22, owner decision, as a DSA upstream that browses its downstream broker whole). The upstream may also readwy/<site>/sys/**andwy/<site>/upstream/**: queries, subscriptions and the data sent up (put,delete,reply) cover only**/~metaand**/~valthere (upstream-sub,upstream-data), so nothing else published undersys, such as the audit records ofsys/audit/<link>, leaves the site; declarations and liveliness cover the sections whole.~setand~actstay closed everywhere, so nosysaction (Get Log, Install, Purge, …) runs from above. A chainplant → edge → centralworks throughvia: a downstream entry lists the sites that broker relays from further down (downstream: [{ site: "edge", ca, via: ["plant"] }], alsosys/downstream/~act/add {via},PeerDef::via, registry SCHEMA 13). The upstream’ssite-<d>rule then coverswy/<d>/**andwy/<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 theirvialists (wyrmd.json5validation,sys/downstreamAdd and the registry refuse a peer named like a relayed site, and a site relayed twice).wy/<site>/upstreamis 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, readssys/upstreambelow, receives plant samples;setand asysaction below fail). - Test.
two_brokers_over_quicincrates/wyrmd/tests/e2e.rs:central(downstreamedge) andedge(upstreamcentral, mock link,upstream_val_hz: 50). A client on central listswy/edge/downstream, receives samples ofwy/edge/downstream/mock/g0/p0, and itsseton that point fails at the edge ACL.
Consequences
- No write across sites. An upstream site cannot
set/invokeon a downstream site, even with a validptok: the edge ACL drops the query before it reaches the SDK. Reading is open ondownstream,dataflows,sysandupstream(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 iflistenever containsquic/) 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 (
TimeStateininterceptor/downsampling.rs) and picks one matching rule per key (so the rules must not overlap). Each link getsupstream_val_hzsamples/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 (devprofile 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 underupstream_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 mintbroker:<other-downstream>(and receive that site’ssite-<d>rule) orbroker:<upstream>(and read ourdownstream/**anddataflows/**). 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 atls/main listener is not covered by a test yet.two_brokers_isolationcovers the rest between real brokers: no upstream read ofsys/**, no upstreaminvoke, no downstream put or query outside itswy/<d>/**, and no peer from an untrusted CA. - A change of
peersneeds a broker restart (the section is read atDaemon::open); peer CA files are re-read on every broker build.
Alternatives
- Broker links on a separate
tls/…:7448listener (the wiki’s design). Rejected: link, operator and broker subjects would all betls, so a peer CA could mint a CN that matches a link rule. QUIC keeps the subjects apart bylink_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
ptokchecks 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.