Skip to content

feat(kernel): support SOCKS proxies from HTTPS_PROXY on the kernel backend - #607

Open
cathleeny wants to merge 1 commit into
mainfrom
cathleeny/ddf-socks-proxy-go
Open

cathleeny wants to merge 1 commit into
mainfrom
cathleeny/ddf-socks-proxy-go

Conversation

@cathleeny

@cathleeny cathleeny commented Nov 30, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

Makes SOCKS proxies from the environment behave on the kernel backend as they do on the Thrift backend, using the kernel's SOCKS support (databricks/databricks-sql-kernel#518).

  • An HTTP(S)_PROXY socks5:// URL is passed to the kernel as socks5h://, because net/http lets the proxy resolve socks5:// host names. When the warehouse would use a socks4:// or socks4a:// proxy, the connection fails with ErrInvalidKernelConfig, as net/http can't use them either; the error names the scheme, never the URL. When NO_PROXY bypasses the warehouse, such a proxy is passed to the kernel, which uses it (never a direct connection) for any other host that selects it.
  • The environment proxy applies to every kernel destination (warehouse, CloudFetch storage and OAuth). NO_PROXY is translated into the kernel's bypass list, also when it bypasses the warehouse. The warehouse always follows http.ProxyFromEnvironment exactly. For other hosts the kernel matches host names only, so host:port entries apply only with port 443, and .example.com also bypasses example.com. CONNECTION_PARAMETERS.md documents both; exact per-host routing needs a kernel API change and is a separate follow-up. The environment is read once per process, as on the Thrift path.
  • WithKernelProxy URLs, credentials and bypass lists still pass through unchanged; its docs now mention SOCKS URLs.
  • With only ALL_PROXY set, the driver passes no proxy and the kernel reads the environment itself (Thrift ignores ALL_PROXY). This is documented.

No options are added or renamed, and defaults are unchanged.

Dependencies

Needs databricks/databricks-sql-kernel#518. KERNEL_REV still pins 3b691d2, which rejects SOCKS URLs, so make test-kernel on the default path doesn't exercise SOCKS until the pin moves to the merged kernel commit. That update follows #518's merge, and the published kernel bindings in go.mod move with the kernel release.

Validation

  • Unit tests (CGO_ENABLED=0):
    • TestProxyForEndpoint and TestKernelBypassHosts cover socks5 → socks5h and socks4/4a rejection.
    • They also cover storage and OAuth bypass entries, a bypassed warehouse, port and leading-dot entries, *, and IP/CIDR entries.
    • TestResolveKernelProxyEnvironment runs each case in a child process with a real environment, including ALL_PROXY alone and WithKernelProxy winning over the environment.
  • Checks: go vet, go test -race and the -tags databricks_kernel tests pass, and lint reports no new findings.
  • Live against staging DBSQL and Reyden warehouses through a loopback SOCKS fixture that records each handshake:
    • Env socks5h/socks5 send the domain to the proxy, as on Thrift.
    • Credentials are accepted or rejected as expected, and a dead proxy fails closed.
    • NO_PROXY host and suffix entries go direct, ALL_PROXY alone works, and WithKernelProxy wins over the environment.
    • A 200,000-row CloudFetch query downloads through the proxy.
    • SELECT 1 through socks5h stayed within max(+25 %, +150 ms) of direct on both engines.
    • These runs predate the per-destination bypass change, which the unit tests cover.

This pull request and its description were written by Isaac.

@cathleeny
cathleeny force-pushed the cathleeny/ddf-socks-proxy-go branch from c0692fb to 4b8bb28 Compare December 1, 2026 19:41
@cathleeny
cathleeny marked this pull request as ready for review December 1, 2026 19:42
@cathleeny
cathleeny force-pushed the cathleeny/ddf-socks-proxy-go branch from 4b8bb28 to d00ce35 Compare December 1, 2026 20:25

@oss-reviewer-bot oss-reviewer-bot Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔀 Cross-reviewed: two independent reviews (Claude Opus 5.5 · GPT-6.1 Sol), checked by a judge model (Claude Sonnet 5.5).

Verdict: 1 High · 1 Low

Mostly solid: 1 medium, 1 low. The env rewrite and rejection logic are correct and well tested. The main concern is that the docs claim SOCKS support while the pinned kernel bindings may not ship it yet.

Comment thread CHANGELOG.md Resolved
Comment thread kernel_proxy.go Resolved
@cathleeny
cathleeny force-pushed the cathleeny/ddf-socks-proxy-go branch from d00ce35 to 87d2133 Compare December 1, 2026 21:10

@oss-reviewer-bot oss-reviewer-bot Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔀 Cross-reviewed: two independent reviews (Claude Opus 5.5 · GPT-6.1 Sol), checked by a judge model (Claude Sonnet 5.5).

Verdict: 1 High

