feat(sdk): tcp_egress_guard env passthrough (redirect a client's DB endpoint at the proxy) - #103
Open
quanghexa94 wants to merge 1 commit into
Open
feat(sdk): tcp_egress_guard env passthrough (redirect a client's DB endpoint at the proxy)#103quanghexa94 wants to merge 1 commit into
quanghexa94 wants to merge 1 commit into
Conversation
…he proxy
tcp_egress_guard gains an `env` passthrough: each entry is a template with
{host}/{port} placeholders, set to the running proxy's address for the duration
of the block and restored on exit. An agent that reads its database endpoint
from the environment (PGHOST/PGPORT, or a DATABASE_URL) is then gated by
wrapping it, with no change to the code that opens the connection. This is the
same wrap-from-outside shape as egress_guard, so the caller no longer has to
thread the DSN by hand.
async with tcp_egress_guard(enforcer, user, target=("db.internal", 5432),
env={"PGHOST": "{host}", "PGPORT": "{port}"}):
run_agent(...)
An agent that hardcodes host/port inside a DSN still can't be redirected from
the outside; that case needs a transparent-redirect sandbox.
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
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.
What & why
Hexgate is used by wrapping an agent from the outside (
enforce_policy(agent, ...)), not by editing the code that opens each connection. HTTP egress already fits that:egress_guardsetsHTTP_PROXY, and the agent's clients route through the proxy on their own.tcp_egress_guarddidn't fit it. It only handed backproxy.host/proxy.portfor you to thread into a DSN by hand, which assumes you own the line that opens the database connection. In real usage that line is buried inside the agent or a tool.This loosens that.
tcp_egress_guardtakes anenvpassthrough: templates with{host}/{port}placeholders that get pointed at the running proxy and restored on exit. An agent that reads its endpoint from the environment (PGHOST/PGPORT, or aDATABASE_URL) is now gated by wrapping it, no change to its connection code.Where to look
hexgate/egress/tcp.pytcp_egress_guardgainsenv; sets each templated var to the proxy address, restores on exit. Docstring now leads with the wrap-from-outside shape.tests/egress/test_tcp.pyHonest limit (unchanged)
An agent that hardcodes host and port inside a DSN can't be redirected from the outside, the same class as an HTTP client with
trust_env=False. Catching that case needs a transparent-redirect sandbox, which is out of scope for the library.Full egress + TCP suites pass.