Skip to content

feat: in-binary TLS proxy library (with honest re-scope of ADR-003 #4) - #32

Merged
johnnyhuy merged 1 commit into
mainfrom
feat/tls-proxy-library
Aug 7, 2026
Merged

feat: in-binary TLS proxy library (with honest re-scope of ADR-003 #4)#32
johnnyhuy merged 1 commit into
mainfrom
feat/tls-proxy-library

Conversation

@johnnyhuy

Copy link
Copy Markdown
Contributor

Summary

  • Adds opengateway/mojo_bridge/tls_proxy.py: a stdlib-ssl TLS-terminating proxy (accept TLS, proxy to cleartext loopback). Three pytest tests prove the proxy works in pure Python (round-trip, cleartext rejection, multi-chunk forwarding).
  • The proxy is not wired into main.mojo in this commit — the Mojo runtime's daemon-thread + GILReleased interaction prevents the proxy's pump threads from forwarding bytes between the TLS socket and the upstream socket inside the binary. The TLS handshake completes; the byte pump stalls.

Consequences

  • ADR-003 follow-up Add routing guardrails for cost caps and provider fallback #4 re-scoped honestly. Two blockers, both unsolvable from this repo:
    1. Reactor-native TLS serving in flare is a deferred upstream follow-up (STATE_TLS_HANDSHAKE gated on a future Mojo nightly; the server-side FFI ships handshake-only with no SSL_read/SSL_write data path).
    2. In-binary stdlib-ssl proxy works in isolation (this commit proves it) but does not compose cleanly with the Mojo runtime's daemon-thread concurrency model.
  • Production continues to terminate TLS at the edge LB (the standard gateway deployment shape). main.mojo binds cleartext on the loopback address so an LB can proxy in without exposing cleartext to the network.
  • The validated tls_proxy.py is kept in-tree as a reference implementation and a building block for when either blocker is resolved (flare reactor TLS or a deeper investigation of the Mojo GIL/threading interaction).

Testing

  • uv run pytest tests/test_tls_proxy.py — 3 passed (round-trip, cleartext rejected, multi-chunk forwarding); 42 total pytest passed.
  • make mojo-test — 8/8 passed.
  • ruff + mypy clean.
  • Mojo binary builds clean (810 KB).

Adds opengateway.mojo_bridge.tls_proxy: a stdlib-ssl TLS-terminating
proxy that accepts TLS on a public port and proxies bytes to a
cleartext loopback listener. Three tests (round-trip, cleartext
rejection, multi-chunk forwarding) pass in pure Python.

The proxy is a vetted building block but is **not wired into
main.mojo** in this commit — the Mojo runtime's daemon-thread +
GILReleased interaction does not let the proxy's pump threads
forward bytes from the TLS socket to the upstream socket
(the handshake completes inside the binary, but recv stalls).
Reactor-native TLS serving in flare is a separate deferred
upstream follow-up (the STATE_TLS_HANDSHAKE state machine is gated
on a future Mojo nightly, and the server-side FFI has no SSL_read
/ SSL_write data path because the reactor integration was never
wired).

ADR-003 #4 is updated to reflect both blockers honestly. The proxy
remains the in-binary stand-in ready for when the underlying
concurrency interaction is understood; production continues to
terminate TLS at the edge LB (the standard gateway deployment
shape).

Co-authored-by: opencode-agent <noreply@opencode.ai>
@johnnyhuy
johnnyhuy merged commit c12f395 into main Aug 7, 2026
11 checks passed
@johnnyhuy
johnnyhuy deleted the feat/tls-proxy-library branch August 7, 2026 12:44
johnnyhuy added a commit that referenced this pull request Aug 9, 2026
Adds opengateway.mojo_bridge.tls_proxy: a stdlib-ssl TLS-terminating
proxy that accepts TLS on a public port and proxies bytes to a
cleartext loopback listener. Three tests (round-trip, cleartext
rejection, multi-chunk forwarding) pass in pure Python.

The proxy is a vetted building block but is **not wired into
main.mojo** in this commit — the Mojo runtime's daemon-thread +
GILReleased interaction does not let the proxy's pump threads
forward bytes from the TLS socket to the upstream socket
(the handshake completes inside the binary, but recv stalls).
Reactor-native TLS serving in flare is a separate deferred
upstream follow-up (the STATE_TLS_HANDSHAKE state machine is gated
on a future Mojo nightly, and the server-side FFI has no SSL_read
/ SSL_write data path because the reactor integration was never
wired).

ADR-003 #4 is updated to reflect both blockers honestly. The proxy
remains the in-binary stand-in ready for when the underlying
concurrency interaction is understood; production continues to
terminate TLS at the edge LB (the standard gateway deployment
shape).

Co-authored-by: opencode-agent[bot] <219766164+opencode-agent[bot]@users.noreply.github.com>
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.

1 participant