Take the portal's JWKS from the tunnel and verify by kid
The welcome frame's keys replace the set pinned at enrolment, but only over wss:// or loopback, the rule enrolment applies to the portal address. Portal tokens are verified against the key their kid names, so the hub can publish a new key beside the old one. A welcome without keys, from an older hub, leaves the pinned set alone. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01WgBfkm4rCmtd1T4vHWjEPx
This commit is contained in:
@@ -27,10 +27,12 @@ from datetime import timedelta
|
||||
from typing import Any
|
||||
|
||||
import httpx
|
||||
import jwt
|
||||
from fastapi import FastAPI
|
||||
|
||||
import fluksio
|
||||
from fluksio.cloud import config as cloud_config
|
||||
from fluksio.cloud.enroll import is_loopback
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
@@ -239,6 +241,7 @@ class CloudConnector:
|
||||
|
||||
self._owner = welcome.get("owner")
|
||||
self._adopt_owner(config, self._owner)
|
||||
self._adopt_jwks(welcome.get("jwks"))
|
||||
|
||||
attached = True
|
||||
self._connected = True
|
||||
@@ -319,6 +322,27 @@ class CloudConnector:
|
||||
# link: everything else this connection does still works.
|
||||
logger.exception("Could not map the enrolling account to the portal owner")
|
||||
|
||||
@staticmethod
|
||||
def _adopt_jwks(jwks: Any) -> None:
|
||||
"""Replace the pinned signing keys with the set the hub sends on attach.
|
||||
|
||||
Taken only from a link that is encrypted or on this machine, the rule
|
||||
enrolment applies to the portal address. Over cleartext anything on the
|
||||
path could hand this instance a key of its own.
|
||||
"""
|
||||
config = cloud_config.load()
|
||||
if config is None or not isinstance(jwks, dict) or jwks == config.jwks:
|
||||
return
|
||||
if not config.ws_url.startswith("wss://") and not is_loopback(config.ws_url):
|
||||
return
|
||||
try:
|
||||
jwt.PyJWKSet.from_dict(jwks)
|
||||
except jwt.PyJWTError as exc:
|
||||
logger.warning("Ignoring unusable portal keys: %s", exc)
|
||||
return
|
||||
cloud_config.save(replace(config, jwks=jwks))
|
||||
logger.info("Took the portal's current signing keys")
|
||||
|
||||
@staticmethod
|
||||
def _forget_member(portal_sub: str, owner: str | None) -> None:
|
||||
"""Delete the local user of somebody the portal no longer admits.
|
||||
|
||||
Reference in New Issue
Block a user