Needs a kernel pin before merging: 1 high concern. The driver-side env mapping (socks5→socks5h, failing closed on socks4/4a, keeping credentials out of errors) is correct and well tested. The SOCKS support it documents depends on a kernel release this PR doesn't pin.

Comment thread CHANGELOG.md Resolved

@aakash-saravanan-db aakash-saravanan-db left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the PR! Normalizing environment socks5 to socks5h preserves Go's proxy-side DNS behavior, and the scheme-only error keeps credentials out of diagnostics. The isolated environment tests are useful for avoiding the standard library's cached environment state.

The main change needed is to preserve that policy for every request destination, including CloudFetch storage and OAuth hosts. I've also left a small test-necessity comment and followed up on the existing source-pin discussion; the published bindings update remains separate release work.

Please also shorten the PR description to the public behavior, dependencies, and relevant validation, removing internal tracking details and prior-review history.


This review was generated with GitHub MCP.

Comment thread kernel_config.go Resolved
Comment thread internal/backend/kernel/kernel_test.go Resolved
@cathleeny
cathleeny force-pushed the cathleeny/ddf-socks-proxy-go branch from 87d2133 to 46e6e6b Compare December 2, 2026 01:18

@oss-reviewer-bot oss-reviewer-bot Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔀 Cross-reviewed: two independent reviews (Claude Opus 5.5 · GPT-6.1 Sol), checked by a judge model (Claude Sonnet 5.5).

Verdict: 1 High · 1 Low

Looks good, with 1 low concern. The SOCKS rewrite and rejection, the NO_PROXY translation and the warehouse parity with Go are correct and well tested, including real-environment tests in a child process. The CHANGELOG entry understates how far the NO_PROXY handling changed.

This overview is Claude Opus 5.5's initial take; GPT-6.1 Sol added findings it doesn't mention — see the findings below.

