From e611e5ea05441acf6935cd172f4341e94df34518 Mon Sep 17 00:00:00 2001 From: Kevin Veen-Birkenbach Date: Sat, 24 Oct 2026 15:26:22 +0200 Subject: [PATCH] fix(objstore): name the consumer when resolving its onion origin sys-svc-objstore includes the provider role with application_id set to "{{ _provider_role }}", which is itself lookup('objstore', ...). For a consumer served only on onion the objstore lookup sets proxy_required and calls lookup('tls', consumer_id); without a consumer, align_domain_to_consumer renders variables['application_id'], which runs the objstore lookup again, and the chain repeats until Ansible stops with "Recursive loop detected" / "Maximum depth exceeded" (fork run 40042690056, jobs Moodle#2 and Nextcloud#12, log line 286323). Only web-app-matrix sets single_mode, so only its multi-mode onion deploys hit it. The tls lookup takes a consumer= kwarg and hands it to align_domain_to_consumer, the way canonical_url already does, and the objstore lookup names its consumer. The default stays empty, so no other caller changes. Regression tests cover both lookups; an onion consumer now resolves to http://matrix./objstore/matrix. Co-Authored-By: Claude Opus 5.5 --- plugins/lookup/objstore.py | 6 +++--- plugins/lookup/tls.py | 2 ++ .../python/plugins/lookup/test_objstore.py | 19 ++++++++++++++++++- tests/unit/python/plugins/lookup/test_tls.py | 19 +++++++++++++++++++ 4 files changed, 42 insertions(+), 4 deletions(-) diff --git a/plugins/lookup/objstore.py b/plugins/lookup/objstore.py index b7801e7705..7e48f930a3 100644 --- a/plugins/lookup/objstore.py +++ b/plugins/lookup/objstore.py @@ -246,10 +246,10 @@ class LookupModule(LookupBase): else "http" ) - def _lookup(name: str, args: list[Any]) -> Any: + def _lookup(name: str, args: list[Any], **kwargs: Any) -> Any: return lookup_loader.get( name, loader=self._loader, templar=getattr(self, "_templar", None) - ).run(args, variables=vars_)[0] + ).run(args, variables=vars_, **kwargs)[0] def _consumer_is_onion_only() -> bool: domains_map = _lookup("domains", []) @@ -268,7 +268,7 @@ class LookupModule(LookupBase): browser_domain = public_domain browser_scheme = scheme if proxy_required: - consumer_tls = _lookup("tls", [consumer_id]) + consumer_tls = _lookup("tls", [consumer_id], consumer=consumer_id) browser_domain = f"{consumer_tls['domain']}{OBJSTORE_PROXY_PREFIX}" browser_scheme = consumer_tls["protocols"]["web"] diff --git a/plugins/lookup/tls.py b/plugins/lookup/tls.py index 24d8f2a6bd..c585917372 100644 --- a/plugins/lookup/tls.py +++ b/plugins/lookup/tls.py @@ -58,6 +58,7 @@ class LookupModule(LookupBase): ) forced_mode = as_str(kwargs.get("mode", "auto")).lower() + consumer = as_str(kwargs.get("consumer", "")) app_id, primary_domain = resolve_term( term, @@ -74,6 +75,7 @@ class LookupModule(LookupBase): domains, app_id, primary_domain, + consumer=consumer, variables=variables, templar=templar, ) diff --git a/tests/unit/python/plugins/lookup/test_objstore.py b/tests/unit/python/plugins/lookup/test_objstore.py index cb4733c5be..0d957ac445 100644 --- a/tests/unit/python/plugins/lookup/test_objstore.py +++ b/tests/unit/python/plugins/lookup/test_objstore.py @@ -334,8 +334,14 @@ class ObjstoreSameOriginProxyTests(unittest.TestCase): }, } + self.run_kwargs = {} + def fake_get(name, **_kwargs): - return mock.MagicMock(run=lambda *_a, **_k: [payloads[name]]) + def run(_terms, **kwargs): + self.run_kwargs[name] = kwargs + return [payloads[name]] + + return mock.MagicMock(run=run) with ( mock.patch.object(self.mod, "lookup_loader") as loader_mock, @@ -372,6 +378,17 @@ class ObjstoreSameOriginProxyTests(unittest.TestCase): "the rebase must not overwrite the upstream it proxies to", ) + def test_the_consumer_origin_is_resolved_for_the_named_consumer(self): + self._resolve(consumer_domains=["foo.abcdefghij.onion"]) + + self.assertEqual( + self.run_kwargs["tls"].get("consumer"), + "web-app-foo", + "sys-svc-objstore binds application_id to a template over this very " + "lookup, so tls falling back to application_id recurses until Jinja " + "gives up", + ) + def test_a_clearnet_consumer_keeps_the_provider_host(self): out = self._resolve(consumer_domains=["foo.example.com"], consumer_web="https") diff --git a/tests/unit/python/plugins/lookup/test_tls.py b/tests/unit/python/plugins/lookup/test_tls.py index af91c312e7..d12abb2b72 100644 --- a/tests/unit/python/plugins/lookup/test_tls.py +++ b/tests/unit/python/plugins/lookup/test_tls.py @@ -176,6 +176,25 @@ class TestTlsResolveLookup(unittest.TestCase): self.assertEqual(out["domain"], "cdn.abc.onion") self.assertFalse(out["enabled"]) + def test_explicit_consumer_outranks_application_id(self): + class _Templar: + def template(self, value): + if value == "{{ _provider_role }}": + raise AssertionError("application_id must not be rendered") + return value + + self.lookup._templar = _Templar() + v = dict(self.base_vars) + v["domains"] = { + **self.domains, + "web-svc-cdn": ["cdn.abc.onion", "cdn.example"], + } + v["application_id"] = "{{ _provider_role }}" + out = self.lookup.run( + ["web-svc-cdn"], variables=v, mode="app", consumer="web-app-a" + )[0] + self.assertEqual(out["domain"], "cdn.example") + def test_term_with_unresolved_jinja_is_templated(self): class _FakeTemplar: def __init__(self, mapping):