Skip to content

Commit 0c4d22b

Browse files
cathleenyIsaac
andcommitted
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 the kernel SOCKS change (316a75a) so kernel-e2e builds the binding that supports it. The published 1.5.0 binding still rejects SOCKS URLs, so the kernel release and package pin must land first. 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 <no-reply@databricks.com> Signed-off-by: Cathleen Yan <58714163+cathleeny@users.noreply.github.com>
1 parent abedbbf commit 0c4d22b

5 files changed

Lines changed: 55 additions & 8 deletions

File tree

‎CHANGELOG.md‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# Release History
22

3+
## Unreleased
4+
5+
- Kernel backend: support SOCKS proxies through the `proxy` option.
6+
37
## 3.1.0
48

59
- Upgrade to [kernel 1.5.0](https://github.com/databricks/databricks-sql-kernel/releases/tag/v1.5.0): fix CloudFetch pagination, ordering and cancellation, paged inline Arrow results with CloudFetch disabled, and affected-row counts.

‎CONNECTION_PARAMETERS.md‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ Per-statement `useCloudFetch` overrides remain unsupported on the kernel backend
7979
| Option | Type | Thrift | Kernel | Default Value | Note |
8080
| --------------------------- | ------------------------ | :----: | :----: | ------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
8181
| `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. |
82-
| `proxy` | `ProxyOptions` | ✅ | ⚠️ | — | `{protocol, host, port, auth}`. Kernel supports HTTP/HTTPS proxies only; Thrift also supports the declared SOCKS variants. |
82+
| `proxy` | `ProxyOptions` | ✅ | ✅ | — | `{protocol, host, port, auth}`. Kernel maps `socks` to `socks5h` (DNS at the proxy, as on Thrift). Without `proxy`, Kernel honors `HTTPS_PROXY`, `ALL_PROXY` and `NO_PROXY`, including SOCKS URLs; Thrift ignores them. |
8383
| `noProxy` (internal) | `string` | ❌ | ⚠️ | — | Runtime-only Kernel bypass list, forwarded as `bypassHosts` only when an explicit `proxy` is also supplied. |
8484
| `customHeaders` | `Record<string, string>` | ✅ | ✅ | — | 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`. |
8585
| `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.
243243
## Main backend gaps
244244

245245
Thrift-only capabilities include custom/token-provider authentication, custom
246-
OAuth persistence, SOCKS proxies, authenticated/driver-buffer telemetry knobs,
246+
OAuth persistence, authenticated/driver-buffer telemetry knobs,
247247
query timeout, Direct Results `maxRows`, per-statement CloudFetch/LZ4 hints, and
248248
volume operations.
249249

‎KERNEL_REV‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
5c3a909771f749174567af074bfe18c24a335f5c
1+
316a75a3f1606c85c05d641c437f302dcc4219e8

‎lib/kernel/KernelAuth.ts‎

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -243,7 +243,7 @@ export interface KernelHttpOptions {
243243
}
244244

245245
/**
246-
* HTTP(S) proxy forwarded to the napi binding's `ConnectionOptions.proxy`
246+
* HTTP(S) or SOCKS proxy forwarded to the napi binding's `ConnectionOptions.proxy`
247247
* (kernel `ProxyConfig`). The public `ConnectionOptions.proxy` is the
248248
* Thrift-shaped `{protocol, host, port, auth}`; `buildKernelProxyOptions`
249249
* maps it onto the kernel's structured proxy input — `url` composed from
@@ -811,18 +811,19 @@ export function buildKernelTelemetryOptions(
811811
* credentials); `auth.{username,password}` are forwarded as separate
812812
* basic-auth fields (the kernel applies them via reqwest `Proxy::basic_auth`),
813813
* avoiding any URL percent-encoding footgun. The `noProxy` host list (a driver
814-
* option, not on the published `.d.ts`) is forwarded as `bypassHosts`. The
815-
* kernel accepts only `http://` / `https://`; a SOCKS protocol surfaces a clear
816-
* kernel error at connect (reqwest SOCKS support is not compiled in).
814+
* option, not on the published `.d.ts`) is forwarded as `bypassHosts`.
815+
* `socks` becomes `socks5h` (proxy-side DNS, as on Thrift); the kernel
816+
* rejects bare `socks://`. Other protocols pass through verbatim.
817817
*/
818818
export function buildKernelProxyOptions(options: ConnectionOptions): KernelProxyOptions {
819819
const { proxy } = options;
820820
if (!proxy) {
821821
return {};
822822
}
823823
const { noProxy } = options as ConnectionOptions & { noProxy?: string };
824+
const protocol = proxy.protocol === 'socks' ? 'socks5h' : proxy.protocol;
824825
const out: NonNullable<KernelProxyOptions['proxy']> = {
825-
url: `${proxy.protocol}://${proxy.host}:${proxy.port}`,
826+
url: `${protocol}://${proxy.host}:${proxy.port}`,
826827
};
827828
if (proxy.auth?.username !== undefined) out.username = proxy.auth.username;
828829
if (proxy.auth?.password !== undefined) out.password = proxy.auth.password;

‎tests/unit/kernel/connectionOptions.test.ts‎

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import {
1818
buildKernelTlsOptions,
1919
buildKernelHttpOptions,
2020
buildKernelRetryOptions,
21+
buildKernelProxyOptions,
2122
} from '../../../lib/kernel/KernelAuth';
2223
import { ConnectionOptions } from '../../../lib/contracts/IDBSQLClient';
2324
import HiveDriverError from '../../../lib/errors/HiveDriverError';
@@ -443,6 +444,47 @@ describe('KernelAuth HTTP options (buildKernelHttpOptions)', () => {
443444
});
444445
});
445446