Other findings

  • 🟠 High — The rewritten SOCKS URL still reaches the native setter, but the pinned kernel rejects SOCKS as acknowledged in the PR description, leaving the advertised feature unusable with the default dependency configuration. Update both the released bindings and source-build pin before merging, and add a tagged SOCKS setter test against those dependencies. (Found by GPT-6.1 Sol · the judge couldn't confirm it)

Comment thread CHANGELOG.md Resolved

@oss-reviewer-bot oss-reviewer-bot Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔀 Cross-reviewed: two independent reviews (Claude Opus 5.5 · GPT-6.1 Sol), checked by a judge model (Claude Sonnet 5.5).

Verdict: 1 High · 1 Low

The proxy translation logic looks correct, with one medium concern: the changelog announces SOCKS support before the linked kernel can use it. The kernel.Config proxy doc in internal/backend/kernel/config.go (outside the diff) still says the env path leaves ProxyBypassHosts empty, which this PR makes untrue (nit).

This overview is Claude Opus 5.5's initial take; GPT-6.1 Sol added findings it doesn't mention — see the findings below.

Comment thread kernel_proxy.go Resolved
Comment thread kernel_proxy.go Resolved
@cathleeny

Copy link
Copy Markdown
Collaborator Author

On the review's other finding (High, kernel pin), which the bot's judge couldn't confirm: not changing this here. It's the merge prerequisite already discussed in the resolved KERNEL_REV thread and listed under Dependencies. KERNEL_REV and the bindings move once databricks/databricks-sql-kernel#518 merges and is released, and a SOCKS setter test against those dependencies isn't possible before then.

@cathleeny
cathleeny force-pushed the cathleeny/ddf-socks-proxy-go branch from fd2ead6 to 2747d8d Compare December 2, 2026 02:30

@oss-reviewer-bot oss-reviewer-bot Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔀 Cross-reviewed: two independent reviews (Claude Opus 5.5 · GPT-6.1 Sol), checked by a judge model (Claude Sonnet 5.5).

Verdict: 1 High · 1 Low

Looks good, with 1 low concern. The NO_PROXY translation matches httpproxy's rules, the SOCKS scheme mapping fails closed without leaking the URL, and tests cover the branches. Nits: the WithKernelProxy doc still says "basic-auth credentials" only, and the env fallback assertion in TestResolveKernelProxy is now weak (exact cases live in the child-process test).

This overview is Claude Opus 5.5's initial take; GPT-6.1 Sol added findings it doesn't mention — see the findings below.

Other findings

  • 🟠 High — The new SOCKS translation still reaches a kernel that rejects SOCKS URLs: the shipped bindings remain v1.5.0 and KERNEL_REV remains 3b691d2, as acknowledged in the description, so the advertised feature cannot work for consumers of this PR. Update the published bindings pins and KERNEL_REV before merging, and add a SOCKS case to the real applyProxy setter test so this dependency gap fails validation. (Found by GPT-6.1 Sol · the judge couldn't confirm it)

Comment thread kernel_proxy.go Resolved
@cathleeny
cathleeny force-pushed the cathleeny/ddf-socks-proxy-go branch from 2747d8d to 311641d Compare December 2, 2026 08:43

@oss-reviewer-bot oss-reviewer-bot Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔀 Cross-reviewed: two independent reviews (Claude Opus 5.5 · GPT-6.1 Sol), checked by a judge model (Claude Sonnet 5.5).

Verdict: 1 High · 1 Low

Looks good, with 1 low concern. I checked the SOCKS rewrite, the NO_PROXY translation and the error propagation from resolveKernelProxy, and they look correct and well tested. The Reyden fallback path doesn't call resolveKernelProxy, but that was already true before this PR.

This overview is Claude Opus 5.5's initial take; GPT-6.1 Sol added findings it doesn't mention — see the findings below.

Other findings

  • 🟠 High — The new SOCKS URL still reaches a native proxy setter without the required kernel dependency update: the PR acknowledges that pinned revision 3b691d2 rejects SOCKS, and the published bindings remain unchanged, so normal pinned builds cannot deliver this feature. Update KERNEL_REV and the released bindings together before merging, and add a tagged SOCKS case exercising the real applyProxy setter. (Found by GPT-6.1 Sol · the judge couldn't confirm it)

Comment thread kernel_proxy.go Resolved
@cathleeny

Copy link
Copy Markdown
Collaborator Author

On the latest review's High (pinned kernel and bindings), which the bot's judge couldn't confirm: it's the merge prerequisite already answered in the resolved KERNEL_REV threads and listed under Dependencies. KERNEL_REV and the bindings move together once databricks/databricks-sql-kernel#518 merges and is released. A tagged SOCKS case against the real setter would only pass after that pin bump, so it belongs in that change.

…ckend

With a kernel that supports SOCKS, keep the Thrift path's behavior for an
environment-derived SOCKS proxy on the kernel path. net/http resolves
socks5:// targets at the proxy, so an HTTPS_PROXY socks5:// URL is sent to
the kernel as socks5h://. net/http cannot use socks4/socks4a, so when the
warehouse selects one the connection fails with ErrInvalidKernelConfig; the
error names the scheme, not the URL. When NO_PROXY bypasses the warehouse,
a socks4/socks4a URL is passed as is, since no request may need it.
WithKernelProxy URLs are still passed verbatim with kernel semantics.

The environment proxy now applies to every kernel destination: the driver
passes it with NO_PROXY translated into the kernel's bypass list, so
CloudFetch storage and OAuth hosts in NO_PROXY connect directly. When
NO_PROXY bypasses the warehouse, the proxy is still passed with the
warehouse added to the bypass list, instead of leaving the kernel to read
the raw environment. The warehouse always follows Go's NO_PROXY rules, and
the environment is read once per process, as on the Thrift path.

Document the kernel-path SOCKS and NO_PROXY behavior, including ALL_PROXY,
which the kernel reads itself when no HTTP(S)_PROXY applies.

Signed-off-by: Cathleen Yan <58714163+cathleeny@users.noreply.github.com>
Co-authored-by: Isaac <no-reply@databricks.com>
@cathleeny
cathleeny force-pushed the cathleeny/ddf-socks-proxy-go branch from 311641d to b851e2e Compare December 2, 2026 09:12

@oss-reviewer-bot oss-reviewer-bot Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔀 Cross-reviewed: two independent reviews (Claude Opus 5.5 · GPT-6.1 Sol), checked by a judge model (Claude Sonnet 5.5).

Verdict: 1 High

Mostly solid, with 1 medium concern: the docs claim SOCKS support that the pinned kernel bindings don't provide yet. The NO_PROXY translation and the warehouse-exact filtering look correct and are well tested. Nit: the WithKernelProxy doc comment still says "basic-auth credentials", while the struct docs now also cover RFC 1929 for SOCKS5.

Comment thread CHANGELOG.md
- Evict kernel connections when SEA reports a missing or invalid session, and reject later requests locally without replaying the failed statement.
- Reduce Thrift row-scan CPU by binding scalar readers and null/type handling once per Arrow record (databricks/databricks-sql-go#602).
- **Behavior change:** Closed Thrift Arrow row scanners return an explicit error without logging an ERROR instead of stale values; a destination whose column count differs from the Arrow holders now errors instead of filling leading columns or NULL-padding missing columns. Column-value setup failures now stop scanning and are retained for subsequent scans instead of only being logged and ignored (databricks/databricks-sql-go#602).
- Support SOCKS proxies on the kernel backend; see [Proxy](CONNECTION_PARAMETERS.md#proxy).

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟠 High — The CHANGELOG and docs advertise kernel SOCKS support, but this PR does not touch KERNEL_REV or the v1.5.0 per-platform bindings in go.mod. I found no SOCKS handling in the kernel Go wrapper, so the pinned native kernel probably still rejects SOCKS URLs, including the socks5h:// URL this code produces. Bump the pins to a SOCKS-capable kernel release, or hold the changelog and docs entries until then.

🔀 Found by both reviewers · confirmed by the judge

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants