Skip to content

docs: describe SOCKS proxies from the environment on the kernel backend - #1082

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

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

Conversation

@cathleeny

Copy link
Copy Markdown
Collaborator

What type of PR is this?

  • Other (documentation)

Description

On the Thrift backend, SOCKS proxies don't work: a socks5h:// HTTPS_PROXY fails with urllib3's ProxySchemeUnknown, and ALL_PROXY is ignored. With today's kernel release, use_kernel=True fails closed for any SOCKS URL. The kernel SOCKS change (databricks/databricks-sql-kernel, candidate f4826ba16c8d460e4018f5b7de4d820c9a604d4a) adds SOCKS support to the kernel's existing environment-proxy handling, so with that kernel the connector's kernel path honors SOCKS proxies from the environment with no connector code change.

This PR documents that in CONNECTION_PARAMETERS.md as a recorded difference from Thrift. It adds a "SOCKS proxies from environment variables" section and one line in the "Supported on Kernel, missing / ignored on Thrift" gap list. The section covers:

  • the variables honored: HTTPS_PROXY, then ALL_PROXY when HTTPS_PROXY is unset, with NO_PROXY bypass;
  • the schemes accepted (socks4, socks4a, socks5, socks5h; bare socks:// is rejected);
  • DNS per scheme: socks5/socks4 resolve locally, socks5h/socks4a at the proxy;
  • credentials as URL userinfo (SOCKS5 RFC 1929), and fail-closed behavior;
  • Thrift's behavior (ProxySchemeUnknown for a SOCKS HTTPS_PROXY, ALL_PROXY ignored).

No connector code, option, default or guard changes. Feature: socks-proxy. No ADBC-specific changes.

How is this tested?

  • Unit tests
  • E2E Tests (live, through the public sql.connect API with a locally built kernel wheel)
  • Manually
  • N/A

Acceptance

  • AC-2 (connect, query, fetch and close through SOCKS): with use_kernel=True and HTTPS_PROXY=socks5h://…, SELECT 1 returns 1 and closes cleanly on both engines. The backend object is KernelDatabricksClient, and the fixture relayed the warehouse connection.
  • AC-3 (DNS per scheme, kernel semantics as documented): socks5h and socks4a send the warehouse host as a domain; socks5 and socks4 send an IPv4 address (DBSQL: all four; Reyden: socks5h, socks4a, socks5).
  • AC-4 (RFC 1929): a correct user:password@ pair in the URL passes on both engines. A wrong pair fails with SOCKS error: credentials not accepted, with no retry without credentials and no direct connection.
  • AC-5 (fail closed): with a dead proxy port, connect fails with error connecting to socks proxy and nothing reaches the warehouse. That took about 17 s with _retry_stop_after_attempts_count=1, and 103 s (6 attempts) under the default retry policy. A dead proxy on a CloudFetch query fails the same way.
  • AC-6 (bypass): NO_PROXY=<warehouse host> connects directly on both engines; NO_PROXY=.databricks.com connects directly on DBSQL. With a host-only NO_PROXY on the 200,000-row CloudFetch query, the warehouse connection goes direct while the storage-host downloads still go through the proxy, because they are not matched.
  • AC-7 (CloudFetch): a 200,000-row range() query downloads every storage chunk through the proxy, with the same address type as the workspace connection (domain for socks5h, IPv4 for socks5). Row counts are exact on DBSQL and Reyden.
  • AC-10 (env proxies on the kernel path; documented difference from Thrift): HTTPS_PROXY and ALL_PROXY each route through the proxy, and HTTPS_PROXY wins over a dead ALL_PROXY. In the same session, Thrift fails with ProxySchemeUnknown for a SOCKS HTTPS_PROXY and ignores ALL_PROXY, connecting directly.
  • No fake fixture credential appeared in any error or captured driver log line, and on the kernel path no Python-side (urllib3) connection was opened.
  • Dual pre-push review (Claude + Codex): not yet run. It reviews candidate 687029ab4b8ce2db5456941ce683a200e71606d0.
  • Driver API: unchanged. Approved deviation (D4): the kernel path honors env SOCKS proxies, which Thrift does not.

Baseline and target validation

Engine Baseline/version/effective path Target/effective path Cases Result
DBSQL Thrift, connector 4.10.0 (ThriftDatabricksClient) Kernel, local wheel built from kernel f4826ba (KernelDatabricksClient) env socks5h/socks5/socks4a/socks4 SELECT 1; ALL_PROXY only; HTTPS_PROXY beats ALL_PROXY; userinfo ok/bad; dead proxy (1 attempt, default retry, CloudFetch); NO_PROXY host/suffix; CloudFetch 200k socks5h/socks5/NO_PROXY host; direct control; Thrift HTTPS_PROXY and ALL_PROXY Kernel rows pass through the proxy or fail closed as expected. Thrift: ProxySchemeUnknown for HTTPS_PROXY; ALL_PROXY ignored (direct)
Reyden Thrift: HTTPS_PROXY fails client-side with ProxySchemeUnknown. With ALL_PROXY, Thrift goes direct, is rejected (KP001) and the connector recovers onto the kernel: unsupported, standing deviation RE-16039 Kernel (KernelDatabricksClient) env socks5h/socks5/socks4a; ALL_PROXY only; HTTPS_PROXY beats ALL_PROXY; userinfo ok/bad; dead proxy; NO_PROXY host; CloudFetch 200k socks5h; direct control Kernel rows pass through the proxy or fail closed as on DBSQL; Reyden returned external links for the CloudFetch query

Every positive row ran behind a controlled loopback SOCKS4/4a/5 fixture with --require-proxy, so a pass the fixture did not relay would count as a failure. The fixture records SOCKS version, address type and RFC 1929 result. The probe reports the effective transport from the connection's backend object and records the loaded kernel binary's hash, which matched the locally built wheel on every row.

Hermetic tests: pytest tests/unit -m "not realkernel" (1413 passed, 4 skipped), pytest tests/unit/test_session.py -m realkernel against the candidate kernel wheel (2 passed), pytest tests/unit/test_kernel_async_readers.py -m realkernel (6 passed), and black src --check (clean).

Bounded performance comparison: connect + open session + SELECT 1 + fetch + close, one fresh process per sample, kernel direct vs kernel HTTPS_PROXY=socks5h. Each pair had 1 warm-up plus 5 samples, interleaved and run sequentially with no other live cases. The agreed tolerance is a SOCKS median within max(+25 %, +150 ms) of the direct median.

  • DBSQL: 1445 ms direct (1118–1496) vs 1512 ms SOCKS (1471–1618), +67 ms against a limit of +361 ms.
  • Reyden: 1263 ms direct (1104–1285) vs 1196 ms SOCKS (1001–1368), −67 ms (run-to-run noise).

Both are within tolerance. The fixture is a single-threaded Python relay, so its overhead is included.

Nightly coverage: SOCKSPROXY-001..007 and 010 are planned in databricks-driver-test (specs/socks-proxy.yaml, tests/python/tests/test_socks_proxy.py), run by the existing databricks-sql-python-nightly.yml (cron 0 3 * * *, kernel/normal and kernel/reyden legs). That is a separate driver-test change. HTTP-proxy no-regression coverage is the existing HTTPPROXY-006..008 (tests/python/tests/test_environment_proxy.py) in the same nightly.

Blocked/unsupported cases: Reyden rejects Thrift (KP001), which is the standing deviation RE-16039. It is reported, not counted as a pass.

Related Tickets & Documents

  • PECOBLR-4152.
  • Depends on databricks/databricks-sql-kernel: SOCKS proxy support, candidate f4826ba16c8d460e4018f5b7de4d820c9a604d4a (unit socks-proxy--kernel).
  • Merge order: kernel PR, then this PR. The docs say the behavior needs "a databricks-sql-kernel release that supports SOCKS", so they stay accurate before that release. The published kernel 1.5.0 still rejects SOCKS URLs, so tests against it do not cover this behavior. Moving the [kernel] floor to that release is a separate kernel-upgrade change. KERNEL_REV is not changed here.

This pull request and its description were written by Isaac.

Once the installed databricks-sql-kernel supports SOCKS, use_kernel=True
connections honor socks4/socks4a/socks5/socks5h URLs in HTTPS_PROXY, or
in ALL_PROXY when HTTPS_PROXY is unset, with NO_PROXY bypass, through the
kernel's existing environment-proxy handling. The connector needs no code
change for this.

Record it in CONNECTION_PARAMETERS.md as a documented difference from
Thrift: the variables honored, DNS per scheme (socks5/socks4 resolve
locally, socks5h/socks4a at the proxy), credentials as URL userinfo,
fail-closed behavior, and that Thrift raises ProxySchemeUnknown for a
SOCKS HTTPS_PROXY and ignores ALL_PROXY.

Signed-off-by: Cathleen Yan <58714163+cathleeny@users.noreply.github.com>
Co-authored-by: Isaac <no-reply@databricks.com>

This branch was previously deployed

1 inactive deployment
azure-prod — 687029ab Deployed Nov 30, 2026 by cathleeny via test-with-coverage #1407
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.

1 participant