Files
skills/orchestrator/kvb_orchestrator/keys.py
T
Kevin Veen-BirkenbachandClaude Opus 5.5 6d2bca77f7 feat(orchestrator): S8 shared speech service and sealed model transport
Requirement 001 S8: the hub can use a shared OpenAI-style speech service (KVB_ORCHESTRATOR_SPEECH_URL, key from a mounted file) instead of the local piper and whisper engines, and the image takes its pinned artefacts through an optional INFINITO_ARTEFACT_BASE cache. A new transport serves speech and the LLM: one wall-clock deadline over DNS, connect, TLS handshake and body, certificate and hostname always verified, no redirect followed. A key travels only over https or to loopback; both the speech and the LLM start refuse it otherwise. Key files are capped at 4096 bytes. Streamed WAV answers with placeholder sizes are accepted only when the data chunk runs to the end, and are rewritten before caching. Accepted MEDUSA false positives (41, independent review, operator pick): raw client socket patterns in transport.py, AIC-EXFIL-005 on the sealed key path, JB-SCAN-2237 on the hub's own system prompt, STG009 on the RIFF pad byte and LLM01 at language.py:111, where agent-written titles reach the NL prompt but the model only proposes a plan the operator confirms.

🎯 Fix: 93 %
💥 Break: 4 %
💸 Cost: –
⏱️ Time: –
🛡️ Security: 100 %
🏆 Score: 89
🚦 Gate: ✅ 90/5, cost and time <= 100, security 100 %

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-13 16:57:52 +00:00

55 lines
1.7 KiB
Python

from __future__ import annotations
from pathlib import Path
from urllib.parse import urlsplit
from .errors import ToolError
KEY_LIMIT = 4096
LOOPBACK = frozenset({"127.0.0.1", "localhost", "::1"})
def bearer(key: str) -> bool:
"""Returns:
Whether key is printable ASCII without whitespace, the only shape an
Authorization header carries.
"""
return key.isascii() and key.isprintable() and not any(character.isspace() for character in key)
def sealed(url: str) -> bool:
"""Returns:
Whether a bearer key sent to url stays off the open network: an https
URL or one whose host is 127.0.0.1, localhost or ::1; False for a URL
that does not parse.
"""
try:
parts = urlsplit(url)
return parts.scheme == "https" or parts.hostname in LOOPBACK
except ValueError:
return False
def key_from(path: Path, owner: str) -> str:
"""Args:
path: a bearer key file; an empty file such as /dev/null means no key.
owner: what the key is for, such as "speech service", named in the
message.
Returns:
The key without the whitespace around it.
Raises:
ToolError naming the path, never its content, when the file cannot be
read as UTF-8 text or holds more than KEY_LIMIT bytes; at most
KEY_LIMIT + 1 bytes are read, so /dev/zero fails at once.
"""
try:
with path.open("rb") as handle:
data = handle.read(KEY_LIMIT + 1)
if len(data) > KEY_LIMIT:
raise ToolError(f"the {owner} key file {path} holds more than {KEY_LIMIT} bytes")
return data.decode("utf-8").strip()
except (OSError, ValueError):
raise ToolError(f"the {owner} key file {path} is unreadable") from None