feat: add the proxy command with a transparent TCP relay - #1
Merged
Conversation
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
Adds the
proxysubcommand: a transparent TCP relay that sits between a client and a PostgreSQL server and forwards bytes unchanged. This is the outer shell that the wire parser, policy evaluation, and ledger will be layered into; today it enforces nothing and records nothing.What is in here
internal/proxy:Server{Upstream, Logger}.Serve(ctx, ln)accepts connections, dials the upstream with a 10s timeout, and relays both directions. A half-close on one side is passed on asCloseWriteso the other direction can drain. TransientAccepterrors are retried with exponential backoff (5ms to 1s); only a closed listener is fatal. Canceling the context closes the listener and every live session and returnsnil, soSIGINT/SIGTERMexit 0.internal/cli:rollcall proxy -upstream ADDR [-listen ADDR](default listen127.0.0.1:6432). Both addresses are validated ashost:portbefore binding.-his only treated as a help request when it is the first argument; elsewhere theflagpackage handles it. The template'shellocommand is removed.log/slog: onelisteningline at startup, session open/close at debug level, and a warning for relay errors other than EOF or a closed connection.Testing
make testandmake lint(custom-gcl withdeadmutandpointless) pass.internal/proxy: relays both directions through an echo server, propagates half-close, closes the client when the upstream is unreachable, and returns anaccept:error when the listener is closed externally.internal/cli: flag and address validation cases, help handling before and after flags, and a live-listener test that starts the proxy, waits for thelisteninglog line, cancels, and asserts exit 0.Not in this PR
PostgreSQL message framing, statement classification, policy, and the ledger. The next step replaces the client-to-upstream
io.Copywith a message-framed loop.