mirror of
https://github.com/ruvnet/ruflo.git
synced 2026-11-23 21:59:14 +09:00
* docs(adr): ADR-111 — federation network mesh via WireGuard Optional in-tree WG mesh layer for the federation plugin. Replaces Tailscale Inc. dependency for the common case (≤50 peers, direct UDP reachable, no NAT traversal needed) while keeping Tailscale as the right answer when its specific value-adds are needed. Key design choices: - OPT-IN via config.wgMesh — existing tailnet+ws path remains default - WG public keys exchanged via existing federation manifests (same Ed25519 trust chain we already ship) - Trust levels (UNTRUSTED → PRIVILEGED) project to packet-layer AllowedIPs slices — no two-system drift between federation trust + network access - Breaker SUSPEND/EVICT instantly removes peer from mesh (Tailscale fundamentally lacks this — compromised tailnet device stays in the network until manual admin action) - Every coordination change witness-signed (Ed25519, append-only) — cryptographic provenance Tailscale's central panel can't offer Anti-goals explicitly documented: - NAT traversal (use Tailscale) - DERP relays (use Tailscale) - MagicDNS, SSO (federation already has identity) - Windows/mobile (v1 = Linux + macOS) 7-phase implementation plan, 14-18 days for v1, 30 with full firewall hardening across linux nftables + macOS pf. Co-Authored-By: RuFlo <ruv@ruv.net> * feat(federation): ADR-111 Phases 1-3 — opt-in WG mesh layer Implements the in-tree WireGuard control plane laid out in v3/docs/adr/ADR-111-federation-wg-mesh.md. Closes the federation-trust ↔ packet-layer-reachability gap: when the breaker SUSPENDs or EVICTs a peer, the same transition propagates to WG AllowedIPs, so a peer the trust layer just blocked can't reach the rest of the mesh at L3 either. OPT-IN (config.wgMesh + integrations.wgMesh) — the default tailnet+ws path remains untouched. No new runtime deps; X25519 keypair generation uses Node's core crypto. ## Phase 1 — Manifest extension + key generation - `domain/value-objects/wg-config.ts` - `WgManifestSection` (publicKey, endpoint, meshIP), `WgLocalKey` - `generateWgKeyPair()` — X25519 via Node `generateKeyPairSync`, extracts raw 32-byte key from PKCS8/SPKI DER → base64 (the WG wire format). - `deriveMeshIP(nodeId, subnet, usedIPs)` — sha256(nodeId) → host octets, clamps .0/.255 to avoid network/broadcast collisions, rotates the hash input on usedIPs hit (bounded 1024-probe retry). - `FederationManifest.wg?` — optional manifest section; Ed25519 sig already covers the block since it's part of `Omit<FM, 'signature'>`. ## Phase 2 — WgMeshService - `domain/services/wg-mesh-service.ts` - `WG_NETWORK_GATES`: trust-level → port-rule table (ADR section). - `buildInterfaceConfig(peers)` — pure-projection wg-quick config string. Operator writes + runs `wg-quick up`; service never shells out per CLAUDE.md destructive-actions guidance. - Breaker hooks: `removeAllowedIPs` (soft-block via empty AllowedIPs), `restoreAllowedIPs` (set-allowed-ips), `removePeer` (terminal). - Defense-in-depth: `formatCmd` regex-validates every arg before splicing — refuses any string with shell metachars. - `summarize()` for the eventual `federation_wg_status` MCP tool (Phase 6). ## Phase 3 — Coordinator/breaker wiring - `FederationCoordinatorIntegrations.wgMesh` + `wgCommandSink`. - `evictPeer()` → after successful evict: `wgMesh.removePeer()` + audit. - `reactivatePeer()` → after successful reactivate: `wgMesh.restoreAllowedIPs()` + audit. - `FederationBreakerService` gains optional `BreakerTransitionListener` 3rd constructor arg — fires post-transition (apply mode only); errors are swallowed so failing WG propagation can't unwind a successful entity transition. Coordinator wires this to drive auto-suspend WG ops. - No-op for peers without `metadata.wgPublicKey` / `metadata.wgMeshIP`, so mixed-deployment safety preserved. ## ADR doc fixes - Status flipped: Proposed → Accepted (Phases 1-3 Implemented). - Phase 4 firewall: inconsistent "Phase 2 add" → "Phase 4 add". - Subnet rationale: documented 10.50.0.0/16 choice vs tailscale's 100.64.0.0/10, birthday-collision thresholds, and the collision-handling probe loop. Also notes 10.50.0.0/12 jump for larger deployments. ## Tests - 33 new unit tests across 3 files; all 513 pre-existing tests still pass. - `wg-config.test.ts` — keygen format/uniqueness, IP determinism, .0/.255 clamping, custom subnets, collision handling, error paths. - `wg-mesh-service.test.ts` — config generation, trust filtering, suspend/restore/evict commands, shell-injection rejection, summarize(). - `wg-coordinator-integration.test.ts` — evictPeer/reactivatePeer emit WG commands; no-op for peers without wg metadata; breaker onTransition listener fires on successful transition. ## Not in this PR (separate phases tracked in #1879) - Phase 4 — trust-graded firewall (nftables/pf projection) - Phase 5 — witness attestation chain for mesh changes - Phase 6 — operator MCP tools (federation_wg_status / _attest / _keyrotate) - Phase 7 — cross-OS validation (mac↔ruvultra), federation alpha bump Co-Authored-By: RuFlo <ruv@ruv.net> --------- Co-authored-by: Reuven <cohen@ruv-mac-mini.local>