Skip to content
Merged
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
9 changes: 9 additions & 0 deletions .github/workflows/napi-checks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,15 @@ jobs:
# (built below) intentionally omits it and keeps link-time symbols.
run: cargo test --locked --features dyn-symbols

- uses: actions/setup-node@49933ea5288caeca8642d1e84afbd3f7d6820020 # v4.4.0
with:
node-version: '20'

- name: Test external authentication from Node
run: |
cargo build --locked
node --test tests/auth-external.test.cjs

# Drift guard for the committed loader (napi/index.js +
# napi/index.d.ts). PR #146 review feedback: nothing in CI
# detects when a contributor adds a top-level `#[napi]` symbol
Expand Down
24 changes: 22 additions & 2 deletions CONNECTION_PARAMETERS.md
Original file line number Diff line number Diff line change
Expand Up @@ -151,9 +151,29 @@ binding additionally exposes `azure-sp-m2m` via `auth_type="azure-sp-m2m"` with
the `azure_client_id` / `azure_client_secret` / `azure_tenant_id` (optional)
kwargs.

Two further variants are reserved but not usable in v0:
**`External`** — a caller-supplied credentials provider
(`Box<dyn TokenProvider>`). The kernel calls `TokenProvider::headers` once per
authenticated request, retries included, with no kernel cache; the default
returns `Authorization: Bearer <token()>`, and a provider may return extra
headers or omit `Authorization`. Its headers replace configured custom headers
of the same name (case-insensitive). Values with CR, LF or NUL fail the request,
and `User-Agent`, `Content-Type`, `Content-Length`, `Host`, `Transfer-Encoding`,
`Connection`, `Accept-Encoding`, `x-databricks-org-id` and the per-request
`x-databricks-metadata-operation-type`, `x-databricks-sea-can-run-fully-sync`,
and `x-databricks-require-thrift-native-metadata` are ignored. A provider error
fails the request with `Unauthenticated`, without a retry. External authentication
is async-only; the kernel's token-federation exchange does not run for this variant.
Bindings: pyo3
`auth_type="external"` + `header_provider` (a callable returning a
`dict[str, str]`); napi `authMode: External` + an async `headerProvider`
(second `openSession` argument) returning `HeaderEntry[]`; C ABI
`kernel_session_config_set_auth_external` with a `KernelAuthHeadersCallback`.
The Python and Node bindings reject conflicting token, OAuth, JWT, Azure,
federation and token-cache options with External authentication.

One further variant is reserved but not usable in v0:
`OAuthFederation` (RFC 8693 token exchange — returns `InvalidArgument`
until implemented) and `External` (a caller-supplied `TokenProvider`).
until implemented).

## `DefaultOpts` — session defaults (optional)

Expand Down
3 changes: 3 additions & 0 deletions NEXT_CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ changes go in their respective binding's NEXT_CHANGELOG.
if the host has credentials, a path, query or fragment.
- `ProxyConfig.url`, the Rust ADBC driver's `adbc.databricks.proxy.url`,
`HTTPS_PROXY` and `ALL_PROXY` accept SOCKS4 and SOCKS5 proxy URLs.
- Custom credentials providers: `AuthConfig::External` and the C ABI
`kernel_session_config_set_auth_external` call the caller's provider for the
auth headers of every request, so the host can refresh credentials.
- Volume `PUT`, `GET` and `REMOVE`: with `StatementSpec::volume` set, executing
a statement the server marks as a Volume operation also runs its file
transfer. Local paths, with symlinks resolved, must be inside the caller's
Expand Down
36 changes: 34 additions & 2 deletions include/databricks_kernel.h
Original file line number Diff line number Diff line change
Expand Up @@ -243,8 +243,8 @@ typedef struct kernel_result_stream_canceller_t kernel_result_stream_canceller_t
*
* Build a config, set exactly one connection form and exactly one auth
* form, then hand it to `kernel_session_open` (which consumes it). Only
* PAT, OAuth M2M, and OAuth U2M (interactive browser flow) auth are
* exposed over the C ABI.
* PAT, OAuth M2M, OAuth U2M (interactive browser flow) and a host
* credentials callback are exposed over the C ABI.
*/
KernelStatusCode kernel_session_config_new(KernelSessionConfig** out);
void kernel_session_config_free(KernelSessionConfig* config);
Expand Down Expand Up @@ -325,6 +325,38 @@ KernelStatusCode kernel_session_config_set_auth_azure_sp(KernelSessionConfig* co
const char* azure_tenant_id,
const char* azure_workspace_resource_id);

