Skip to content

Commit d20691d

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 (a10f22e) 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 26a32d3 commit d20691d

5 files changed

Lines changed: 52 additions & 8 deletions

File tree

‎CHANGELOG.md‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
- Kernel backend: `port` is passed to the kernel as is, so a custom port works over HTTPS as on Thrift. IPv6 hosts need brackets, an invalid port or host fails with a `ParameterError`, and the published `@databricks/databricks-sql-kernel-*` native packages must be bumped to a release that includes databricks/databricks-sql-kernel#505, since older packages ignore `port`.
66
- Release completed Thrift CloudFetch body-reader listeners so idle connections do not retain downloaded result buffers.
7+
- Kernel backend: support SOCKS proxies through the `proxy` option.
78

89
## 3.1.0
910

‎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-
3b691d2a2c235ef847d61b308c31604979830994
1+
a10f22ea3fd41b599a12c869fd5a3f48736f124c

‎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
@@ -820,18 +820,19 @@ export function buildKernelTelemetryOptions(
820820
* credentials); `auth.{username,password}` are forwarded as separate
821821
* basic-auth fields (the kernel applies them via reqwest `Proxy::basic_auth`),
822822
* avoiding any URL percent-encoding footgun. The `noProxy` host list (a driver
823-
* option, not on the published `.d.ts`) is forwarded as `bypassHosts`. The
824-
* kernel accepts only `http://` / `https://`; a SOCKS protocol surfaces a clear
825-
* kernel error at connect (reqwest SOCKS support is not compiled in).
823+
* option, not on the published `.d.ts`) is forwarded as `bypassHosts`.
824+
* `socks` becomes `socks5h` (proxy-side DNS, as on Thrift); the kernel
825+
* rejects bare `socks://`. Other protocols pass through verbatim.
826826
*/
827827
export function buildKernelProxyOptions(options: ConnectionOptions): KernelProxyOptions {
828828
const { proxy } = options;
829829
if (!proxy) {
830830
return {};
831831
}
832832
const { noProxy } = options as ConnectionOptions & { noProxy?: string };
833+
const protocol = proxy.protocol === 'socks' ? 'socks5h' : proxy.protocol;
833834
const out: NonNullable<KernelProxyOptions['proxy']> = {
834-
url: `${proxy.protocol}://${proxy.host}:${proxy.port}`,
835+
url: `${protocol}://${proxy.host}:${proxy.port}`,
835836
};
836837
if (proxy.auth?.username !== undefined) out.username = proxy.auth.username;
837838
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';
@@ -416,6 +417,47 @@ describe('KernelAuth HTTP options (buildKernelHttpOptions)', () => {
416417
});
417418
});
418419

420+
describe('KernelAuth proxy options (buildKernelProxyOptions)', () => {
421+
const proxyUrl = (protocol: string) =>
422+
buildKernelProxyOptions(opts({ proxy: { protocol, host: 'proxy.example', port: 1080 } })).proxy?.url;
423+
424+
// `socks` resolves at the proxy on Thrift (socks-proxy-agent), so it maps to
425+
// `socks5h`; every other protocol keeps its own DNS mode.
426+
const cases: Array<[string, string]> = [
427+
['http', 'http://proxy.example:1080'],
428+
['https', 'https://proxy.example:1080'],
429+
['socks', 'socks5h://proxy.example:1080'],
430+
['socks4', 'socks4://proxy.example:1080'],
431+
['socks4a', 'socks4a://proxy.example:1080'],
432+
['socks5', 'socks5://proxy.example:1080'],
433+
['socks5h', 'socks5h://proxy.example:1080'],
434+
];
435+
for (const [protocol, url] of cases) {
436+
it(`maps protocol '${protocol}' to ${url}`, () => {
437+
expect(proxyUrl(protocol)).to.equal(url);
438+
});
439+
}
440+
441+
it('is empty without a proxy', () => {
442+
expect(buildKernelProxyOptions(opts({}))).to.deep.equal({});
443+
});
444+
445+
it('forwards credentials verbatim as separate fields, never in the URL', () => {
446+
const auth = { username: 'u@:/#?', password: 'p@:/#?' };
447+
const options = opts({ proxy: { protocol: 'socks', host: 'proxy.example', port: 1080, auth } });
448+
expect(buildKernelProxyOptions(options)).to.deep.equal({
449+
proxy: { url: 'socks5h://proxy.example:1080', username: auth.username, password: auth.password },
450+
});
451+
});
452+
453+
it('forwards noProxy as bypassHosts and folds into the full connection options', () => {
454+
const native = buildKernelConnectionOptions(
455+
opts({ proxy: { protocol: 'socks5', host: 'proxy.example', port: 1080 }, noProxy: 'h.databricks.com' }),
456+
);
457+
expect(native.proxy).to.deep.equal({ url: 'socks5://proxy.example:1080', bypassHosts: 'h.databricks.com' });
458+
});
459+
});
460+
419461
describe('KernelAuth retry options — buildKernelRetryOptions', () => {
420462
// The driver's ClientConfig retry defaults (ms / total-attempt count).
421463
const defaults = {

0 commit comments

Comments
 (0)