447+
describe('KernelAuth proxy options (buildKernelProxyOptions)', () => {
448+
const proxyUrl = (protocol: string) =>
449+
buildKernelProxyOptions(opts({ proxy: { protocol, host: 'proxy.example', port: 1080 } })).proxy?.url;
450+
451+
// `socks` resolves at the proxy on Thrift (socks-proxy-agent), so it maps to
452+
// `socks5h`; every other protocol keeps its own DNS mode.
453+
const cases: Array<[string, string]> = [
454+
['http', 'http://proxy.example:1080'],
455+
['https', 'https://proxy.example:1080'],
456+
['socks', 'socks5h://proxy.example:1080'],
457+
['socks4', 'socks4://proxy.example:1080'],
458+
['socks4a', 'socks4a://proxy.example:1080'],
459+
['socks5', 'socks5://proxy.example:1080'],
460+
['socks5h', 'socks5h://proxy.example:1080'],
461+
];
462+
for (const [protocol, url] of cases) {
463+
it(`maps protocol '${protocol}' to ${url}`, () => {
464+
expect(proxyUrl(protocol)).to.equal(url);
465+
});
466+
}
467+
468+
it('is empty without a proxy', () => {
469+
expect(buildKernelProxyOptions(opts({}))).to.deep.equal({});
470+
});
471+
472+
it('forwards credentials verbatim as separate fields, never in the URL', () => {
473+
const auth = { username: 'u@:/#?', password: 'p@:/#?' };
474+
const options = opts({ proxy: { protocol: 'socks', host: 'proxy.example', port: 1080, auth } });
475+
expect(buildKernelProxyOptions(options)).to.deep.equal({
476+
proxy: { url: 'socks5h://proxy.example:1080', username: auth.username, password: auth.password },
477+
});
478+
});
479+
480+
it('forwards noProxy as bypassHosts and folds into the full connection options', () => {
481+
const native = buildKernelConnectionOptions(
482+
opts({ proxy: { protocol: 'socks5', host: 'proxy.example', port: 1080 }, noProxy: 'h.databricks.com' }),
483+
);
484+
expect(native.proxy).to.deep.equal({ url: 'socks5://proxy.example:1080', bypassHosts: 'h.databricks.com' });
485+
});
486+
});
487+
446488
describe('KernelAuth retry options — buildKernelRetryOptions', () => {
447489
// The driver's ClientConfig retry defaults (ms / total-attempt count).
448490
const defaults = {

0 commit comments

Comments
 (0)