feat(network): point logout and peer allowlists at every network a vhost serves

CI run 40979252521 Nextcloud#0: on the onion pass the biber OIDC logout cleared only the clearnet session, because Keycloak holds one front-channel URL per client and the injected logout sent no post-logout target for the onion network; and Collabora's aliasgroup1 listed only the clearnet WOPI host.

On a vhost outside the application's canonical network (and without an external issuer) the injected logout one-liner now adds client_id and post_logout_redirect_uri set to that network's logout conductor, and Keycloak registers every conductor sibling as post-logout redirect URI next to '+'. Collabora's aliasgroup1 lists the Nextcloud WOPI host of every network (one instance, union allowlist). network_modes.md gains a Network-Aligned Values table, and test_network_allowlist_sinks.py fails when a template names an allowlist sink without the sibling union.

Rendering is covered by 14 tests; the full gate and the runtime acceptance of the '##' post-logout list by Keycloak and the comma aliasgroup by Collabora still need a gate on store-i18n and an onion deploy.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
kevinveenbirkenbachandClaude Opus 5.5 committed 2026-10-30 18:00:24 +01:00
1 parent 11308259b3
commit 41ea801fd9
9 files changed
+276 -7

No files matched your search

Whitespace-only changes.
@@ -0,0 +1,75 @@
from __future__ import annotations
import unittest
from urllib.parse import parse_qs, urlsplit
from jinja2 import Environment, StrictUndefined, select_autoescape
from plugins.filter.network_of import network_of
from utils.cache.files import PROJECT_ROOT, read_text
TEMPLATE = PROJECT_ROOT / "roles/sys-front-inj-logout/templates/logout_one_liner.js.j2"
ONION = "a" * 56 + ".onion"
LOGOUT_URL = "https://auth.example/realms/example/protocol/openid-connect/logout"
CONDUCTORS = {"clearnet": "https://logout.example/", "tor": f"http://logout.{ONION}/"}
def logout_target(domain: str, canonical: str, **extra) -> str:
def lookup(name, *terms):
if name == "domain":
return canonical
if name == "tls" and terms == ("web-svc-logout", "url.base"):
return CONDUCTORS[network_of(domain)]
raise AssertionError(f"unexpected lookup: {name!r} {terms!r}")
env = Environment(
undefined=StrictUndefined,
autoescape=select_autoescape(default_for_string=False),
)
env.filters["network_of"] = network_of
rendered = env.from_string(read_text(str(TEMPLATE))).render(
lookup=lookup,
domain=domain,
application_id="web-app-nextcloud",
MODE_DEBUG=False,
OIDC={"CLIENT": {"LOGOUT_URL": LOGOUT_URL, "ID": "example"}},
**extra,
)
return rendered.split("initLogoutPatch(")[1].split("'")[1]
class TestLogoutOneLiner(unittest.TestCase):
def test_the_canonical_vhost_keeps_the_bare_issuer_logout(self):
self.assertEqual(
logout_target("next.cloud.example", "next.cloud.example"), LOGOUT_URL
)
def test_the_onion_vhost_returns_to_the_onion_conductor(self):
target = urlsplit(logout_target(f"next.cloud.{ONION}", "next.cloud.example"))
self.assertEqual(f"{target.scheme}://{target.netloc}{target.path}", LOGOUT_URL)
self.assertEqual(
parse_qs(target.query),
{
"client_id": ["example"],
"post_logout_redirect_uri": [CONDUCTORS["tor"]],
},
)
def test_an_onion_only_node_keeps_the_bare_issuer_logout(self):
self.assertEqual(
logout_target(f"next.cloud.{ONION}", f"next.cloud.{ONION}"), LOGOUT_URL
)
def test_an_external_issuer_keeps_the_bare_logout(self):
self.assertEqual(
logout_target(
f"next.cloud.{ONION}",
"next.cloud.example",
OIDC_OVERRIDE={"URL": "https://idp.example"},
),
LOGOUT_URL,
)
if __name__ == "__main__":
unittest.main()
@@ -20,7 +20,18 @@ NEXTCLOUD_ONION = "next.cloud." + "a" * 56 + ".onion"
COLLABORA_ONION = "collabora." + "a" * 56 + ".onion"
def wopi_host(domains: dict[str, list[str]]) -> str:
SINGLE_HOST_EXPRESSION = (
"{{ lookup('tls', lookup('domain', 'web-app-nextcloud'), 'protocols.web') }}://"
"{{ lookup('domain', 'web-app-nextcloud') }}:"
"{{ lookup('tls', lookup('domain', 'web-app-nextcloud'), 'ports.web') }}"
)
def wopi_host(
domains: dict[str, list[str]],
siblings: dict[str, list[str]] | None = None,
expression: str | None = None,
) -> str:
variables = {
"domains": domains,
"applications": {},
@@ -41,9 +52,12 @@ def wopi_host(domains: dict[str, list[str]]) -> str:
return domains[terms[0]][0]
if name == "tls":
return tls.run(list(terms), variables=variables)[0]
if name == "network_siblings":
return (siblings or {}).get(terms[0], [terms[0]])
raise AssertionError(f"the expression calls an unexpected lookup: {name!r}")
expression = load_yaml_str(read_text(str(VARS)))["COLLABORA_WOPI_HOST"]
if expression is None:
expression = load_yaml_str(read_text(str(VARS)))["COLLABORA_WOPI_HOSTS"]
env = Environment(
undefined=StrictUndefined,
autoescape=select_autoescape(default_for_string=False),
@@ -87,6 +101,18 @@ class TestWopiHost(unittest.TestCase):
"https://next.cloud.example:443",
)
def test_every_network_sibling_of_nextcloud_is_an_alias(self):
domains = {
"web-app-nextcloud": ["next.cloud.example", NEXTCLOUD_ONION],
"web-svc-collabora": ["collabora.example", COLLABORA_ONION],
}
siblings = {"next.cloud.example": ["next.cloud.example", NEXTCLOUD_ONION]}
expected = f"https://next.cloud.example:443,http://{NEXTCLOUD_ONION}:80"
self.assertEqual(wopi_host(domains, siblings), expected)
self.assertNotEqual(
wopi_host(domains, siblings, SINGLE_HOST_EXPRESSION), expected
)
if __name__ == "__main__":
unittest.main()