Enrol over http only to loopback; serve the API docs to this machine
The enrolment exemption covered any *.local host, which mDNS answers with whoever claims it; it is now localhost, 127.0.0.0/8 and ::1. /docs, /redoc and openapi.json stay closed in production and otherwise answer only a loopback caller unless API_DOCS_ENABLED is set, which the dev compose does, so `fluksio serve --host 0.0.0.0` no longer hands the schema to the network. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_013GAeg4Jo6xjZzjwy9QDWMQ
This commit is contained in:
@@ -9,6 +9,7 @@ before the engine has started, holding nothing but the database.
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import ipaddress
|
||||
import logging
|
||||
import secrets
|
||||
from datetime import UTC, datetime
|
||||
@@ -37,10 +38,19 @@ class EnrollError(Exception):
|
||||
self.detail = detail
|
||||
|
||||
|
||||
def _is_local(url: str) -> bool:
|
||||
"""Whether the address is this machine or a compose-internal service."""
|
||||
def _is_loopback(url: str) -> bool:
|
||||
"""Whether the address is this machine.
|
||||
|
||||
Not a `*.local` name: mDNS answers it with whoever claims it on the LAN,
|
||||
which would then receive the claim code and the credential in clear.
|
||||
"""
|
||||
host = urlsplit(url).hostname or ""
|
||||
return host in {"localhost", "127.0.0.1", "::1"} or host.endswith(".local")
|
||||
if host == "localhost":
|
||||
return True
|
||||
try:
|
||||
return ipaddress.ip_address(host).is_loopback
|
||||
except ValueError:
|
||||
return False
|
||||
|
||||
|
||||
def redeem_claim(
|
||||
@@ -52,10 +62,8 @@ def redeem_claim(
|
||||
# this address. Over plain http both are readable by anything on the path,
|
||||
# so refuse rather than enrol insecurely — bar a loopback portal, which is
|
||||
# how the stack is developed against itself.
|
||||
if not base.startswith("https://") and not _is_local(base):
|
||||
raise EnrollError(
|
||||
422, "The portal address must be https:// (or a local address)"
|
||||
)
|
||||
if not base.startswith("https://") and not _is_loopback(base):
|
||||
raise EnrollError(422, "The portal address must be https:// (or this machine)")
|
||||
try:
|
||||
response = httpx.post(
|
||||
f"{base}/api/v1/enroll/",
|
||||
|
||||
Reference in New Issue
Block a user