Repository navigation
WireGuard mesh between hosts, with routes to each host's bridge subnet - #96
Merged
Merged
Conversation
#84) fleet.yml's `mesh:` (enabled, interface, listen_port, subnet) and each host's `hosts.<name>.mesh` (public_key, optional address and endpoint). Each daemon converges its own side through the normal plan and apply: a wg-quick@wg0 unit whose config has no private key (PostUp sets it from the key file), one peer per other host with AllowedIPs = its tunnel address and its bridge subnet (so wg-quick routes every bridge over the mesh), IP forwarding, and ufw rules marked 'native-ops mesh' for the WireGuard port and mesh traffic between tunnel addresses and bridges. The private key is generated on the host by a script fed on stdin and never leaves it. The first apply generates it; the plan then blocks with "this host's mesh public key is X; add it to hosts.<name>.mesh.public_key" until fleet.yml has every host's matching key. The plan reads the host through one fixed probe script that the read-only executor lets through byte for byte. With mesh absent or disabled nothing is read or planned, and plans, their JSON and their hashes are unchanged (golden test). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
wmantly
added a commit
that referenced
this pull request
Nov 5, 2026
… reconcile Only the docs conflicted: README's node-02 example now shows both its incus_remote and its mesh key, and the daemon.md roadmap lists the mesh, DNS and reconcile per host, host-keyed backups and the migrate job as done. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #84. Part of #43.
What changed
Config.
fleet.ymlgetsmesh:withenabled,interface(defaultwg0),listen_port(default 51820) andsubnet. Each host getshosts.<name>.meshwithpublic_key, and optionallyaddressandendpoint. A tunnel address ismesh.addressif set; otherwise it is the subnet's (i+1)th address for the i-th host in sorted name order, so every daemon derives the same addresses. When the mesh is enabled,fleet.ymlis refused if:A disabled
mesh:is not checked (pkg/config/mesh.go).Plan and apply (
pkg/engine/mesh.go).FleetPlangets ameshpart, and each daemon plans its own host's side:mesh-key: generates the key on the host.mesh-interface/mesh-peer: writes/etc/wireguard/wg0.conf. Each peer'sAllowedIPsis that peer's tunnel/32plus that peer's bridge subnet.mesh-route: the bridge routes, which wg-quick creates fromAllowedIPs.mesh-restart: enables and startswg-quick@wg0, and restarts it only when the config changed, a route is missing, or the unit is down.mesh-forward:net.ipv4.ip_forward=1, persisted in/etc/sysctl.d/60-native-ops-mesh.conf.mesh-firewall: the ufw rules.Apply reads the host again and plans again with the same function. If the result differs from the approved plan, it refuses and says to plan again. A converged host plans nothing, and a second apply changes nothing.
Key exchange. The private key is generated on the host by a script fed on stdin (
wg genkeyinto/etc/wireguard/wg0.key, mode 0600) and never leaves it:PrivateKeyline (PostUp = wg set %i private-key …);wg0.pub.The steps:
this host's mesh public key is X; add it to fleet.yml as hosts.<name>.mesh.public_key, and the key is also in the plan JSON (mesh.public_key). The plan also blocks on a peer's missing key, a missing endpoint, or a key that differs from the host's. A plan never replaces a host's key.Read-only. The plan reads the host through one fixed probe script (
pkg/remote/meshprobe.go).remote.ReadOnlylets it through only when both the command and the stdin match it byte for byte; every other script is still refused.Firewall (A service's declared forwards: publishes a port, but the host firewall is not part of the plan #75). This is the smallest correct step. When ufw is active, the daemon manages only rules with
comment 'native-ops mesh':allow <port>/udp;wg0from each peer's tunnel address to this host's;wg0from each peer's tunnel address and bridge subnet to this host's bridge subnet.It removes mesh rules that are no longer needed and never touches other rules. When ufw is inactive, the plan notes that no rules were written.
Docs. A "Mesh between hosts" section in
docs/daemon.mdcovers the key exchange, how bridge IPs become reachable, andinstance migrateover the tunnel address. The README'sfleet.ymlreference and its migrate note are updated, and so are the roadmap and the migrate bullet that pointed at WireGuard mesh between hosts, with routes for each host's bridge subnet #84.Mesh off is unchanged. With
mesh:absent orenabled: false, nothing is read or planned.TestMeshOffChangesNothingchecks that the text, JSON and hash match the existing golden frommain. The hash only takes a new shape when a plan has a mesh part.Design choices to review
hostBootstrapCommands), and the bootstrap does not use networkd.ManageForeignRoutesdefault it can drop routes it doesn't own.AllowedIPs.PostUpsetting the key, the config file has no secret in it, so the plan can compare the whole file.fleet.ymlthat refused a host without a key would make the first deploy, the one that generates the keys, impossible. Malformed keys, addresses and subnets are still refused when the file loads.Not done here (needs #75 or follow-ups)
route allow out on <bridge>lets any forwarded traffic reach the bridge), and the rest of the host firewall, are still outside the plan (A service's declared forwards: publishes a port, but the host firewall is not part of the plan #75).incus remote add <peer> https://<tunnel>:8443, pluscore.https_address) is documented, not automated.ufw show addedprints the mesh rules in exactly the form the plan compares against (ufw route allow in on wg0 out on incusbr0 from A to B comment 'native-ops mesh'). If it does not, the plan would keep showing firewall changes on a converged host. The ufw commands themselves are idempotent, so nothing would break.Checks
gofmt -l .: prints nothinggo mod tidy && git diff --exit-code go.mod go.sum: cleango vet ./...: passesgo test -race ./...: all packages passnode --check pkg/server/ui/static/js/app.js: passesgo test.No self-merge.
🤖 Generated with Claude Code