mirror of
https://github.com/kevinveenbirkenbach/computer-playbook.git
synced 2026-11-28 22:06:31 +00:00
feat(network): serve roles on clearnet and onion from one registry
A node runs in NETWORK_MODE clearnet, tor or multi; empty derives multi when svc-net-tor is deployed. meta/networks.yml reachability narrows a role (modes, single_mode, each justified by a network-reachability nocheck), and utils/networks/reachability.py is the one registry every network decision goes through. services.tor keeps only the dependency bond; exclusive and primary are gone and Matrix is single_mode. Every canonical domain gains one sibling per effective network, clearnet first. sys-stk-front-proxy renders one vhost per sibling, and TLS, CSP, injected snippets, redirects, the web health probe and the CSP crawler are decided per vhost. Cross-app URLs follow the network of the vhost being rendered, the SSO issuer stays single, clearnet vhosts of multi roles send Onion-Location, and the shared location forwards X-Forwarded-Host, which lets Wazuh derive its OIDC redirect per request again. The to_onion_url filter is removed; its two consumers render per vhost instead. Measured before commit: on a clearnet node the domain map of all 108 apps and every CSP header are identical to HEAD; on a multi node every role keeps its clearnet domains first and only gains onion siblings, and no CSP source crosses networks except the SSO issuer. Refs: docs/requirements/037-multi-network-serving.md Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
1 parent
42e66e2080
commit
66c8df6729
73 files changed
+1986
-1135
No files matched your search
@@ -1,27 +1,9 @@
|
||||
import unittest
|
||||
|
||||
from plugins.filter.cookie_scope import common_dns_suffix, domain_strings
|
||||
from utils.cache.files import PROJECT_ROOT, read_text
|
||||
|
||||
|
||||
class CommonDnsSuffixTests(unittest.TestCase):
|
||||
def test_sso_template_normalizes_mapping_before_filtering(self):
|
||||
template = read_text(
|
||||
str(
|
||||
PROJECT_ROOT
|
||||
/ "roles/web-app-keycloak/templates/sso_proxy/oauth2-proxy-keycloak.cfg.j2"
|
||||
)
|
||||
)
|
||||
|
||||
normalization = "| domain_strings"
|
||||
self.assertIn(normalization, template)
|
||||
self.assertLess(
|
||||
template.index(normalization), template.index("select('search'")
|
||||
)
|
||||
self.assertLess(
|
||||
template.index(normalization), template.index("reject('search'")
|
||||
)
|
||||
|
||||
def test_domain_pipeline_normalizes_every_supported_shape(self):
|
||||
mapping = {
|
||||
"filer": "filer.seaweedfs.s3.infinito.test",
|
||||
|
||||
@@ -18,10 +18,10 @@ class TestCspFamilyAlignment(unittest.TestCase):
|
||||
self.domains = {
|
||||
"web-app-bigbluebutton": ["bbb.example.org"],
|
||||
"web-app-dashboard": ["dash.abc.onion"],
|
||||
"web-svc-cdn": ["cdn.abc.onion", "cdn.example.org"],
|
||||
"web-app-matomo": ["matomo.abc.onion", "matomo.example.org"],
|
||||
"web-svc-logout": ["logout.abc.onion", "logout.example.org"],
|
||||
"web-app-keycloak": ["auth.abc.onion", "auth.example.org"],
|
||||
"web-svc-cdn": ["cdn.example.org", "cdn.abc.onion"],
|
||||
"web-app-matomo": ["matomo.example.org", "matomo.abc.onion"],
|
||||
"web-svc-logout": ["logout.example.org", "logout.abc.onion"],
|
||||
"web-app-keycloak": ["auth.example.org", "auth.abc.onion"],
|
||||
}
|
||||
|
||||
def test_clearnet_consumer_gets_clearnet_provider_tokens(self):
|
||||
@@ -46,6 +46,21 @@ class TestCspFamilyAlignment(unittest.TestCase):
|
||||
self.assertNotIn("cdn.example.org", header)
|
||||
self.assertNotIn("matomo.example.org", header)
|
||||
|
||||
def test_onion_vhost_of_a_clearnet_consumer_gets_onion_tokens(self):
|
||||
domains = dict(self.domains)
|
||||
domains["web-app-bigbluebutton"] = ["bbb.example.org", "bbb.abc.onion"]
|
||||
header = self.filter.build_csp_header(
|
||||
self.apps,
|
||||
"web-app-bigbluebutton",
|
||||
domains,
|
||||
"https",
|
||||
vhost_domain="bbb.abc.onion",
|
||||
)
|
||||
self.assertIn("http://cdn.abc.onion", header)
|
||||
self.assertIn("http://matomo.abc.onion", header)
|
||||
self.assertNotIn("cdn.example.org", header)
|
||||
self.assertIn("https://auth.example.org", header)
|
||||
|
||||
def test_onion_only_provider_falls_back_for_clearnet_consumer(self):
|
||||
domains = dict(self.domains)
|
||||
domains["web-svc-cdn"] = ["cdn.abc.onion"]
|
||||
@@ -61,5 +76,5 @@ class TestCspFamilyAlignment(unittest.TestCase):
|
||||
header = self.filter.build_csp_header(
|
||||
self.apps, "web-app-bigbluebutton", domains, "https"
|
||||
)
|
||||
self.assertIn("http://cdn.abc.onion", header)
|
||||
self.assertNotIn("https://cdn.abc.onion", header)
|
||||
self.assertIn("https://cdn.example.org", header)
|
||||
self.assertNotIn("cdn.abc.onion", header)
|
||||
@@ -8,6 +8,8 @@ PRIMARY = "infinito.test"
|
||||
|
||||
|
||||
class TestCspOnionMirror(unittest.TestCase):
|
||||
"""Whitelist sources under DOMAIN_PRIMARY follow the vhost's network."""
|
||||
|
||||
def setUp(self):
|
||||
self.filter = FilterModule()
|
||||
self.apps = {
|
||||
@@ -20,6 +22,10 @@ class TestCspOnionMirror(unittest.TestCase):
|
||||
},
|
||||
"svc-net-tor": {"services": {"tor": {"node": NODE}}},
|
||||
}
|
||||
self.domains = {
|
||||
"web-svc-cdn": ["cdn." + PRIMARY, "cdn." + NODE],
|
||||
"app1": ["app1." + PRIMARY, "app1." + NODE],
|
||||
}
|
||||
|
||||
def _tokens(self, header, directive):
|
||||
for raw in header.split(";"):
|
||||
@@ -28,54 +34,40 @@ class TestCspOnionMirror(unittest.TestCase):
|
||||
return [t for t in part[len(directive) :].strip().split(" ") if t]
|
||||
return []
|
||||
|
||||
def _header(self, app_domains):
|
||||
domains = {"web-svc-cdn": ["cdn." + PRIMARY], **app_domains}
|
||||
def _header(self, vhost, domains=None, apps=None):
|
||||
return self.filter.build_csp_header(
|
||||
copy.deepcopy(self.apps),
|
||||
copy.deepcopy(apps or self.apps),
|
||||
"app1",
|
||||
domains,
|
||||
"http",
|
||||
domains or self.domains,
|
||||
"https",
|
||||
domain_primary=PRIMARY,
|
||||
vhost_domain=vhost,
|
||||
)
|
||||
|
||||
def test_primary_keeps_clearnet_and_adds_onion(self):
|
||||
frame = self._tokens(
|
||||
self._header({"app1": ["app1." + NODE, "app1." + PRIMARY]}), "frame-src"
|
||||
)
|
||||
self.assertIn("*." + PRIMARY, frame)
|
||||
self.assertIn("*." + NODE, frame)
|
||||
def test_clearnet_vhost_keeps_clearnet_sources(self):
|
||||
header = self._header("app1." + PRIMARY)
|
||||
self.assertEqual(self._tokens(header, "frame-src"), ["'self'", "*." + PRIMARY])
|
||||
self.assertIn("https://cdn." + PRIMARY, self._tokens(header, "connect-src"))
|
||||
self.assertNotIn(".onion", header)
|
||||
|
||||
def test_onion_sibling_of_a_tls_token_is_plaintext(self):
|
||||
domains = {
|
||||
"web-svc-cdn": ["cdn." + PRIMARY],
|
||||
"app1": ["app1." + PRIMARY, "app1." + NODE],
|
||||
}
|
||||
header = self.filter.build_csp_header(
|
||||
copy.deepcopy(self.apps), "app1", domains, "https", domain_primary=PRIMARY
|
||||
)
|
||||
def test_onion_vhost_moves_sources_to_the_node_in_plaintext(self):
|
||||
header = self._header("app1." + NODE)
|
||||
self.assertEqual(self._tokens(header, "frame-src"), ["'self'", "*." + NODE])
|
||||
connect = self._tokens(header, "connect-src")
|
||||
self.assertIn("https://cdn." + PRIMARY, connect)
|
||||
self.assertIn("http://cdn." + NODE, connect)
|
||||
self.assertNotIn("https://cdn." + NODE, connect)
|
||||
self.assertNotIn("https://cdn." + PRIMARY, connect)
|
||||
|
||||
def test_exclusive_replaces_clearnet_with_onion(self):
|
||||
frame = self._tokens(self._header({"app1": ["app1." + NODE]}), "frame-src")
|
||||
def test_tor_only_app_without_vhost_follows_its_primary(self):
|
||||
domains = {"web-svc-cdn": ["cdn." + NODE], "app1": ["app1." + NODE]}
|
||||
frame = self._tokens(self._header(None, domains=domains), "frame-src")
|
||||
self.assertIn("*." + NODE, frame)
|
||||
self.assertNotIn("*." + PRIMARY, frame)
|
||||
|
||||
def test_non_tor_app_unchanged(self):
|
||||
frame = self._tokens(self._header({"app1": ["app1." + PRIMARY]}), "frame-src")
|
||||
self.assertIn("*." + PRIMARY, frame)
|
||||
self.assertFalse(any(".onion" in t for t in frame))
|
||||
|
||||
def test_no_mirror_without_node(self):
|
||||
def test_no_translation_without_node(self):
|
||||
apps = copy.deepcopy(self.apps)
|
||||
del apps["svc-net-tor"]
|
||||
domains = {"web-svc-cdn": ["cdn." + PRIMARY], "app1": ["app1." + NODE]}
|
||||
header = self.filter.build_csp_header(
|
||||
apps, "app1", domains, "http", domain_primary=PRIMARY
|
||||
)
|
||||
self.assertFalse(any(".onion" in t for t in self._tokens(header, "frame-src")))
|
||||
frame = self._tokens(self._header("app1." + NODE, apps=apps), "frame-src")
|
||||
self.assertEqual(frame, ["'self'", "*." + PRIMARY])
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
||||
@@ -0,0 +1,52 @@
|
||||
import unittest
|
||||
|
||||
from plugins.filter.network_of import FilterModule
|
||||
|
||||
ONION = "abc123def456ghij789klmno000pqrstuvwx111yz222abc333def444gh.onion"
|
||||
|
||||
|
||||
class TestNetworkFilters(unittest.TestCase):
|
||||
def setUp(self):
|
||||
self.filters = FilterModule().filters()
|
||||
|
||||
def test_network_of_is_the_registry_lookup(self):
|
||||
self.assertEqual(self.filters["network_of"]("x.abc.onion"), "tor")
|
||||
self.assertEqual(self.filters["network_of"]("x.infinito.test"), "clearnet")
|
||||
|
||||
def test_network_sibling_translates_the_primary(self):
|
||||
self.assertEqual(
|
||||
self.filters["network_sibling"](
|
||||
"infinito.test", "tor", "infinito.test", ONION
|
||||
),
|
||||
ONION,
|
||||
)
|
||||
|
||||
def test_network_suffix_comes_from_the_registry(self):
|
||||
self.assertEqual(self.filters["network_suffix"]("tor"), ".onion")
|
||||
self.assertEqual(self.filters["network_suffix"]("clearnet"), "")
|
||||
|
||||
def test_network_suffixes_maps_only_networks_with_a_suffix(self):
|
||||
self.assertEqual(
|
||||
self.filters["network_suffixes"](["clearnet", "tor"]), {"tor": ".onion"}
|
||||
)
|
||||
self.assertEqual(self.filters["network_suffixes"](["clearnet"]), {})
|
||||
|
||||
def test_in_network_keeps_the_domains_of_one_network(self):
|
||||
domains = ["a.infinito.test", f"a.{ONION}", "b.infinito.test"]
|
||||
self.assertEqual(
|
||||
self.filters["in_network"](domains, "clearnet"),
|
||||
["a.infinito.test", "b.infinito.test"],
|
||||
)
|
||||
self.assertEqual(self.filters["in_network"](domains, "tor"), [f"a.{ONION}"])
|
||||
|
||||
def test_network_sibling_is_empty_without_a_node(self):
|
||||
self.assertEqual(
|
||||
self.filters["network_sibling"](
|
||||
"infinito.test", "tor", "infinito.test", ""
|
||||
),
|
||||
"",
|
||||
)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
@@ -1,45 +0,0 @@
|
||||
import unittest
|
||||
|
||||
from plugins.filter.url.to_onion import to_onion_url
|
||||
|
||||
NODE = "abc123def456ghij789klmno000pqrstuvwx111yz222abc333def444gh.onion"
|
||||
PRIMARY = "infinito.test"
|
||||
|
||||
|
||||
class TestToOnionUrl(unittest.TestCase):
|
||||
def test_subdomain_swapped_and_forced_http(self):
|
||||
self.assertEqual(
|
||||
to_onion_url("https://auth.infinito.test/realms/x", NODE, PRIMARY),
|
||||
f"http://auth.{NODE}/realms/x",
|
||||
)
|
||||
|
||||
def test_bare_primary_becomes_node(self):
|
||||
self.assertEqual(
|
||||
to_onion_url("https://infinito.test/", NODE, PRIMARY),
|
||||
f"http://{NODE}/",
|
||||
)
|
||||
|
||||
def test_path_and_query_preserved(self):
|
||||
self.assertEqual(
|
||||
to_onion_url("https://cdn.infinito.test/a/b.js?v=3", NODE, PRIMARY),
|
||||
f"http://cdn.{NODE}/a/b.js?v=3",
|
||||
)
|
||||
|
||||
def test_host_not_under_primary_unchanged(self):
|
||||
url = "https://example.org/foo"
|
||||
self.assertEqual(to_onion_url(url, NODE, PRIMARY), url)
|
||||
|
||||
def test_noop_without_tor_node(self):
|
||||
url = "https://auth.infinito.test/"
|
||||
self.assertEqual(to_onion_url(url, "", PRIMARY), url)
|
||||
|
||||
def test_noop_on_empty_url(self):
|
||||
self.assertEqual(to_onion_url("", NODE, PRIMARY), "")
|
||||
|
||||
def test_already_onion_host_unchanged(self):
|
||||
url = f"http://auth.{NODE}/"
|
||||
self.assertEqual(to_onion_url(url, NODE, PRIMARY), url)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
@@ -84,6 +84,13 @@ class TestCertPlanLookup(unittest.TestCase):
|
||||
)
|
||||
self.assertEqual(out["domains"]["san"], ["a.example"])
|
||||
|
||||
def test_sans_leave_out_networks_without_tls(self):
|
||||
v = dict(self.vars)
|
||||
v["domains"] = dict(self.domains)
|
||||
v["domains"]["web-app-a"] = ["a.example", "a.abc.onion"]
|
||||
out = self.lookup.run(["web-app-a"], variables=v, mode="app")[0]
|
||||
self.assertEqual(out["domains"]["san"], ["a.example"])
|
||||
|
||||
def test_letsencrypt_plan_uses_cert_name_override(self):
|
||||
v = dict(self.vars)
|
||||
v["applications"] = dict(self.applications)
|
||||
|
||||
@@ -0,0 +1,68 @@
|
||||
"""Contract of ``lookup('network_siblings')``: every logical domain renders
|
||||
once per network its app is served on, and exactly once overall."""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import unittest
|
||||
|
||||
from plugins.lookup.network_siblings import served_siblings
|
||||
|
||||
ONION = "abc123def456ghij789klmno000pqrstuvwx111yz222abc333def444gh.onion"
|
||||
PRIMARY = "infinito.test"
|
||||
|
||||
|
||||
class TestServedSiblings(unittest.TestCase):
|
||||
def test_multi_app_renders_both_networks_from_the_canonical_domain(self) -> None:
|
||||
domains = {"web-app-x": ["x.infinito.test", f"x.{ONION}"]}
|
||||
self.assertEqual(
|
||||
served_siblings("x.infinito.test", domains, PRIMARY, ONION),
|
||||
["x.infinito.test", f"x.{ONION}"],
|
||||
)
|
||||
|
||||
def test_multi_app_skips_the_non_canonical_sibling(self) -> None:
|
||||
domains = {"web-app-x": ["x.infinito.test", f"x.{ONION}"]}
|
||||
self.assertEqual(served_siblings(f"x.{ONION}", domains, PRIMARY, ONION), [])
|
||||
|
||||
def test_tor_only_app_maps_a_raw_clearnet_domain_to_its_onion(self) -> None:
|
||||
domains = {"web-app-x": [f"x.{ONION}"]}
|
||||
self.assertEqual(
|
||||
served_siblings("x.infinito.test", domains, PRIMARY, ONION), [f"x.{ONION}"]
|
||||
)
|
||||
|
||||
def test_clearnet_only_app_renders_one_vhost(self) -> None:
|
||||
domains = {"web-app-x": ["x.infinito.test"]}
|
||||
self.assertEqual(
|
||||
served_siblings("x.infinito.test", domains, PRIMARY, ONION),
|
||||
["x.infinito.test"],
|
||||
)
|
||||
|
||||
def test_named_canonicals_fan_out_per_key(self) -> None:
|
||||
domains = {
|
||||
"web-app-x": {
|
||||
"api": "api.infinito.test",
|
||||
"web": "web.infinito.test",
|
||||
"api_onion": f"api.{ONION}",
|
||||
"web_onion": f"web.{ONION}",
|
||||
}
|
||||
}
|
||||
self.assertEqual(
|
||||
served_siblings("web.infinito.test", domains, PRIMARY, ONION),
|
||||
["web.infinito.test", f"web.{ONION}"],
|
||||
)
|
||||
|
||||
def test_unknown_domain_renders_as_given(self) -> None:
|
||||
self.assertEqual(
|
||||
served_siblings("elsewhere.example", {}, PRIMARY, ONION),
|
||||
["elsewhere.example"],
|
||||
)
|
||||
|
||||
def test_node_without_tor_renders_as_given(self) -> None:
|
||||
domains = {"web-app-x": ["x.infinito.test"]}
|
||||
self.assertEqual(
|
||||
served_siblings("x.infinito.test", domains, PRIMARY, ""),
|
||||
["x.infinito.test"],
|
||||
)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
Reference in new issue
Block a user