Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

## Unreleased

- Kernel backend: `authType: 'custom'`, `'token-provider'` and `'external-token'` now work, including `enableTokenFederation`; the deprecated second-argument provider also takes precedence over `authType`.
Comment thread
cathleeny marked this conversation as resolved.
Resolved
- Preserve wide negative DECIMAL values exactly with `preserveBigNumericPrecision: true`, including nested arrays and structs, on both backends. The default number conversion is unchanged.
- 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`.
- Release completed Thrift CloudFetch body-reader listeners so idle connections do not retain downloaded result buffers.
Expand Down
18 changes: 9 additions & 9 deletions CONNECTION_PARAMETERS.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,21 +58,21 @@ Per-statement `useCloudFetch` overrides remain unsupported on the kernel backend
| Option | Type | Thrift | Kernel | Default Value | Note |
| --------------------------------------------- | ------------------------------------------------------------ | :----: | :----: | ----------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `authType` — common modes | `'access-token'` \| `'databricks-oauth'` \| `'static-token'` | ✅ | ✅ | `'access-token'` | `access-token` uses `token`; `static-token` uses `staticToken`. OAuth supports U2M and M2M, with the Kernel qualifications below. |
| `authType` — Thrift-only modes | `'custom'` \| `'token-provider'` \| `'external-token'` | ✅ | ❌ | — | Kernel rejects these auth modes. |
| `authType` — provider modes | `'custom'` \| `'token-provider'` \| `'external-token'` | ✅ | ✅ | — | Kernel calls the provider for the headers of every request, retries included. Kernel ignores a provider `User-Agent` and fails the request on a CR, LF or NUL in a header value. |
| `token` | `string` | ✅ | ✅ | required for `access-token` | Thrift sends the PAT as a Bearer token (`Authorization: Bearer <token>`); Kernel uses native PAT auth. Kernel rejects blank/reserved values client-side. |
| `staticToken` | `string` | ✅ | ✅ | required for `static-token` | Thrift optionally wraps it in federation. Kernel uses native bearer-token auth with federation always enabled. |
| `provider` | `IAuthentication` | ✅ | ❌ | required for `custom` | Custom Thrift authentication provider. |
| `tokenProvider` | `ITokenProvider` | ✅ | ❌ | required for `token-provider` | Thrift wraps it with caching and optional federation. |
| `getToken` | `TokenCallback` | ✅ | ❌ | required for `external-token` | Callback used by the Thrift external-token provider. |
| `provider` | `IAuthentication` | ✅ | ✅ | required for `custom` | Custom authentication provider. Thrift calls `authenticate()` per RPC; Kernel calls it per HTTP request. |
| `tokenProvider` | `ITokenProvider` | ✅ | ✅ | required for `token-provider` | Both backends wrap it with caching and optional federation. |
| `getToken` | `TokenCallback` | ✅ | ✅ | required for `external-token` | Callback used by the external-token provider, with the same caching and optional federation. |
| `oauthScopes` | `Array<string>` | ⚠️ | ⚠️ | flow-dependent | Honored for U2M and workspace-OIDC M2M; entries are split on whitespace and blank values use the default (M2M `all-apis`, U2M `sql offline_access`). Azure Entra-direct uses its fixed resource scope. |
| `oauthClientId` | `string` | ✅ | ✅ | flow- and cloud-dependent | In-house OAuth defaults to `databricks-sql-connector`. Thrift Entra-direct defaults to its Azure application id; Kernel Entra-direct M2M requires an explicit id. |
| `oauthClientSecret` | `string` | ✅ | ✅ | — | Presence selects M2M; absence selects U2M on both. Kernel forwards blank values for workspace-OIDC parity, but rejects them in the Azure Entra-direct arm. |
| `azureTenantId` / `useDatabricksOAuthInAzure` | `string` / `boolean` | ✅ | ⚠️ | — | Kernel ignores both for U2M. On Azure M2M, `useDatabricksOAuthInAzure: false`/omitted selects Entra-direct and `true` selects workspace OIDC; `azureTenantId` applies only to Entra-direct. |
| `persistence` | `OAuthPersistence` | ✅ | ❌ | in-memory store / — | Custom OAuth persistence hook. Kernel rejects it; use `tokenCacheEnabled` for the Kernel U2M cache. |
| `tokenCacheEnabled` | `boolean` | ❌ | ✅ | — / `false` | Kernel U2M only. Enables its encrypted on-disk refresh-token cache; it has no effect on M2M or other auth types. |
| `enableTokenFederation` | `boolean` | ✅ | ❌ | `false` / — | Thrift federation opt-in. Kernel ignores it because federation is always enabled for `static-token`. |
| `federationClientId` | `string` | ✅ | ⚠️ | — | Thrift uses it when federation is enabled for token-provider, external-token, or static-token auth. Kernel honors it only for `static-token`; a non-empty value selects SP-wide WIF and omission selects account-wide WIF. |
| `authProvider` second argument (deprecated) | `IAuthentication` | ✅ | ❌ | — | Deprecated second argument to `DBSQLClient.connect`. It overrides Thrift authentication; Kernel ignores it and authenticates from `ConnectionOptions`. |
| `enableTokenFederation` | `boolean` | ✅ | ⚠️ | `false` / — | Federation opt-in for `token-provider`, `external-token` and (Thrift) `static-token`. Kernel ignores it for `static-token`, where federation is always enabled. |
| `federationClientId` | `string` | ✅ | ⚠️ | — | Both backends use it when federation is enabled for token-provider, external-token, or static-token auth. For Kernel's `static-token` (always federated), a non-empty value selects SP-wide and omission account-wide WIF. |
| `authProvider` second argument (deprecated) | `IAuthentication` | ✅ | ✅ | — | Deprecated second argument to `DBSQLClient.connect`. It overrides the authentication selected by `ConnectionOptions` on both backends. |

## HTTP client, proxy, and retries

Expand Down Expand Up @@ -242,8 +242,8 @@ session parameter surface.

## Main backend gaps

Thrift-only capabilities include custom/token-provider authentication, custom
OAuth persistence, SOCKS4 user IDs, authenticated/driver-buffer telemetry knobs,
Thrift-only capabilities include custom OAuth persistence, SOCKS4 user IDs,
authenticated/driver-buffer telemetry knobs,
query timeout, Direct Results `maxRows`, per-statement CloudFetch/LZ4 hints, and
volume operations.

Expand Down
2 changes: 1 addition & 1 deletion KERNEL_REV
Original file line number Diff line number Diff line change
@@ -1 +1 @@
a29235cbea9532efa5572ebff010045583a19cbe
6d6c1e4eb70e3d5bebea75b76c5b19c459d9a467
7 changes: 6 additions & 1 deletion lib/DBSQLClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -802,7 +802,12 @@ export default class DBSQLClient extends EventEmitter implements IDBSQLClient, I
// surface a misleading "backend not implemented" / partial-state error
// instead of the accurate "DBSQLClient: not connected".
try {
await backend.connect(options);
// The deprecated second argument takes precedence over authType on Thrift.
// Preserve that precedence for direct kernel connections and Reyden fallback.
const backendOptions = authProvider
? { ...options, authType: 'custom' as const, provider: authProvider }
: options;
await backend.connect(backendOptions);
} catch (err) {
// `IBackend.close()` is documented as safe on a partially-initialized
// backend; best-effort cleanup so we don't leak sockets / state.
Expand Down
78 changes: 72 additions & 6 deletions lib/kernel/KernelAuth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
// limitations under the License.

import os from 'os';
import { HeadersInit } from 'node-fetch';
import { ConnectionOptions } from '../contracts/IDBSQLClient';
import { ClientConfig } from '../contracts/IClientContext';
import { InternalConnectionOptions } from '../contracts/InternalConnectionOptions';
Expand Down Expand Up @@ -316,6 +317,12 @@ export type KernelNativeConnectionOptions = KernelSessionDefaults &
azureClientSecret: string;
azureTenantId?: string;
}
| {
hostName: string;
httpPath: string;
// Headers come from the `headerProvider` that `KernelBackend` passes to `openSession`.
authMode: 'External';
}
);

function prependSlash(str: string): string {
Expand Down Expand Up @@ -535,10 +542,8 @@ export function buildKernelHttpOptions(options: ConnectionOptions): KernelHttpOp
// Per-connection socket read timeout (ms). The public `socketTimeout`
// ConnectionOption maps onto the kernel napi `socketTimeoutMs`
// (kernel `HttpConfig::request_timeout` / reqwest `Client::timeout`).
// Only forward a POSITIVE value: `socketTimeout: 0` means "disabled / wait
// indefinitely" on the Thrift path, but forwarding `0` would make reqwest
// time out immediately, so we omit it and let the kernel keep its (large)
// default — preserving the "effectively no idle timeout" semantics.
// Only forward a POSITIVE value: `socketTimeout: 0` disables the Thrift
// timeout, while the kernel uses its default timeout for zero or omission.
if (typeof socketTimeout === 'number' && socketTimeout > 0) {
http.socketTimeoutMs = socketTimeout;
}
Expand Down Expand Up @@ -1117,9 +1122,70 @@ export function buildKernelConnectionOptions(options: ConnectionOptions): Kernel
};
}

// The kernel asks `KernelBackend`'s header provider for the headers of every
// request. That provider is the client's own `IAuthentication`, so caching and
// `enableTokenFederation` behave as on Thrift.
if (authType === 'custom' || authType === 'token-provider' || authType === 'external-token') {
return { ...base, authMode: 'External' };
}

throw new HiveDriverError(
`kernel backend: unsupported auth mode '${authType}'. ` +
"Supported modes on the kernel backend today: 'access-token' (PAT), 'static-token', and 'databricks-oauth' " +
'(M2M with oauthClientId+oauthClientSecret, or U2M with neither).',
"Supported modes on the kernel backend today: 'access-token' (PAT), 'static-token', 'databricks-oauth' " +
"(M2M with oauthClientId+oauthClientSecret, or U2M with neither), 'custom', 'token-provider' and 'external-token'.",
);
}

/**
* Convert the headers an `IAuthentication.authenticate()` returns into the napi
* `HeaderEntry` list, with the values node-fetch sends on Thrift: every
* `HeadersInit` shape is accepted, values (string arrays included) are
* stringified, and a repeated name (any case) is combined with `, ` under the
* first name seen. Unlike Thrift, which sends the literal text, `undefined` and
* `null` values are skipped. The kernel ignores the
* headers it manages itself (such as `User-Agent`) and fails the request on a
* CR, LF or NUL in a value. Values are never put in error messages.
*/
export function toKernelHeaderEntries(headers: HeadersInit): Array<{ name: string; value: string }> {
const entries: Array<{ name: string; value: string }> = [];
const byName = new Map<string, { name: string; value: string }>();
const add = (name: unknown, value: unknown) => {
if (value === undefined || value === null) {
return;
}
const text = String(value);
const key = String(name).toLowerCase();
const existing = byName.get(key);
if (existing) {
existing.value = `${existing.value}, ${text}`;
} else {
const entry = { name: String(name), value: text };
byName.set(key, entry);
entries.push(entry);
}
};

if (!headers || typeof headers !== 'object') {
return entries;
}
if (Array.isArray(headers)) {
headers.forEach((pair: unknown, index) => {
if (!Array.isArray(pair) || pair.length !== 2) {
throw new TypeError(
`Custom credentials provider returned header pair ${index} that is not a [name, value] tuple`,
);
}
add(pair[0], pair[1]);
});
} else if (typeof (headers as { forEach?: unknown }).forEach === 'function') {
// `Headers` (node-fetch or WHATWG): `forEach` yields each name once, values already combined.
(headers as { forEach(cb: (value: unknown, name: unknown) => void): void }).forEach((value, name) =>
add(name, value),
);
} else {
for (const [name, value] of Object.entries(headers)) {
add(name, value);
}
}
return entries;
}
Loading
Loading