From f6178cc6b844a425c8a34772e4681038db8fd160 Mon Sep 17 00:00:00 2001 From: Cathleen Yan <58714163+cathleeny@users.noreply.github.com> Date: Mon, 30 Nov 2026 21:44:48 +0000 Subject: [PATCH] feat(kernel): route the proxy option through SOCKS on the kernel backend With a kernel build that supports SOCKS proxies, the existing `proxy` connection option now works on the kernel backend (useKernel: true) for socks4, socks4a, socks5 and socks5h, as it already does on Thrift. buildKernelProxyOptions maps protocol 'socks' to 'socks5h', so the proxy resolves DNS as socks-proxy-agent does on Thrift. The kernel rejects a bare socks:// URL. Other protocols pass through verbatim, and credentials stay separate fields. No option is added or renamed. KERNEL_REV points at a29235c, the merged kernel SOCKS commit (databricks/databricks-sql-kernel#518), so kernel-e2e builds the binding that supports it; native/kernel/index.d.ts picks up that kernel's ProxyInput doc update. The published 1.5.0 binding still rejects SOCKS URLs, so the @databricks/databricks-sql-kernel-* package pins must move to the kernel release that includes it. The kernel does not send a SOCKS4 user ID yet, so CONNECTION_PARAMETERS.md marks kernel proxy support as partial. Table-driven unit tests cover the protocol mapping and credential and bypass forwarding. CONNECTION_PARAMETERS.md describes the kernel support, including the kernel's HTTPS_PROXY/ALL_PROXY/NO_PROXY handling when no proxy option is set (Thrift ignores those variables). CHANGELOG.md has a short entry. Co-authored-by: Isaac Signed-off-by: Cathleen Yan <58714163+cathleeny@users.noreply.github.com> --- CHANGELOG.md | 1 + CONNECTION_PARAMETERS.md | 4 +- KERNEL_REV | 2 +- lib/kernel/KernelAuth.ts | 11 +++--- native/kernel/index.d.ts | 5 ++- tests/unit/kernel/connectionOptions.test.ts | 42 +++++++++++++++++++++ 6 files changed, 55 insertions(+), 10 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 1b630444..3eaac70f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,7 @@ - Release completed Thrift CloudFetch body-reader listeners so idle connections do not retain downloaded result buffers. - **Behavior change:** Thrift `getSchema()` and `getResultMetadata().schema` return `{ columns: [] }` for statements without output columns when Arrow metadata has no fields. Check `columns.length` before indexing. `getMetadata()` and responses without Arrow metadata (including `arrowEnabled: false` and older protocols) retain the `Result STRING` placeholder. (#651) - Fix `fetchAll()` and `fetchChunk()` hanging on column-based results with an empty or missing schema. (#651) +- Kernel backend: support SOCKS proxies through the `proxy` option. ## 3.1.0 diff --git a/CONNECTION_PARAMETERS.md b/CONNECTION_PARAMETERS.md index 1c1f437e..feeed0a1 100644 --- a/CONNECTION_PARAMETERS.md +++ b/CONNECTION_PARAMETERS.md @@ -79,7 +79,7 @@ Per-statement `useCloudFetch` overrides remain unsupported on the kernel backend | Option | Type | Thrift | Kernel | Default Value | Note | | --------------------------- | ------------------------ | :----: | :----: | ------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | | `socketTimeout` | `number` (ms) | ✅ | ⚠️ | `900000` / `120000` | Kernel forwards only positive values. `0` means no timeout on Thrift but is omitted on Kernel, which then keeps its 120-second default. | -| `proxy` | `ProxyOptions` | ✅ | ⚠️ | — | `{protocol, host, port, auth}`. Kernel supports HTTP/HTTPS proxies only; Thrift also supports the declared SOCKS variants. | +| `proxy` | `ProxyOptions` | ✅ | ⚠️ | — | `{protocol, host, port, auth}`. Kernel maps `socks` to `socks5h` (DNS at the proxy, as on Thrift) and doesn't send a SOCKS4 user ID yet. Without `proxy`, it honors `HTTPS_PROXY`, `ALL_PROXY` and `NO_PROXY` (SOCKS too); Thrift ignores them. | | `noProxy` (internal) | `string` | ❌ | ⚠️ | — | Runtime-only Kernel bypass list, forwarded as `bypassHosts` only when an explicit `proxy` is also supplied. | | `customHeaders` | `Record` | ✅ | ✅ | — | Sent on workspace, telemetry and feature-flag requests, not OAuth. Workspace calls ignore caller `Authorization`, `User-Agent`, `Content-Type`, `Content-Length`, `Transfer-Encoding`, `Connection`; Kernel also ignores `x-databricks-org-id`. | | `retryMaxAttempts` | `number` | ✅ | ✅ | `5` | Total attempts, including the initial request. Kernel converts this to its retries-after-first representation internally. | @@ -243,7 +243,7 @@ session parameter surface. ## Main backend gaps Thrift-only capabilities include custom/token-provider authentication, custom -OAuth persistence, SOCKS proxies, authenticated/driver-buffer telemetry knobs, +OAuth persistence, SOCKS4 user IDs, authenticated/driver-buffer telemetry knobs, query timeout, Direct Results `maxRows`, per-statement CloudFetch/LZ4 hints, and volume operations. diff --git a/KERNEL_REV b/KERNEL_REV index 101d21c5..418c81d3 100644 --- a/KERNEL_REV +++ b/KERNEL_REV @@ -1 +1 @@ -3b691d2a2c235ef847d61b308c31604979830994 +a29235cbea9532efa5572ebff010045583a19cbe diff --git a/lib/kernel/KernelAuth.ts b/lib/kernel/KernelAuth.ts index 556b4eb5..ed990ca9 100644 --- a/lib/kernel/KernelAuth.ts +++ b/lib/kernel/KernelAuth.ts @@ -243,7 +243,7 @@ export interface KernelHttpOptions { } /** - * HTTP(S) proxy forwarded to the napi binding's `ConnectionOptions.proxy` + * HTTP(S) or SOCKS proxy forwarded to the napi binding's `ConnectionOptions.proxy` * (kernel `ProxyConfig`). The public `ConnectionOptions.proxy` is the * Thrift-shaped `{protocol, host, port, auth}`; `buildKernelProxyOptions` * maps it onto the kernel's structured proxy input — `url` composed from @@ -820,9 +820,9 @@ export function buildKernelTelemetryOptions( * credentials); `auth.{username,password}` are forwarded as separate * basic-auth fields (the kernel applies them via reqwest `Proxy::basic_auth`), * avoiding any URL percent-encoding footgun. The `noProxy` host list (a driver - * option, not on the published `.d.ts`) is forwarded as `bypassHosts`. The - * kernel accepts only `http://` / `https://`; a SOCKS protocol surfaces a clear - * kernel error at connect (reqwest SOCKS support is not compiled in). + * option, not on the published `.d.ts`) is forwarded as `bypassHosts`. + * `socks` becomes `socks5h` (proxy-side DNS, as on Thrift); the kernel + * rejects bare `socks://`. Other protocols pass through verbatim. */ export function buildKernelProxyOptions(options: ConnectionOptions): KernelProxyOptions { const { proxy } = options; @@ -830,8 +830,9 @@ export function buildKernelProxyOptions(options: ConnectionOptions): KernelProxy return {}; } const { noProxy } = options as ConnectionOptions & { noProxy?: string }; + const protocol = proxy.protocol === 'socks' ? 'socks5h' : proxy.protocol; const out: NonNullable = { - url: `${proxy.protocol}://${proxy.host}:${proxy.port}`, + url: `${protocol}://${proxy.host}:${proxy.port}`, }; if (proxy.auth?.username !== undefined) out.username = proxy.auth.username; if (proxy.auth?.password !== undefined) out.password = proxy.auth.password; diff --git a/native/kernel/index.d.ts b/native/kernel/index.d.ts index 0597773f..f4957491 100644 --- a/native/kernel/index.d.ts +++ b/native/kernel/index.d.ts @@ -1256,13 +1256,14 @@ export interface NamedTypedValueInput { export declare function openSession(options: ConnectionOptions): Promise /** - * Programmatic HTTP/HTTPS proxy configuration, mirroring the kernel's + * Programmatic HTTP/HTTPS/SOCKS proxy configuration, mirroring the kernel's * internal [`ProxyConfig`]. Supplied as a structured object rather than a * flattened URL so credentials never have to be percent-encoded into the URL * and the bypass-host list can be expressed. * * - `url` — proxy endpoint, e.g. `"http://proxy.corp.example.com:8080"`. Must - * use the `http://` or `https://` scheme. + * use the `http://`, `https://`, `socks4://`, `socks4a://`, `socks5://` or + * `socks5h://` scheme. * - `username` / `password` — optional proxy basic-auth, applied via * `reqwest`'s `Proxy::basic_auth` (not embedded in the URL). * - `bypassHosts` — optional comma-separated host/domain list that should diff --git a/tests/unit/kernel/connectionOptions.test.ts b/tests/unit/kernel/connectionOptions.test.ts index 69608636..3435aa42 100644 --- a/tests/unit/kernel/connectionOptions.test.ts +++ b/tests/unit/kernel/connectionOptions.test.ts @@ -18,6 +18,7 @@ import { buildKernelTlsOptions, buildKernelHttpOptions, buildKernelRetryOptions, + buildKernelProxyOptions, } from '../../../lib/kernel/KernelAuth'; import { ConnectionOptions } from '../../../lib/contracts/IDBSQLClient'; import HiveDriverError from '../../../lib/errors/HiveDriverError'; @@ -416,6 +417,47 @@ describe('KernelAuth HTTP options (buildKernelHttpOptions)', () => { }); }); +describe('KernelAuth proxy options (buildKernelProxyOptions)', () => { + const proxyUrl = (protocol: string) => + buildKernelProxyOptions(opts({ proxy: { protocol, host: 'proxy.example', port: 1080 } })).proxy?.url; + + // `socks` resolves at the proxy on Thrift (socks-proxy-agent), so it maps to + // `socks5h`; every other protocol keeps its own DNS mode. + const cases: Array<[string, string]> = [ + ['http', 'http://proxy.example:1080'], + ['https', 'https://proxy.example:1080'], + ['socks', 'socks5h://proxy.example:1080'], + ['socks4', 'socks4://proxy.example:1080'], + ['socks4a', 'socks4a://proxy.example:1080'], + ['socks5', 'socks5://proxy.example:1080'], + ['socks5h', 'socks5h://proxy.example:1080'], + ]; + for (const [protocol, url] of cases) { + it(`maps protocol '${protocol}' to ${url}`, () => { + expect(proxyUrl(protocol)).to.equal(url); + }); + } + + it('is empty without a proxy', () => { + expect(buildKernelProxyOptions(opts({}))).to.deep.equal({}); + }); + + it('forwards credentials verbatim as separate fields, never in the URL', () => { + const auth = { username: 'u@:/#?', password: 'p@:/#?' }; + const options = opts({ proxy: { protocol: 'socks', host: 'proxy.example', port: 1080, auth } }); + expect(buildKernelProxyOptions(options)).to.deep.equal({ + proxy: { url: 'socks5h://proxy.example:1080', username: auth.username, password: auth.password }, + }); + }); + + it('forwards noProxy as bypassHosts and folds into the full connection options', () => { + const native = buildKernelConnectionOptions( + opts({ proxy: { protocol: 'socks5', host: 'proxy.example', port: 1080 }, noProxy: 'h.databricks.com' }), + ); + expect(native.proxy).to.deep.equal({ url: 'socks5://proxy.example:1080', bypassHosts: 'h.databricks.com' }); + }); +}); + describe('KernelAuth retry options — buildKernelRetryOptions', () => { // The driver's ClientConfig retry defaults (ms / total-attempt count). const defaults = {