diff --git a/cli/administration/inventory/mesh/inventory.py b/cli/administration/inventory/mesh/inventory.py index 428e399c5d..84cbc7833e 100644 --- a/cli/administration/inventory/mesh/inventory.py +++ b/cli/administration/inventory/mesh/inventory.py @@ -57,6 +57,7 @@ def specs_of(group_vars_file: Path) -> list[MeshSpec]: if not isinstance(declared, list) or not declared: raise ValueError(f"{group_vars_file} declares no {MESHES_VAR}") + pool = document.get(POOL_VAR) specs = [ MeshSpec( name=entry["name"], @@ -65,10 +66,11 @@ def specs_of(group_vars_file: Path) -> list[MeshSpec]: subnet=entry["subnet"], listen_port=int(entry["listen_port"]), spoke_group_prefixes=tuple(entry.get("spoke_group_prefixes", ())), + routed_range=entry.get("routed_range") or pool or entry["subnet"], ) for entry in declared ] - assert_no_subnet_overlap(specs, document.get(POOL_VAR)) + assert_no_subnet_overlap(specs, pool) return specs diff --git a/cli/administration/inventory/mesh/model.py b/cli/administration/inventory/mesh/model.py index aac385cd5d..68557eebc3 100644 --- a/cli/administration/inventory/mesh/model.py +++ b/cli/administration/inventory/mesh/model.py @@ -22,6 +22,9 @@ class MeshSpec: this declaration changing. subnet: the mesh address range, as ``a.b.c.0/24``. listen_port: UDP port the hub listens on. + routed_range: the range a spoke routes through the hub. Wider than + ``subnet`` whenever a spoke must reach a plane it is not a member + of, which is the entire point of the hub being in both. """ name: str @@ -30,6 +33,7 @@ class MeshSpec: subnet: str listen_port: int spoke_group_prefixes: tuple[str, ...] = () + routed_range: str = "" @dataclass(frozen=True) diff --git a/cli/administration/inventory/mesh/write.py b/cli/administration/inventory/mesh/write.py index 63ed0640f9..903571fcd2 100644 --- a/cli/administration/inventory/mesh/write.py +++ b/cli/administration/inventory/mesh/write.py @@ -97,8 +97,14 @@ def _peer_entries(mesh: Mesh, host: str) -> list[CommentedMap]: entry["host"] = peer.host entry["public_key"] = peer.public_key entry["address"] = peer.address + # Exception: a spoke routes the whole pool through the hub, not just + # its own mesh. A worker is not a member of the data plane, so pinning + # this to the mesh subnet leaves it with no route to the NFS server and + # the mount fails while every tunnel still reports a healthy handshake. entry["allowed_ips"] = ( - mesh.spec.subnet if peer.is_hub else peer.address + HOST_PREFIX_32 + (mesh.spec.routed_range or mesh.spec.subnet) + if peer.is_hub + else peer.address + HOST_PREFIX_32 ) entry["is_hub"] = peer.is_hub entries.append(entry) diff --git a/tests/unit/python/cli/administration/inventory/mesh/test_write.py b/tests/unit/python/cli/administration/inventory/mesh/test_write.py index b924f8145b..7180d60d5a 100644 --- a/tests/unit/python/cli/administration/inventory/mesh/test_write.py +++ b/tests/unit/python/cli/administration/inventory/mesh/test_write.py @@ -157,6 +157,36 @@ class TestMeshShapeOnDisk(MeshOnDisk, unittest.TestCase): self.assertIn("swarm:", text) self.assertIn("data:", text) + def test_a_spoke_routes_the_whole_pool_through_the_hub(self): + """A worker must reach the data plane it is not a member of. + + Pinning a spoke's AllowedIPs to its own mesh subnet leaves the worker + with no route to the NFS server, and the mount fails while every tunnel + still reports a healthy handshake -- so the symptom points at storage + rather than at routing. + """ + self._write_all() + for spec in self.specs: + mesh = plan_mesh(spec, self.groups) + for spoke in mesh.spokes: + with self.subTest(mesh=spec.name, spoke=spoke.host): + peers = mesh.peers_of(spoke.host) + self.assertEqual([p.host for p in peers], [mesh.hub.host]) + self.assertEqual(spec.routed_range, "10.100.0.0/16") + + def test_the_hub_pins_each_spoke_to_a_single_address(self): + """The inverse of the spoke rule. + + A hub that routed the pool to one spoke would blackhole every other + member behind it. + """ + self._write_all() + for spec in self.specs: + mesh = plan_mesh(spec, self.groups) + for peer in mesh.peers_of(mesh.hub.host): + with self.subTest(mesh=spec.name, peer=peer.host): + self.assertFalse(peer.is_hub) + class TestIdempotence(MeshOnDisk, unittest.TestCase): def test_a_second_run_leaves_every_file_byte_identical(self):