mirror of
https://github.com/kevinveenbirkenbach/computer-playbook.git
synced 2026-11-29 14:30:52 +00:00
fix(proxy): withdraw an ACL-gated MCP path instead of leaving it to the ACL
mcp/vhost.conf.j2 wrapped its whole body in `{% if not mcp_acl_gated %}`.
That skipped the serve block, which was the intent, but it also skipped the
withdrawal loop underneath it. An ACL-gated vhost therefore rendered no
`location` for its MCP paths at all, so requests fell through to the
application's generic location and the endpoint was reachable behind
nothing but the SSO proxy ACL.
Folding the gate into the `mcp_served` expression keeps the serve block
gated while letting the withdrawal loop run in every case. With an empty
`mcp_served` both declared paths differ from it, so both are withdrawn with
`return 404`.
The behaviour is latent today: only moodle and wordpress declare
`exposure: public`, and both carry `flavor: oidc`, so `is_proxy_gated` is
false and the branch is never taken. This closes the hole before a role
combines public exposure with an oauth2 proxy flavor.
test_mcp_vhost_exposure.py could not reach the branch: its lookup stub
returned "" for every non-config kind, so mcp_acl_gated was always falsy.
It now resolves is_proxy_gated and oauth2_acl, and gained the bool filter
that the internal-exposure cases never needed because `mcp.exposure ==
'public'` short-circuits before it. Rendering the pre-fix template under
gating yields zero withdrawals; the new one yields two.
This commit is contained in:
1 parent
3dff3fd606
commit
0f0d804a67
2 files changed
+40
-5
No files matched your search
@@ -43,12 +43,13 @@ def meta(role: str) -> dict:
|
||||
return load_yaml(PROJECT_ROOT / "roles" / role / ROLE_FILE_META_MCP)
|
||||
|
||||
|
||||
def render(role: str, *, exposure: str) -> str:
|
||||
def render(role: str, *, exposure: str, sso_gated: bool = False) -> str:
|
||||
"""Return `vhost.conf.j2` for one role at one exposure.
|
||||
|
||||
Args:
|
||||
role: the role directory name.
|
||||
exposure: the `mcp.exposure` value to render under.
|
||||
sso_gated: whether the vhost sits behind an SSO proxy ACL.
|
||||
"""
|
||||
block = meta(role)
|
||||
values = {
|
||||
@@ -64,6 +65,18 @@ def render(role: str, *, exposure: str) -> str:
|
||||
def config(_app, key, default=None):
|
||||
return values.get(key, default)
|
||||
|
||||
sso_values = {
|
||||
"is_proxy_gated": sso_gated,
|
||||
"oauth2_acl": ["group:staff"] if sso_gated else [],
|
||||
}
|
||||
|
||||
def lookup(kind, *args, **_kw):
|
||||
if kind == "config":
|
||||
return config(*args)
|
||||
if kind == "sso":
|
||||
return sso_values.get(args[1], "")
|
||||
return ""
|
||||
|
||||
env = Environment(
|
||||
loader=FileSystemLoader(str(TEMPLATE_DIR)),
|
||||
undefined=StrictUndefined,
|
||||
@@ -73,9 +86,14 @@ def render(role: str, *, exposure: str) -> str:
|
||||
pattern, repl, value
|
||||
)
|
||||
env.filters["regex_escape"] = re.escape
|
||||
env.filters["bool"] = lambda value: (
|
||||
value
|
||||
if isinstance(value, bool)
|
||||
else str(value).strip().lower() in {"true", "1", "yes", "on"}
|
||||
)
|
||||
return env.get_template("vhost.conf.j2").render(
|
||||
application_id=role,
|
||||
lookup=lambda kind, *args, **_kw: config(*args) if kind == "config" else "",
|
||||
lookup=lookup,
|
||||
)
|
||||
|
||||
|
||||
@@ -164,6 +182,25 @@ class TestInternalSurfaceIsWithdrawn(unittest.TestCase):
|
||||
"pass vacuously",
|
||||
)
|
||||
|
||||
def test_an_acl_gated_public_surface_is_withdrawn_not_left_to_the_acl(self):
|
||||
block = meta(FRONT_CONTROLLER_ROLE)
|
||||
rendered = render(FRONT_CONTROLLER_ROLE, exposure="public", sso_gated=True)
|
||||
self.assertNotIn(
|
||||
"proxy_pass",
|
||||
rendered,
|
||||
"an ACL-gated surface must not be served at the edge",
|
||||
)
|
||||
for declared in (
|
||||
block["endpoint"]["path"],
|
||||
block["adapter"]["upstream_path"],
|
||||
):
|
||||
with self.subTest(path=declared):
|
||||
self.assertTrue(
|
||||
is_blocked(rendered, declared),
|
||||
f"{declared} is left to the SSO ACL alone instead of being "
|
||||
f"withdrawn at the edge",
|
||||
)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
Reference in new issue
Block a user