feat: the realtime transport is always TLS #20

Merged
troed merged 9 commits from feat/fleet-tls-piece-3-computer into devel 2026-10-14 16:55:55 +02:00
Owner

feat: the realtime transport is always TLS

What this is

Piece 3 of the fleet-wide TLS-only change, in computer. The design
(docs/superpowers/specs/2026-10-14-fleet-tls-only-design.md) names one defect
shared by three repos: TLS material is optional, and its absence silently
degrades the realtime transport to plaintext ws://.
In computer that was
--ws_tls_cert/--ws_tls_key being optional, with a partial config also
falling back to plaintext.

The defect was not hypothetical. On 2026-10-14 the attached ESP32 joined its
network, obtained an IP, and died at the WebSocket upgrade because the server
served wss:// while the flashed build spoke plaintext ws://. A plaintext
HTTP upgrade into a TLS listener is closed with zero bytes, so it read as "the
wake word stopped working".

After this branch, no code path in computer can put the realtime protocol on
the wire unencrypted, and missing / partial / unusable material always fails
loudly — a startup error or a failed connection, never a downgrade.

This supersedes the transport default in docs/plans/2026-09-10-ota-computer.md
(that plan is history).

Change

Server — trust material is required. New src/computer/server_tls.py owns
trust resolution and the one startup log line that says which material is live
(cert=<path> subject=<subject> source=<explicit|dev>). build_pipeline
resolves once, for the serving modes only, before any heavy model load:

  • --ws_tls_cert / --ws_tls_key are required. Absent or partial is a
    startup ValueError naming both flags, and mentioning --dev-trust as the
    dev alternative. The plaintext and partial-config fallbacks are deleted from
    both build_uvicorn_config and WebSocketStreamer.
  • --dev-trust is the explicit dev convenience: it resolves the shared dev set
    ($STARFLEET_TRUST_DIR, else ../.dev-trust), requires server.pem and
    server.key on disk, and logs source=dev. It refuses to combine with
    explicit material.
  • Deliberate asymmetry: the server never auto-falls-back to dev trust. A
    device wrongly trusting a dev CA merely fails to connect; a server quietly
    coming up on plaintext or a dev CA is a security regression on a shared LAN.
  • --mode local / socket serve no socket and are deliberately unaffected.

