Skip to content

feat(tls): client-side TLS termination via --tls-cert/--tls-key - #19

Merged
pingedbrain merged 2 commits into
mainfrom
feat/tls-termination
Oct 28, 2026
Merged

pingedbrain merged 2 commits into
mainfrom
feat/tls-termination

Conversation

@pingedbrain

Copy link
Copy Markdown
Owner

Summary

Closes #18. Part of #6 (TLS termination — the second remaining item after the stream-mode injection landed in #17).

Client-side TLS termination with an operator-supplied cert/key pair — no generation, no CA integration, no upstream re-encryption (the upstream leg stays plaintext, matching the local-dev workflow every transport already targets).

  • src/microburst/tls.py — shared helpers: server_ssl_context(cert, key) (all-or-nothing pair validation, PROTOCOL_TLS_SERVER + load_cert_chain) and upgrade_writer_tls(writer, ctx) for in-band STARTTLS-style upgrades. asyncio streams expose no public server-side upgrade (StreamWriter.start_tls is client-only), so it drives loop.start_tls on the stream's own transport+protocol and rebinds the writer's transport slot — the reader keeps buffered bytes.
  • cli.py — --tls-cert/--tls-key flags (+ tls_cert:/tls_key: config keys); a lone half exits with code 2 before dispatch.
  • transports.py — options=("tls_cert","tls_key") on postgres/redis/mysql/grpc/tcp so the registry forwards them.
  • postgres — SSLRequest → S + upgrade when configured (N otherwise); GSSENCRequest always N.
  • mysql — CLIENT_SSL kept in the relayed greeting when configured; an SSLRequest upgrades in-band and the real handshake response is read inside TLS. Without a pair the existing 1043/08S01 Bad handshake refusal is preserved. CLIENT_COMPRESS/CLIENT_ZSTD_COMPRESSION are always stripped (the proxy doesn't speak compressed framing).
  • redis/grpc/tcp — ssl= on asyncio.start_server: rediss:///grpcs:///tcps:// listeners. gRPC's upstream leg stays prior-knowledge h2c (grpcs:// upstreams still rejected at the CLI seam).
  • http — web.run_app(ssl_context=...) makes the main listener https://; the banner reports the real scheme.
  • Docs synchronized (README per-transport limitation lists, ROADMAP remaining-scope lines, AGENTS.md, examples/14-grpc).
  • Also regenerates fidelity/rest_sweep.json — installed botocore dropped the bedrock-agentcore-control RetrievalInstruction API; same drift maintenance as fix(ci): unbreak main — pyright strictness errors + rest_sweep refresh #11, needed for the suite to pass.

Test plan

  • tests/test_tls.py — 12 new tests (openssl-minted self-signed pair, skipped when openssl absent): pair validation, CLI lone-flag rejection, pg SSLRequest→S upgrade + startup + query inside TLS + GSSENC still N inside the tunnel, mysql SSLRequest upgrade + plaintext client still works, rediss round-trip + plaintext rejection, grpcs unary call, tcps echo, https HTTP listener proxying + health
  • pytest — 1705 passed, 2 skipped
  • ruff check src/ tests/ — clean
  • pyright — 0 errors

Operator-supplied cert/key pair terminates TLS on the client-facing
listener for every transport; the upstream leg stays plaintext (no
re-encryption, no cert generation, no CA integration).

- src/microburst/tls.py: server_ssl_context() builds the pair-validated
  server context (all-or-nothing, a lone half is a config error) and
  upgrade_writer_tls() performs the in-band STARTTLS-style upgrade —
  asyncio streams expose no public server-side upgrade, so it drives
  loop.start_tls on the stream's own transport+protocol.
- cli.py/transports.py: --tls-cert/--tls-key flags (+ tls_cert:/
  tls_key: config keys), pair validation before dispatch, options
  forwarded through the TRANSPORTS registry.
- postgres: SSLRequest gets 'S' + in-band upgrade when configured,
  'N' otherwise; GSSENCRequest always 'N'.
- mysql: CLIENT_SSL stays in the relayed greeting when configured and
  an SSLRequest upgrades mid-handshake (the real handshake response is
  read inside TLS); without a pair the 1043/08S01 Bad handshake
  refusal is preserved. Compression caps still stripped.
- redis/grpc/tcp: ssl= on asyncio.start_server — rediss/grpcs/tcps
  listeners; grpc upstream stays prior-knowledge h2c.
- http: web.run_app(ssl_context=...) — the listener becomes https.

Also regenerates fidelity/rest_sweep.json — the installed botocore
removed the bedrock-agentcore-control RetrievalInstruction API, so the
committed snapshot drifted again (same maintenance as #11).

12 new tests in tests/test_tls.py cover pair validation, the pg
SSLRequest→S upgrade (+ GSSENC still refused inside TLS), the mysql
SSLRequest upgrade, TLS-from-connect listeners for redis/grpc/tcp, the
https HTTP listener, and plaintext rejection on a TLS listener.

Closes #18. Part of #6 (TLS termination).
CI installs the floating botocore (uv pip install ignores uv.lock);
1.43.120 reshaped bedrock-agentcore-control — committed snapshot must
match what the sweep test runs against.
@pingedbrain
pingedbrain merged commit 38dbd11 into main Oct 28, 2026
5 checks passed
@pingedbrain
pingedbrain deleted the feat/tls-termination branch October 28, 2026 02:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

feat: TLS termination with user-provided certs (--tls-cert/--tls-key)

1 participant