feat: roster serves TLS on both surfaces, with required material #5

Merged
troed merged 7 commits from feat/app-tier-tls into main 2026-10-17 18:16:07 +02:00
Owner

feat: roster serves TLS on both surfaces, with required material

What this is

Part of the fleet app-tier TLS change. Design and plan live in the
starfleet docs repo:

  • docs/superpowers/specs/2026-10-17-app-tier-tls-design.md
  • docs/superpowers/plans/2026-10-17-app-tier-tls.md
  • docs/superpowers/plans/2026-10-17-app-tier-tls-runbook.md (the live cutover)

Roster served plain HTTP on :4020 (API + admin UI) and :4021 (MCP). The
admin UI carried a bearer token in localStorage over cleartext, and the MCP
surface was reached over cleartext. Nothing in the roster docs mentioned
transport security — the plaintext default was by omission, not by decision.

After this branch roster can only serve TLS, and a missing or partial
tls_cert/tls_key pair is a startup error naming the missing key rather than
a silent plaintext fallback.

Change

Config. [api] tls_cert / tls_key and a new [trust] ca_bundle, mapped
to api_tls_cert, api_tls_key, trust_ca_bundle, all joined to
_PATH_FIELDS. Parsing stays validation-free — load_config is used by
non-serving commands, so the required-pair check lives in the serve paths.

One assembly point. server_kwargs(cfg) builds the uvicorn kwargs and
raises ConfigError naming tls_cert or tls_key on an incomplete pair. Both
serve() and mcp_server.main() consume it, so the two surfaces cannot
diverge — and it is evaluated before roster.start(), so a bad pair no
longer fires a scheduler tick first.

The MCP surface needed real work. The installed mcp SDK's
run_streamable_http_async builds its own uvicorn.Config and exposes no
ssl arguments, so it cannot serve TLS. It now builds
streamable_http_app(...) and runs our own uvicorn.Config, preserving every
other transport default of the helper it replaced — including host=, without
which DNS-rebinding protection would auto-enable for 127.0.0.1 while bound to
0.0.0.0 and 403 real LAN clients.

Outbound trust. New trust.py::resolve_ca_bundle resolves
--ca-bundle → $STARFLEET_CA_BUNDLE → [trust] ca_bundle → ConfigError
naming all three, and validates the resolved bundle with
load_verify_locations. A path that is missing or is not a PEM therefore fails
at resolution, naming the setting and the path — not at the first request, where
it would look like "the server is down" (and, for the MCP process, only after
it had already bound its socket). RosterClient gained a ca_bundle parameter;
delivery.py's crew POST uses the resolved bundle; the MCP process talks to the
API over https://127.0.0.1:<api_port>.

Two config hazards fixed. Config.expand() now leaves an empty path value
empty — the new TLS fields are the first empty-default _PATH_FIELDS members,
and Path("") becomes ".", which would have made the required-pair check
unfirable. And serve()/mcp_server.main() now expand the loaded config at
all: they never did, and a ~/.config/… cert path would have reached uvicorn
raw.

CLI. --ca-bundle (global to the client subcommands, as in crew); the
default --url is now https://127.0.0.1:4020. main() catches ConfigError
for every command, so a missing or unreadable CA prints a clean error: …
and exits 1 instead of a stack trace — serve/mcp still refuse to start, which
is the intended loud failure; only the presentation changed.

Docs. README (TLS section, CA resolution order, https URLs) and
roster.toml.example.

Verification

Sandbox suite at the branch head: 235 passed, ruff check /
ruff format --check / mypy src/ clean.

cd $HOME/dev/starfleet/roster
export UV_CACHE_DIR=/tmp/opencode/uv-cache      # ~/.cache/uv is read-only in the sandbox
uv sync --quiet                                 # host-made .venv is unusable in-sandbox
env -u ALL_PROXY -u all_proxy -u HTTPS_PROXY -u https_proxy -u HTTP_PROXY -u http_proxy \
  uv run ruff check src/ tests/ && uv run ruff format --check src/ tests/ \
  && uv run mypy src/ && uv run pytest tests/ -q

Verification is proven by real TLS, not mocks: one test stands up a self-signed
TLS peer and asserts both the positive control (trusting the peer's own cert
succeeds) and the negative (a different bundle refuses the handshake); another
serves the real streamable_http_app under a real uvicorn.Server with a
self-signed leaf and completes a handshake against /mcp. Tests that asserted
plaintext behaviour were inverted, not deleted.

