Skip to content
Closed
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
11 changes: 11 additions & 0 deletions NEXT_CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,17 @@ changes go in their respective binding's NEXT_CHANGELOG.
value is ignored (default preserved) with a warning rather than failing session
creation. The key is client-only — it is consumed before session creation and never
reaches the SEA wire. Benefits ODBC too.
- Auth: mandatory OIDC token exchange (BYOT federation) — when an authenticated
token was issued by a party other than the target workspace (Azure AD, an external
IdP, a Bring-Your-Own-Token, or a Workload Identity Federation token), the kernel
now exchanges it for an in-house Databricks token at `<host>/oidc/v1/token` before
using it, transparently across PAT / M2M / U2M. Gated by the token's `iss` claim
(non-JWT and same-host tokens pass through with no HTTP call) and falls back to the
original token if the exchange fails, so existing flows are unaffected. New optional
`SessionConfig::identity_federation_client_id` (and matching
`SessionBuilder::identity_federation_client_id`) selects SP-wide WIF; unset means
BYOT / account-wide WIF. Follows the ADBC wire contract
(`grant_type=jwt-bearer`, `assertion`, `scope=sql`).

### Updated

Expand Down
12 changes: 12 additions & 0 deletions include/databricks_kernel.h
Original file line number Diff line number Diff line change
Expand Up @@ -346,6 +346,18 @@ KernelStatusCode kernel_session_config_set_retry_config(KernelSessionConfig* con
KernelStatusCode kernel_session_config_set_ignore_transactions(KernelSessionConfig* config,
bool ignore);

/* SP-wide Workload Identity Federation client id for mandatory OIDC token
* exchange. Optional. When the authenticated token is issued by a party other
* than the target workspace, the kernel exchanges it for an in-house
* Databricks token; setting this makes that exchange send
* `identity_federation_client_id` (SP-wide WIF). Unset takes the BYOT /
* account-wide WIF path (`return_original_token_if_authenticated=true`). Not a
* feature toggle — the exchange is always attempted, gated only by the token's
* issuer. `client_id` must be non-NULL. Shared by all drivers (ODBC / Go). */
KernelStatusCode
kernel_session_config_set_identity_federation_client_id(KernelSessionConfig* config,
const char* client_id);

/* Configure the on-disk OAuth token cache for U2M (browser) auth. Mirrors
* the EnableTokenCache / TokenCachePassPhrase pair exposed by the reference
* ODBC driver and JDBC.
Expand Down
7 changes: 7 additions & 0 deletions napi/NEXT_CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,13 @@ layout, or npm publishing. Pure-kernel changes go in the root

### Added

- `ConnectionOptions`: new optional `identityFederationClientId` field — selects
SP-wide Workload Identity Federation for mandatory OIDC token exchange. When the
authenticated token is issued by a party other than the target workspace, the
kernel exchanges it for an in-house Databricks token, sending this client id.
Omit for BYOT / account-wide WIF. Not a feature toggle — the exchange is always
attempted, gated only by the token's issuer.

### Updated

### Fixed
Expand Down
10 changes: 10 additions & 0 deletions napi/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,16 @@ export interface ConnectionOptions {
* (`["all-apis"]` for M2M; `["all-apis", "offline_access"]` for U2M).
*/
oauthScopes?: Array<string>
/**
* SP-wide Workload Identity Federation client id for mandatory OIDC
* token exchange. Optional. When the authenticated token is issued by
* a party other than the target workspace, the kernel exchanges it for
* an in-house Databricks token; setting this sends
* `identity_federation_client_id` (SP-wide WIF). Omitted ⇒ BYOT /
* account-wide WIF. Not a feature toggle — the exchange is always
* attempted, gated only by the token's issuer.
*/
identityFederationClientId?: string
/**
* Default catalog for statements executed on this session.
* Routed through the kernel's `DefaultOpts` and onto the SEA
Expand Down
32 changes: 32 additions & 0 deletions napi/src/database.rs
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,15 @@ pub struct ConnectionOptions {
/// OAuth scopes override (M2M / U2M). Omitted ⇒ kernel defaults
/// (`["all-apis"]` for M2M; `["all-apis", "offline_access"]` for U2M).
pub oauth_scopes: Option<Vec<String>>,
/// SP-wide Workload Identity Federation client id for mandatory OIDC
/// token exchange. Optional. When the authenticated token is issued by
/// a party other than the target workspace, the kernel exchanges it for
/// an in-house Databricks token; setting this sends
/// `identity_federation_client_id` (SP-wide WIF). Omitted ⇒ BYOT /
/// account-wide WIF. Not a feature toggle — the exchange is always
/// attempted, gated only by the token's issuer. Maps onto the kernel
/// [`SessionBuilder::identity_federation_client_id`].
pub identity_federation_client_id: Option<String>,
/// Default catalog for statements executed on this session.
/// Routed through the kernel's `DefaultOpts` and onto the SEA
/// `CreateSession.catalog` wire field.
Expand Down Expand Up @@ -544,6 +553,11 @@ pub async fn open_session(mut options: ConnectionOptions) -> napi::Result<Connec
let mut builder = Session::builder()
.http_path(options.host_name, options.http_path)
.auth(auth_config);
// SP-wide WIF client id for mandatory token exchange. Unset ⇒
// BYOT / account-wide WIF (the builder default).
if let Some(client_id) = options.identity_federation_client_id {
builder = builder.identity_federation_client_id(client_id);
}
// Only wire `DefaultOpts` when at least one of catalog / schema
// was provided; otherwise leave the config's `defaults` field
// `None` so the kernel can distinguish "no defaults" from
Expand Down Expand Up @@ -616,6 +630,7 @@ mod tests {
oauth_client_secret: None,
oauth_redirect_port: None,
oauth_scopes: None,
identity_federation_client_id: None,
catalog: None,
schema: None,
session_conf: None,
Expand Down Expand Up @@ -753,6 +768,23 @@ mod tests {
assert_invalid_arg(build_auth_config(&o).unwrap_err(), "oauthClientId");
}

#[test]
fn identity_federation_client_id_is_on_the_options_boundary() {
// The SP-wide WIF selector must be reachable on the JS boundary
// struct (a regression that dropped the field would fail to compile
// this). Defaults to absent (BYOT / account-wide WIF); accepts a
// value. It is forwarded to the builder in `open_session`, which
// needs a live connection, so this asserts the boundary surface
// rather than the network path.
let mut o = base();
assert!(o.identity_federation_client_id.is_none());
o.identity_federation_client_id = Some("sp-client-abc".to_owned());
assert_eq!(
o.identity_federation_client_id.as_deref(),
Some("sp-client-abc")
);
}

#[test]
fn tls_defaults_to_secure() {
// No `check_server_certificate` ⇒ secure by default: strict chain +
Expand Down
7 changes: 7 additions & 0 deletions pyo3/NEXT_CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,13 @@ changes go in the root `NEXT_CHANGELOG.md`.

### Added

- `Session(...)`: new optional `identity_federation_client_id` keyword — selects
SP-wide Workload Identity Federation for mandatory OIDC token exchange. When
the authenticated token is issued by a party other than the target workspace,
the kernel exchanges it for an in-house Databricks token; this value is sent as
`identity_federation_client_id`. Omit for BYOT / account-wide WIF. Not a feature
toggle — the exchange is always attempted, gated only by the token's issuer.

### Updated

### Fixed
Expand Down
13 changes: 13 additions & 0 deletions pyo3/src/session.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,14 @@ impl Session {
/// OAuth is kernel-owned: the kernel acquires and transparently
/// refreshes tokens itself.
///
/// `identity_federation_client_id` is optional and enables SP-wide
/// Workload Identity Federation for mandatory OIDC token exchange:
/// when the authenticated token is issued by a party other than the
/// target workspace, the kernel exchanges it for an in-house
/// Databricks token, sending this client id. Omit it for BYOT /
/// account-wide WIF. It is not a feature toggle — the exchange is
/// always attempted, gated only by the token's issuer.
///
/// TLS: all knobs are optional relaxations / additions on top of
/// the secure default (validate system trust store, verify chain
/// + hostname). `tls_ca_cert` adds a PEM CA bundle (bytes);
Expand Down Expand Up @@ -118,6 +126,7 @@ impl Session {
token_url=None,
redirect_port=None,
oauth_callback_timeout_secs=None,
identity_federation_client_id=None,
tls_ca_cert=None,
tls_skip_verify=false,
tls_skip_hostname_verify=false,
Expand Down Expand Up @@ -147,6 +156,7 @@ impl Session {
token_url: Option<String>,
redirect_port: Option<u16>,
oauth_callback_timeout_secs: Option<u64>,
identity_federation_client_id: Option<String>,
tls_ca_cert: Option<Vec<u8>>,
tls_skip_verify: bool,
tls_skip_hostname_verify: bool,
Expand Down Expand Up @@ -288,6 +298,9 @@ impl Session {
let mut builder = KSession::builder()
.http_path(host, http_path)
.auth(auth_config);
if let Some(client_id) = identity_federation_client_id {
builder = builder.identity_federation_client_id(client_id);
}
if let Some(tls) = tls_config {
builder = builder.tls(tls);
}
Expand Down
25 changes: 25 additions & 0 deletions pyo3/tests/test_auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,3 +59,28 @@ def test_unknown_auth_type_raises_value_error():
auth_type="something-else",
access_token="x",
)


def test_identity_federation_client_id_is_accepted_kwarg():
# The SP-wide WIF selector is a recognized keyword (not a TypeError):
# paired with missing auth it reaches the pre-network auth rejection,
# which proves the signature accepts it without opening a connection.
with pytest.raises(ValueError, match="access_token"):
k.Session(
host="x.databricks.com",
http_path="/sql/1.0/warehouses/abc",
identity_federation_client_id="sp-client-abc",
)


def test_unknown_kwarg_raises_type_error():
# Guards the test above: a genuinely unknown kwarg is a TypeError, so
# the ValueError in the test above really does mean the kwarg was
# accepted by the signature.
with pytest.raises(TypeError):
k.Session(
host="x.databricks.com",
http_path="/sql/1.0/warehouses/abc",
access_token="x",
not_a_real_kwarg="nope",
)
2 changes: 1 addition & 1 deletion src/auth/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ pub mod oauth;
pub mod pat;

pub use config::{AuthConfig, AuthType};
pub use oauth::{AuthorizationCodeProvider, ClientCredentialsProvider};
pub use oauth::{AuthorizationCodeProvider, ClientCredentialsProvider, FederationProvider};
pub use pat::PersonalAccessToken;

use crate::kernel_error::Result;
Expand Down
Loading
Loading