fix(keycloak): register redirect URIs only for the apps a play deploys

lookup('redirect_uris') walked every app in the domains map whose services.sso.enabled resolves truthy, which every role spells as "'web-app-keycloak' in group_names". A round deploying 21 apps therefore registered 69 redirect URIs and web origins on the shared client, 65 of them onion, and an app that is not running has no reason to be a redirect target. group_names is now required and scopes the result, matching KEYCLOAK_SAML_APPS which already selects on it.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This commit is contained in:
kevinveenbirkenbachandClaude Opus 5 committed 2026-09-03 09:18:07 +02:00
1 parent eda2dd08c0
commit b4af1d4b89
2 files changed
+52 -4

No files matched your search

@@ -1,6 +1,7 @@
from __future__ import annotations
import unittest
from unittest import mock
from ansible.errors import AnsibleError
@@ -83,6 +84,18 @@ class TestBuildRedirectUris(unittest.TestCase):
],
)
def test_only_deployed_consumers_are_registered(self):
domains = {"deployed": "a.example.org", "parked": "b.example.org"}
result = build_redirect_uris(
domains, {"deployed": SSO, "parked": SSO}, True, deployed=["deployed"]
)
self.assertEqual(result, ["https://a.example.org/*"])
def test_no_deployment_scope_registers_every_consumer(self):
domains = {"one": "a.example.org", "two": "b.example.org"}
result = build_redirect_uris(domains, {"one": SSO, "two": SSO}, True)
self.assertEqual(result, ["https://a.example.org/*", "https://b.example.org/*"])
def test_invalid_domains_type_raises(self):
with self.assertRaises(AnsibleError):
build_redirect_uris(["not-a-dict"], {}, True) # type: ignore[arg-type]
@@ -105,6 +118,31 @@ class TestRedirectUrisLookup(unittest.TestCase):
with self.assertRaises(AnsibleError):
self.lookup.run([], variables={})
def test_missing_group_names_raises(self):
with self.assertRaises(AnsibleError):
self.lookup.run([], variables={"TLS_ENABLED": True})
def test_group_names_scope_the_registered_consumers(self):
class _Stub:
def __init__(self, payload):
self.payload = payload
def run(self, terms, variables=None, **kwargs):
return [self.payload]
payloads = {
"domains": _Stub({"deployed": "a.example.org", "parked": "b.example.org"}),
"applications": _Stub({"deployed": SSO, "parked": SSO}),
}
with mock.patch(
"plugins.lookup.redirect_uris.lookup_loader.get",
side_effect=lambda name, **kwargs: payloads[name],
):
result = self.lookup.run(
[], variables={"TLS_ENABLED": True, "group_names": ["deployed"]}
)
self.assertEqual(result, [["https://a.example.org/*"]])
if __name__ == "__main__":
unittest.main()