Cross-repo / ops

  • crew and communicator-esp32 carry the sibling pieces.
  • The live cutover is not part of this branch; it is the runbook in the
    starfleet docs repo, deliberately ordered server-first so the OpenCode
    MCP URL is flipped only after roster serves TLS.

Deferred minors (triaged ship)

  • The MCP surface's uvicorn log level is hardcoded to info (equals the SDK's
    effective default today).
  • Client commands that need no config now read the default config path to reach
    the [trust] ca_bundle tier.
  • No --ca-bundle on serve; env and config cover the delivery POST.
  • delivery.py requires a resolvable CA even when the target URL is plaintext —
    one contract beats a conditional one.
  • selftest's mid-poll API loss now prints error: rather than
    selftest FAIL:; doctor's newly clean error path is untested.
  • The mandated TLS tests inherit the certificate helper's pytest.skip when
    openssl is absent (green-by-skip on such a machine).
  • verify=<str> is deprecated in httpx 0.28.1 — this is a plan flaw (the plan
    mandated the string form); verification is on today, but a future httpx bump
    removes the form. Migration is to pass an ssl.SSLContext.
# feat: roster serves TLS on both surfaces, with required material ## What this is Part of the fleet **app-tier TLS** change. Design and plan live in the `starfleet` docs repo: - `docs/superpowers/specs/2026-10-17-app-tier-tls-design.md` - `docs/superpowers/plans/2026-10-17-app-tier-tls.md` - `docs/superpowers/plans/2026-10-17-app-tier-tls-runbook.md` (the live cutover) Roster served plain HTTP on `:4020` (API + admin UI) and `:4021` (MCP). The admin UI carried a bearer token in `localStorage` over cleartext, and the MCP surface was reached over cleartext. Nothing in the roster docs mentioned transport security — the plaintext default was by omission, not by decision. After this branch roster can only serve TLS, and a missing **or partial** `tls_cert`/`tls_key` pair is a startup error naming the missing key rather than a silent plaintext fallback. ## Change **Config.** `[api] tls_cert` / `tls_key` and a new `[trust] ca_bundle`, mapped to `api_tls_cert`, `api_tls_key`, `trust_ca_bundle`, all joined to `_PATH_FIELDS`. Parsing stays validation-free — `load_config` is used by non-serving commands, so the required-pair check lives in the serve paths. **One assembly point.** `server_kwargs(cfg)` builds the uvicorn kwargs and raises `ConfigError` naming `tls_cert` or `tls_key` on an incomplete pair. Both `serve()` and `mcp_server.main()` consume it, so the two surfaces cannot diverge — and it is evaluated **before** `roster.start()`, so a bad pair no longer fires a scheduler tick first. **The MCP surface needed real work.** The installed `mcp` SDK's `run_streamable_http_async` builds its own `uvicorn.Config` and exposes **no** ssl arguments, so it cannot serve TLS. It now builds `streamable_http_app(...)` and runs our own `uvicorn.Config`, preserving every other transport default of the helper it replaced — including `host=`, without which DNS-rebinding protection would auto-enable for `127.0.0.1` while bound to `0.0.0.0` and 403 real LAN clients. **Outbound trust.** New `trust.py::resolve_ca_bundle` resolves `--ca-bundle` → `$STARFLEET_CA_BUNDLE` → `[trust] ca_bundle` → `ConfigError` naming all three, and **validates** the resolved bundle with `load_verify_locations`. A path that is missing or is not a PEM therefore fails at resolution, naming the setting and the path — not at the first request, where it would look like "the server is down" (and, for the MCP process, only after it had already bound its socket). `RosterClient` gained a `ca_bundle` parameter; `delivery.py`'s crew POST uses the resolved bundle; the MCP process talks to the API over `https://127.0.0.1:<api_port>`. **Two config hazards fixed.** `Config.expand()` now leaves an empty path value empty — the new TLS fields are the first empty-default `_PATH_FIELDS` members, and `Path("")` becomes `"."`, which would have made the required-pair check unfirable. And `serve()`/`mcp_server.main()` now expand the loaded config at all: they never did, and a `~/.config/…` cert path would have reached uvicorn raw. **CLI.** `--ca-bundle` (global to the client subcommands, as in crew); the default `--url` is now `https://127.0.0.1:4020`. `main()` catches `ConfigError` for **every** command, so a missing or unreadable CA prints a clean `error: …` and exits 1 instead of a stack trace — `serve`/`mcp` still refuse to start, which is the intended loud failure; only the presentation changed. **Docs.** README (TLS section, CA resolution order, `https` URLs) and `roster.toml.example`. ## Verification Sandbox suite at the branch head: **235 passed**, `ruff check` / `ruff format --check` / `mypy src/` clean. ```bash cd $HOME/dev/starfleet/roster export UV_CACHE_DIR=/tmp/opencode/uv-cache # ~/.cache/uv is read-only in the sandbox uv sync --quiet # host-made .venv is unusable in-sandbox env -u ALL_PROXY -u all_proxy -u HTTPS_PROXY -u https_proxy -u HTTP_PROXY -u http_proxy \ uv run ruff check src/ tests/ && uv run ruff format --check src/ tests/ \ && uv run mypy src/ && uv run pytest tests/ -q ``` Verification is proven by real TLS, not mocks: one test stands up a self-signed TLS peer and asserts both the positive control (trusting the peer's own cert succeeds) and the negative (a different bundle refuses the handshake); another serves the real `streamable_http_app` under a real `uvicorn.Server` with a self-signed leaf and completes a handshake against `/mcp`. Tests that asserted plaintext behaviour were **inverted, not deleted**. ## Cross-repo / ops - `crew` and `communicator-esp32` carry the sibling pieces. - The live cutover is **not** part of this branch; it is the runbook in the `starfleet` docs repo, deliberately ordered **server-first** so the OpenCode MCP URL is flipped only after roster serves TLS. ## Deferred minors (triaged ship) - The MCP surface's uvicorn log level is hardcoded to `info` (equals the SDK's effective default today). - Client commands that need no config now read the default config path to reach the `[trust] ca_bundle` tier. - No `--ca-bundle` on `serve`; env and config cover the delivery POST. - `delivery.py` requires a resolvable CA even when the target URL is plaintext — one contract beats a conditional one. - `selftest`'s mid-poll API loss now prints `error:` rather than `selftest FAIL:`; `doctor`'s newly clean error path is untested. - The mandated TLS tests inherit the certificate helper's `pytest.skip` when `openssl` is absent (green-by-skip on such a machine). - `verify=<str>` is deprecated in httpx 0.28.1 — this is a **plan** flaw (the plan mandated the string form); verification is on today, but a future httpx bump removes the form. Migration is to pass an `ssl.SSLContext`.
- main(): catch ConfigError so a missing/unreadable CA prints a clean
  message instead of a raw traceback (ConfigError is a ValueError and
  escaped the CrewAPIError/httpx handlers).
