Repository navigation
feat(tls): client-side TLS termination via --tls-cert/--tls-key - #19
Merged
Merged
Conversation
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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) andupgrade_writer_tls(writer, ctx)for in-band STARTTLS-style upgrades. asyncio streams expose no public server-side upgrade (StreamWriter.start_tlsis client-only), so it drivesloop.start_tlson the stream's own transport+protocol and rebinds the writer's transport slot — the reader keeps buffered bytes.cli.py—--tls-cert/--tls-keyflags (+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.SSLRequest→S+ upgrade when configured (Notherwise);GSSENCRequestalwaysN.CLIENT_SSLkept in the relayed greeting when configured; an SSLRequest upgrades in-band and the real handshake response is read inside TLS. Without a pair the existing1043/08S01 Bad handshakerefusal is preserved.CLIENT_COMPRESS/CLIENT_ZSTD_COMPRESSIONare always stripped (the proxy doesn't speak compressed framing).ssl=onasyncio.start_server:rediss:///grpcs:///tcps://listeners. gRPC's upstream leg stays prior-knowledge h2c (grpcs://upstreams still rejected at the CLI seam).web.run_app(ssl_context=...)makes the main listenerhttps://; the banner reports the real scheme.fidelity/rest_sweep.json— installed botocore dropped thebedrock-agentcore-controlRetrievalInstruction 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, pgSSLRequest→Supgrade + startup + query inside TLS +GSSENCstillNinside the tunnel, mysql SSLRequest upgrade + plaintext client still works,redissround-trip + plaintext rejection,grpcsunary call,tcpsecho, https HTTP listener proxying + healthpytest— 1705 passed, 2 skippedruff check src/ tests/— cleanpyright— 0 errors