Serve MCP and hooks with a secret through the portal tunnel

The connector now serves /mcp, its OAuth documents and /hooks/ besides
/api/v1/, refuses any dot segment (httpx resolves them, which carried
/api/v1/../../mcp onto the MCP mount), addresses calls to the hub's host,
and bridges served sockets by calling the app with a websocket scope.
A hook without a secret answers the tunnel with the 404 (or 1008) of a
wrong secret. Requests through the hub get the hub's issuer, resource and
consent page in the OAuth metadata and the 401, and the MCP host check
admits the hub while enrolled.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01WgBfkm4rCmtd1T4vHWjEPx
This commit is contained in:
2026-10-15 11:00:19 +02:00
co-authored by Claude Opus 5.5
parent 7a56818213
commit 391edc8766
14 changed files with 526 additions and 31 deletions
+12 -5
View File
@@ -400,11 +400,18 @@ class HttpNode(Node):
:returns: JSON response with trigger result.
:rtype: JSONResponse
"""
if self.secret and not hmac.compare_digest(
str(request.path_params.get("secret", "")).encode(),
self.secret.encode(),
):
# A wrong secret must look like no such hook at all.
from fluksio.cloud.config import via_portal
if (
self.secret
and not hmac.compare_digest(
str(request.path_params.get("secret", "")).encode(),
self.secret.encode(),
)
) or (not self.secret and via_portal(request.headers)):
# A wrong secret must look like no such hook at all, and so must
# a hook without one reached through the portal, which would
# otherwise be open to the whole internet.
return JSONResponse(content={"detail": "Not Found"}, status_code=404)
try:
+10 -4
View File
@@ -342,11 +342,17 @@ class WebSocketNode(Node):
async def _serve(self, websocket: WebSocket) -> None:
"""One client of a served socket, for as long as it stays."""
if self.secret and not hmac.compare_digest(
str(websocket.path_params.get("secret", "")).encode(),
self.secret.encode(),
):
from fluksio.cloud.config import via_portal
if (
self.secret
and not hmac.compare_digest(
str(websocket.path_params.get("secret", "")).encode(),
self.secret.encode(),
)
) or (not self.secret and via_portal(websocket.headers)):
# Closed before accepting: the same 403 as a path with no route.
# Through the portal a socket needs a secret, as a webhook does.
await websocket.close(code=1008)
return
await websocket.accept()