- serve(): validate the TLS pair before the scheduler starts, so a partial
  pair cannot take a single outward-facing tick before refusing.
- server_kwargs(): strip before the emptiness test so a whitespace-only
  tls_cert/tls_key is named here rather than failing inside uvicorn.
- tests: match the distinguishing tail of the refusal message and add the
  key-only case, plus a whitespace-only case; add a clean-error test and a
  before-scheduler test; add real-listener TLS tests for the API and MCP
  surfaces (self-signed leaf + uvicorn.Server in a thread).
- README: the protocol lines and the crew_url example are HTTPS now.
fix(roster): guard every command against ConfigError, not just job commands
All checks were successful
CI / Sanity check (ubuntu-latest) (pull_request) Successful in 27s
a2ce3b829f
The ConfigError handler only covered the _JOB_CMDS branch; serve/mcp/notify/
selftest are dispatched by early return before that try, so a bad or absent
CA bundle (notify, selftest, mcp) still printed a raw traceback. Wrap the whole
dispatch in one try, keeping the RosterAPIError/httpx.HTTPError handling and
the exit code and message text unchanged. serve/mcp still fail on bad TLS/CA
material -- they just read as 'error: ...' now.

Also note in the README that crew_url's host must be a name crew's TLS leaf
covers, since roster verifies it.
troed merged commit 825d18f44f into main 2026-10-17 18:16:07 +02:00
troed deleted branch feat/app-tier-tls 2026-10-17 18:16:07 +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/roster!5
No description provided.