Client — always wss, required bundle. _build_realtime_url loses its
use_tls parameter (always wss://); websocket_client raises, and
computer-client's main() errors, when neither --ca-bundle nor
STARFLEET_CA_BUNDLE is given. client.sh / client.sh.example gain
--ca-bundle in the same change, because they connect with none today and
break the moment the server requires TLS.

Scripts — same rule for every PC-side dialer.
synthetic_conversation_realtime_client.py (and its explicit --url plaintext
rejection), listen_and_play_realtime.py, test_audio_path.py (whose --local
self-test now mints its own throwaway certificate and serves/dials TLS),
test_live_speech.py, and test_server_local.py (a server launcher, so it
forwards --ws-tls-cert/--ws-tls-key/--dev-trust). tests/test_tls_invariant.py
is a static fence over the five scripts, which CI's pytest tests/ never imports.

Test double. tests/conformance/fake_realtime_server.py now takes a
required ssl_context and serves TLS from an in-test throwaway self-signed
certificate
(tests/tls_certs.py + a session fixture) — not the shared dev
set, which keeps the suite self-contained.

Docs. README, AGENTS.md, CONFORMANCE.md, server.sh.example, the
canonical src/computer/api/openai_realtime/README.md, and every realtime
example carry the required material.

Verification

Sandbox suite at the branch head: 968 passed, 1 deselected, ruff check /
ruff format --check / mypy src/ clean. The sandbox needs three mitigations
and /tmp does not survive a sandbox recreate:

cd $HOME/dev/starfleet/computer
# 1. the container has no PortAudio: stub sounddevice on PYTHONPATH
# 2. unset the proxy vars, or httpx demands the 'socksio' package
# 3. three NLTK-`punkt_tab`-dependent files are ignored (egress-blocked)
env -u ALL_PROXY -u HTTP_PROXY -u HTTPS_PROXY -u all_proxy -u http_proxy -u https_proxy \
  PYTHONPATH=/tmp/opencode/sdstub .venv/bin/python -m pytest tests/ -q -p no:cacheprovider \
    --ignore=tests/test_chat_completions_backend.py \
    --ignore=tests/test_responses_api_language_model.py \
    --ignore=tests/test_voice_prompt.py \
    --deselect tests/test_omnivoice_tts_handler.py::test_setup_flashinfer_import_failure_raises

CI (.forgejo/workflows/ci.yml, ubuntu-latest with libportaudio2 and the NLTK
data) is the authoritative full-suite run. Every plaintext-asserting test was
inverted rather than deleted, per the spec's "Testing and verification":
the partial-pair config test now requires both flags, the empty-pair case is
pinned, the ws:// URL assertions flipped to wss://, the fake server and the
reconnect test perform real TLS handshakes against the throwaway certificate,
and the local self-test in test_audio_path.py was run green.

Whole-branch review: no Critical findings; one Important documentation
regression (the canonical realtime README's examples could no longer start, and
the file was missing from the root README's pointer sentence) found and fixed,
plus two same-class Minor traps.

Known cross-repo impact (accepted, follow-up required)

communicator-esp32/host/tests/fake_server_fixture.py loads this repo's
tests/conformance/fake_realtime_server.py by file path and calls
FakeServer() over ws://. TLS is now a required constructor argument, so
esp32's host suite fails immediately with a missing-argument TypeError at
fixture setup — loud and self-explanatory, not a silent protocol drift. The
esp32 follow-up (pass an ssl_context, dial wss:// with the throwaway CA) is
not part of this branch.

Notes

Deferred Minors recorded during per-task review and triaged "ship" by the
whole-branch review — each has a one-line upgrade path: narrowing
server_tls.py's broad except Exception; an untested <empty> subject
branch; the __file__-derived default dev path (fragile under a non-editable
install); a tautological resolve_trust_dir default-path test (a plan defect);
RealtimeServer.__init__'s guard untested; assert server_tls is not None
(stripped under python -O); the untested socket-mode exemption; a
pre-existing hard-coded test CA blob in test_client_capture_mode.py; the
grep-shaped test_tls_invariant.py; test_audio_path.py's optional ca_bundle
default; a missing wss:// guard on listen_and_play_realtime.py's
--websocket-base-url; conformance dead code; the STT/README.md and
TTS/README.md snippet lists (pointer-covered); and one superseded sentence in
the dated docs/plans/2026-09-10-ota-computer.md.

On hardware, the unit currently pins the production CA (it still does); no
on-hardware run was part of piece 3.

# feat: the realtime transport is always TLS ## What this is Piece 3 of the fleet-wide TLS-only change, in `computer`. The design (`docs/superpowers/specs/2026-10-14-fleet-tls-only-design.md`) names one defect shared by three repos: **TLS material is optional, and its absence silently degrades the realtime transport to plaintext `ws://`.** In `computer` that was `--ws_tls_cert`/`--ws_tls_key` being optional, with a *partial* config also falling back to plaintext. The defect was not hypothetical. On 2026-10-14 the attached ESP32 joined its network, obtained an IP, and died at the WebSocket upgrade because the server served `wss://` while the flashed build spoke plaintext `ws://`. A plaintext HTTP upgrade into a TLS listener is closed with zero bytes, so it read as "the wake word stopped working". After this branch, no code path in `computer` can put the realtime protocol on the wire unencrypted, and missing / partial / unusable material always fails loudly — a startup error or a failed connection, never a downgrade. This supersedes the transport default in `docs/plans/2026-09-10-ota-computer.md` (that plan is history). ## Change **Server — trust material is required.** New `src/computer/server_tls.py` owns trust resolution and the one startup log line that says which material is live (`cert=<path> subject=<subject> source=<explicit|dev>`). `build_pipeline` resolves once, for the serving modes only, before any heavy model load: - `--ws_tls_cert` / `--ws_tls_key` are required. Absent **or partial** is a startup `ValueError` naming both flags, and mentioning `--dev-trust` as the dev alternative. The plaintext and partial-config fallbacks are deleted from both `build_uvicorn_config` and `WebSocketStreamer`. - `--dev-trust` is the explicit dev convenience: it resolves the shared dev set (`$STARFLEET_TRUST_DIR`, else `../.dev-trust`), requires `server.pem` and `server.key` on disk, and logs `source=dev`. It refuses to combine with explicit material. - **Deliberate asymmetry:** the server never auto-falls-back to dev trust. A device wrongly trusting a dev CA merely fails to connect; a *server* quietly coming up on plaintext or a dev CA is a security regression on a shared LAN. - `--mode local` / `socket` serve no socket and are deliberately unaffected. **Client — always `wss`, required bundle.** `_build_realtime_url` loses its `use_tls` parameter (always `wss://`); `websocket_client` raises, and `computer-client`'s `main()` errors, when neither `--ca-bundle` nor `STARFLEET_CA_BUNDLE` is given. `client.sh` / `client.sh.example` gain `--ca-bundle` in the same change, because they connect with none today and break the moment the server requires TLS. **Scripts — same rule for every PC-side dialer.** `synthetic_conversation_realtime_client.py` (and its explicit `--url` plaintext rejection), `listen_and_play_realtime.py`, `test_audio_path.py` (whose `--local` self-test now mints its own throwaway certificate and serves/dials TLS), `test_live_speech.py`, and `test_server_local.py` (a *server* launcher, so it forwards `--ws-tls-cert`/`--ws-tls-key`/`--dev-trust`). `tests/test_tls_invariant.py` is a static fence over the five scripts, which CI's `pytest tests/` never imports. **Test double.** `tests/conformance/fake_realtime_server.py` now takes a required `ssl_context` and serves TLS from an **in-test throwaway self-signed certificate** (`tests/tls_certs.py` + a session fixture) — not the shared dev set, which keeps the suite self-contained. **Docs.** README, `AGENTS.md`, `CONFORMANCE.md`, `server.sh.example`, the canonical `src/computer/api/openai_realtime/README.md`, and every realtime example carry the required material. ## Verification Sandbox suite at the branch head: **968 passed, 1 deselected**, `ruff check` / `ruff format --check` / `mypy src/` clean. The sandbox needs three mitigations and `/tmp` does not survive a sandbox recreate: ```bash cd $HOME/dev/starfleet/computer # 1. the container has no PortAudio: stub sounddevice on PYTHONPATH # 2. unset the proxy vars, or httpx demands the 'socksio' package # 3. three NLTK-`punkt_tab`-dependent files are ignored (egress-blocked) env -u ALL_PROXY -u HTTP_PROXY -u HTTPS_PROXY -u all_proxy -u http_proxy -u https_proxy \ PYTHONPATH=/tmp/opencode/sdstub .venv/bin/python -m pytest tests/ -q -p no:cacheprovider \ --ignore=tests/test_chat_completions_backend.py \ --ignore=tests/test_responses_api_language_model.py \ --ignore=tests/test_voice_prompt.py \ --deselect tests/test_omnivoice_tts_handler.py::test_setup_flashinfer_import_failure_raises ``` CI (`.forgejo/workflows/ci.yml`, ubuntu-latest with `libportaudio2` and the NLTK data) is the authoritative full-suite run. Every plaintext-asserting test was **inverted rather than deleted**, per the spec's "Testing and verification": the partial-pair config test now requires both flags, the empty-pair case is pinned, the `ws://` URL assertions flipped to `wss://`, the fake server and the reconnect test perform real TLS handshakes against the throwaway certificate, and the local self-test in `test_audio_path.py` was run green. Whole-branch review: no Critical findings; one Important documentation regression (the canonical realtime README's examples could no longer start, and the file was missing from the root README's pointer sentence) found and fixed, plus two same-class Minor traps. ## Known cross-repo impact (accepted, follow-up required) `communicator-esp32/host/tests/fake_server_fixture.py` loads this repo's `tests/conformance/fake_realtime_server.py` **by file path** and calls `FakeServer()` over `ws://`. TLS is now a required constructor argument, so esp32's host suite fails immediately with a missing-argument `TypeError` at fixture setup — loud and self-explanatory, not a silent protocol drift. The esp32 follow-up (pass an `ssl_context`, dial `wss://` with the throwaway CA) is **not** part of this branch. ## Notes Deferred Minors recorded during per-task review and triaged "ship" by the whole-branch review — each has a one-line upgrade path: narrowing `server_tls.py`'s broad `except Exception`; an untested `<empty>` subject branch; the `__file__`-derived default dev path (fragile under a non-editable install); a tautological `resolve_trust_dir` default-path test (a plan defect); `RealtimeServer.__init__`'s guard untested; `assert server_tls is not None` (stripped under `python -O`); the untested `socket`-mode exemption; a pre-existing hard-coded test CA blob in `test_client_capture_mode.py`; the grep-shaped `test_tls_invariant.py`; `test_audio_path.py`'s optional `ca_bundle` default; a missing `wss://` guard on `listen_and_play_realtime.py`'s `--websocket-base-url`; conformance dead code; the `STT/README.md` and `TTS/README.md` snippet lists (pointer-covered); and one superseded sentence in the dated `docs/plans/2026-09-10-ota-computer.md`. On hardware, the unit currently pins the production CA (it still does); no on-hardware run was part of piece 3.
troed merged commit 311bfdd0f1 into devel 2026-10-14 16:55:55 +02:00
troed deleted branch feat/fleet-tls-piece-3-computer 2026-10-14 16:55:55 +02:00
Sign in to join this conversation.
No reviewers
No labels
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
starfleet/computer!20
No description provided.