/* Host credentials callback. The kernel calls `callback` once per
* authenticated request (retries included, no kernel cache). The callback adds
* headers with kernel_auth_headers_add (usually `Authorization` plus any extra
* headers), which replace custom headers of the same name, and returns 0. Any
* other return fails that request with
* KernelStatusCode_Unauthenticated and no retry; call
* kernel_auth_headers_set_error first to give the reason (no credentials). The
* kernel copies every string before the callback returns. Values with CR, LF or
* NUL fail the request; User-Agent, Content-Type, Content-Length, Host,
* Transfer-Encoding, Connection, Accept-Encoding, x-databricks-org-id and the
* per-request x-databricks-metadata-operation-type,
* x-databricks-sea-can-run-fully-sync and
* x-databricks-require-thrift-native-metadata are ignored. The
* kernel's token-federation exchange does not run for this mode, and
* set_identity_federation_client_id does not apply to it.
*
* The callback runs on kernel threads, possibly concurrently, and must not call
* kernel entry points other than kernel_auth_headers_*. `release` (may be NULL)
* is called exactly once with `user_data` when the kernel no longer needs it:
* after the session is closed and dropped, when the config is freed without
* opening, or when a later set_auth_* call replaces this one. */
typedef struct KernelAuthHeaders KernelAuthHeaders;
typedef int32_t (*KernelAuthHeadersCallback)(void* user_data, KernelAuthHeaders* headers);
typedef void (*KernelAuthReleaseCallback)(void* user_data);
KernelStatusCode kernel_session_config_set_auth_external(KernelSessionConfig* config,
KernelAuthHeadersCallback callback,
KernelAuthReleaseCallback release,
void* user_data);
KernelStatusCode kernel_auth_headers_add(KernelAuthHeaders* headers, const char* name,
const char* value);
KernelStatusCode kernel_auth_headers_set_error(KernelAuthHeaders* headers, const char* message);

/* Optional SP-wide Workload Identity Federation client id used by mandatory
* token exchange. Unset selects BYOT / account-wide WIF. */
KernelStatusCode
Expand Down
3 changes: 3 additions & 0 deletions napi/NEXT_CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ layout, or npm publishing. Pure-kernel changes go in the root
- `ConnectionOptions.port`: an optional connection port. A value outside
`0..=65535`, or a host the kernel can't combine with the port, gives
`InvalidArgument`.
- `authMode: External` with an async `headerProvider` (the second
`openSession` argument) that returns the request headers, called for every
request. Conflicting token or OAuth options are rejected.
- `ExecuteOptions.lz4Compression` overrides Arrow result LZ4 compression per statement.
- `ExecuteOptions.volume` (`{ allowedPaths, removeNotFoundIsSuccess? }`): with
it, executing a Volume `PUT`, `GET` or `REMOVE` also runs its file transfer.
Expand Down
23 changes: 17 additions & 6 deletions napi/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -131,9 +131,8 @@ export interface NamedTypedValueInput {
* `'OAuthM2m'`, `'OAuthU2m'`, `'AzureSpM2m'`).
*
* Mirrors the kernel [`AuthConfig`] variants this binding supports.
* `OAuthFederation` / `External` are intentionally not exposed yet — the
* kernel marks federation as not-yet-implemented and `External` is a
* Rust-trait escape hatch with no JS-callback bridge.
* `OAuthFederation` is intentionally not exposed yet — the kernel marks
* federation as not-yet-implemented.
*/
export const enum AuthMode {
/** Personal access token (`token`). */
Expand All @@ -159,7 +158,12 @@ export const enum AuthMode {
* `azureWorkspaceResourceId` is set — additionally sends the SP
* management token for an RBAC-only service principal.
*/
AzureSpM2m = 'AzureSpM2m'
AzureSpM2m = 'AzureSpM2m',
/**
* Caller-supplied credentials: the `headerProvider` passed to
* `openSession`, called once per authenticated request.
*/
External = 'External'
}
/**
* A single extra HTTP header as an explicit `{ name, value }` pair.
Expand Down Expand Up @@ -241,7 +245,7 @@ export interface ConnectionOptions {
authMode?: AuthMode
/**
* Personal access token. Required (and non-empty) for
* [`AuthMode::Pat`]; ignored otherwise.
* [`AuthMode::Pat`]; rejected for [`AuthMode::External`], ignored otherwise.
*/
token?: string
/**
Expand Down Expand Up @@ -654,10 +658,17 @@ export interface ConnectionOptions {
* `options.auth_mode` (PAT / OAuth M2M / OAuth U2M) — see
* [`build_auth_config`].
*
* `headerProvider` is required for, and only allowed with, `authMode`
* `External`. It is an async function returning `HeaderEntry[]` (usually an
* `Authorization` entry plus any extra headers), called once per
* authenticated request with no caching; the kernel's token-federation
* exchange does not run for it. A rejection fails that request. Conflicting
* token, OAuth, JWT, Azure, federation or token-cache options are rejected.
*
* The JS-visible name is `openSession` (napi-rs converts snake_case
* to camelCase for free functions).
*/
export declare function openSession(options: ConnectionOptions): Promise<Connection>
export declare function openSession(options: ConnectionOptions, headerProvider?: (() => Promise<Array<HeaderEntry>>) | undefined | null): Promise<Connection>
/**
* One kernel log event, as handed to JS. `level` is a lower-case string
* (`error`/`warn`/`info`/`debug`/`trace`) the Node side maps onto its
Expand Down
Loading
Loading