Repository navigation
fix(kernel): honor a custom port over HTTPS on the kernel backend #636
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
d2e2169
97d67cb
a4c91da
9b2e94d
468af3a
23ffcf6
195a115
2fa5c5e
c8dc980
f4eef33
110acaf
fbffc2f
69855ec
3be0d05
2e9227d
1962201
09cb0e8
bbc4d01
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1 +1 @@ | ||
| 5c3a909771f749174567af074bfe18c24a335f5c | ||
| 22ae6ec250837b38d0e3dc720310d4dcfb81fa98 |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -269,12 +269,23 @@ export interface KernelFederationOptions { | |
| identityFederationClientId?: string; | ||
| } | ||
|
|
||
| /** | ||
| * Connection port forwarded to the napi binding's `ConnectionOptions.port`. | ||
| * The kernel folds it into the host (`fold_host_port`). Any explicit port is | ||
| * sent, 443 included; the kernel treats the scheme's default as a no-op (see | ||
| * `buildKernelPort`). | ||
| */ | ||
| export interface KernelPortOptions { | ||
| port?: number; | ||
| } | ||
|
|
||
| export type KernelNativeConnectionOptions = KernelSessionDefaults & | ||
| KernelTlsOptions & | ||
| KernelHttpOptions & | ||
| KernelTelemetryOptions & | ||
| KernelProxyOptions & | ||
| KernelFederationOptions & | ||
| KernelPortOptions & | ||
| ( | ||
| | { | ||
| hostName: string; | ||
|
|
@@ -830,20 +841,36 @@ export function buildKernelProxyOptions(options: ConnectionOptions): KernelProxy | |
| return { proxy: out }; | ||
| } | ||
|
|
||
| // The kernel prepends `https://` to a bare host but keeps an explicit scheme. | ||
| // It otherwise ignores `port`, so carry it into the URL unless `host` already has one. | ||
| function buildKernelHostName(options: ConnectionOptions): string { | ||
| if (options.https !== false) { | ||
| return options.host; | ||
| // An explicit `port` is read as Thrift reads it (`options.port || 443`): a falsy value | ||
| // (unset, null, '', 0, NaN, false) means the default. A truthy value must be a whole | ||
| // port number, and a decimal string such as `'8443'` is accepted. Anything else throws, | ||
| // as Thrift also fails on it. | ||
| function explicitPort(port: unknown): number | undefined { | ||
| if (!port) return undefined; | ||
| let value = Number.NaN; | ||
| if (typeof port === 'number') value = port; | ||
| else if (typeof port === 'string' && /^[0-9]+$/.test(port)) value = Number(port); | ||
| if (value === 0) return undefined; | ||
| if (!Number.isInteger(value) || value < 1 || value > 65535) { | ||
| throw new HiveDriverError(`kernel backend: \`port\` must be an integer between 1 and 65535; got ${String(port)}.`); | ||
| } | ||
| // The kernel accepts a full URL in `host`, so drop an existing `http://` or | ||
| // `https://` scheme before applying HTTP (`https: false` selects the scheme). | ||
| // Then strip a trailing `/` like the Thrift URL builder does. | ||
| const host = options.host.replace(/^https?:\/\//i, '').replace(/\/$/, ''); | ||
| // `name:port` or `[ipv6]:port`; a bare IPv6 literal like `::1` has no port. | ||
| const hasPort = /^(\[[^\]]+\]|[^:]+):\d+$/.test(host); | ||
| const port = options.port && !hasPort ? `:${options.port}` : ''; | ||
| return `http://${host}${port}`; | ||
| return value; | ||
| } | ||
|
|
||
| // The host is passed through as given. The kernel owns port folding, IPv6 bracketing, | ||
| // userinfo and path checks, and trailing-slash handling, and it prepends `https://` to a | ||
| // bare host. The one rewrite left here is plain HTTP: `https: false` sends an explicit | ||
| // `http://` scheme, and the kernel's scheme-based default port then applies. | ||
| function buildKernelHostName(options: ConnectionOptions): string { | ||
| if (options.https !== false) return options.host; | ||
| return `http://${options.host.replace(/^https?:\/\//i, '')}`; | ||
| } | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🟠 High — The driver no longer folds 🔀 Found by both reviewers · confirmed by the judge |
||
|
|
||
| // The port sent to the kernel, or `undefined` for the default. Any explicit port is sent as | ||
| // is: the kernel knows the effective scheme (including an `http://` already in `host`) and | ||
| // treats that scheme's default port (443 for https, 80 for http) as a no-op. | ||
| function buildKernelPort(options: ConnectionOptions): number | undefined { | ||
| return explicitPort(options.port); | ||
| } | ||
|
|
||
| export function buildKernelConnectionOptions(options: ConnectionOptions): KernelNativeConnectionOptions { | ||
|
|
@@ -858,7 +885,8 @@ export function buildKernelConnectionOptions(options: ConnectionOptions): Kernel | |
| } & KernelTlsOptions & | ||
| KernelHttpOptions & | ||
| KernelProxyOptions & | ||
| KernelFederationOptions = { | ||
| KernelFederationOptions & | ||
| KernelPortOptions = { | ||
| hostName: buildKernelHostName(options), | ||
| httpPath: prependSlash(options.path), | ||
| // Match the NodeJS Thrift driver, which surfaces INTERVAL columns as | ||
|
|
@@ -881,6 +909,12 @@ export function buildKernelConnectionOptions(options: ConnectionOptions): Kernel | |
| ...buildKernelProxyOptions(options), | ||
| }; | ||
|
|
||
| // Omitted when no port is set; any explicit port, 443 and 80 included, is sent. | ||
| const port = buildKernelPort(options); | ||
| if (port !== undefined) { | ||
| base.port = port; | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🟠 High — The driver now drops host-side port folding, but the native packages stay pinned to 1.5.0, which does not read 🔀 Found by GPT-6.1 Sol · confirmed by the judge There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🟠 High — The driver now sends 🔀 Found by both reviewers · confirmed by the judge |
||
| } | ||
|
|
||
| if (options.enableGeoSpatialSupport !== undefined) { | ||
| if (typeof options.enableGeoSpatialSupport !== 'boolean') { | ||
| throw new HiveDriverError( | ||
|
|
||
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🟠 High — With
https: falseand a custom port, the driver no longer folds the port into the host. The@databricks/databricks-sql-kernel-*packages are still pinned to 1.5.0, which ignoresport, so those connections now go to port 80. The CHANGELOG admits a follow-up bump is needed. Bump the pins together with this change, or keep folding the port forhttps: falseuntil the binding ships.🔀 Found by both reviewers · confirmed by the judge