Repository navigation
feat(auth): U2M token-cache control on the kernel path (PECOBLR-4146) - #283
Merged
Merged
Conversation
…R-4146) Introduce a TokenPersistence trait so callers can supply a custom OAuth U2M token store (DB, keychain, in-memory) instead of the kernel's built-in encrypted disk cache. The built-in cache becomes the default impl (DiskTokenCache), so behavior is unchanged when no store is supplied. - New src/auth/oauth/persistence.rs: TokenPersistence (async load/save) + DiskTokenCache default impl wrapping the existing TokenCache. - AuthConfig::OAuthU2M gains token_store: Option<Arc<dyn TokenPersistence>>; when Some it overrides the token_cache disk policy. Threaded through the oauth_u2m constructor (bindings must use it -- AuthConfig is non_exhaustive). - AuthorizationCodeProvider swaps cache_passphrase for the store; load errors are treated as a cache miss, save errors logged and swallowed. - session.rs resolves the effective store: caller store wins, else derive DiskTokenCache from the token_cache policy. - C-ABI passes None (no callback surface; out of scope for Go). Kernel-only enabler; napi/pyo3 binding hooks follow in later commits. Co-authored-by: Isaac Signed-off-by: eric-wang-1990 <e.wang@databricks.com>
…COBLR-4146) Thread the kernel's TokenPersistence through the napi binding so a Node caller can supply a custom OAuth U2M token store (its OAuthPersistence) on the kernel path, instead of the built-in disk cache. - openSession gains two optional callbacks (oauthPersistenceRead / oauthPersistencePersist). When both are supplied, a NapiTokenStore wraps them as ThreadsafeFunctions and is installed as the U2M token_store; load/save call the JS store and await its returned Promise. The token crosses as the kernel's OAuthToken JSON (lossless, same bytes the disk cache stores) via the KernelPersistArgs object. - build_auth_config takes the resolved store and forwards it in the U2M arm. - add async-trait dep (to impl the kernel's #[async_trait] TokenPersistence). Contract regeneration note: index.js/index.d.ts are regenerated with @napi-rs/cli@3.8.2 (the version bin/build-native.sh selects for the napi 3.x crate). The committed contract was stale @napi-rs/cli v2-style output, so the diff also migrates the loader to v3 (adds NAPI_RS_ENFORCE_VERSION_CHECK, the per-package version-consistency checks, WASI fallback) — same regeneration the nodejs driver landed in #505. The persistence-specific delta is KernelPersistArgs + the two openSession params. Co-authored-by: Isaac Signed-off-by: eric-wang-1990 <e.wang@databricks.com>
…R-4146) Thread the kernel's TokenPersistence through the Python binding so a caller can supply a custom OAuth U2M token store on the kernel path. - Session(...) gains an oauth_persistence kwarg: a Python object exposing read(host)->Optional[str] / persist(host, token_json). It is wrapped as a PyTokenStore (impl TokenPersistence) that calls the object under the GIL and exchanges the kernel OAuthToken as an opaque JSON string (lossless; the same bytes the disk cache stores; consistent with the napi binding). - Carried on OAuthParams.token_store so build_auth_config's signature and its GIL-less unit-testable inner stay unchanged; the U2M arm forwards it. - add async-trait + serde_json deps. The databricks-sql-python connector adapts its experimental_oauth_persistence onto this in a follow-up (#913). Co-authored-by: Isaac Signed-off-by: eric-wang-1990 <e.wang@databricks.com>
Co-authored-by: Isaac Signed-off-by: eric-wang-1990 <e.wang@databricks.com>
…ence (PECOBLR-4146) Co-authored-by: Isaac Signed-off-by: eric-wang-1990 <e.wang@databricks.com>
eric-wang-1990
requested review from
jayantsing-db,
msrathore-db and
vikrantpuppala
August 22, 2026 02:21
eric-wang-1990
had a problem deploying
to
azure-prod
August 22, 2026 02:21 — with
GitHub Actions
Failure
eric-wang-1990
temporarily deployed
to
azure-prod
August 22, 2026 02:21 — with
GitHub Actions
Inactive
eric-wang-1990
had a problem deploying
to
azure-prod
August 22, 2026 02:21 — with
GitHub Actions
Failure
eric-wang-1990
temporarily deployed
to
azure-prod
August 22, 2026 02:21 — with
GitHub Actions
Inactive
eric-wang-1990
had a problem deploying
to
azure-prod
August 22, 2026 02:21 — with
GitHub Actions
Failure
eric-wang-1990
had a problem deploying
to
azure-prod
August 22, 2026 02:21 — with
GitHub Actions
Failure
eric-wang-1990
had a problem deploying
to
azure-prod
August 22, 2026 02:21 — with
GitHub Actions
Failure
eric-wang-1990
temporarily deployed
to
azure-prod
August 22, 2026 02:21 — with
GitHub Actions
Inactive
eric-wang-1990
had a problem deploying
to
azure-prod
August 22, 2026 02:21 — with
GitHub Actions
Failure
There was a problem hiding this comment.
Verdict: 1 Medium
Solid, well-contained feature — the kernel-side TokenPersistence trait + DiskTokenCache default preserve existing behavior, session.rs correctly resolves caller-store-wins-else-disk, and the U2M load/save rewrite keeps the prior control flow with lenient (miss-on-load-error, swallow-on-save-error) semantics as documented. One medium concern: both bindings key the caller store on host alone, dropping the client_id/scopes the kernel trait (and design doc) say form the key, which diverges from the triple-keyed disk cache. The kernel core carries unit coverage; NapiTokenStore/PyTokenStore are only exercised via connector E2E (acceptable given TSFN/GIL are hard to unit-test).
…m store post-GA PuPr ships kernel-owned persistence: the kernel owns the token lifetime + the built-in encrypted disk cache, and the caller can enable / disable / locate it via TokenCacheConfig exposed through napi/pyo3. A caller-supplied custom token store (via napi/pyo3 callback bridges) is deferred post-GA, built only when a named consumer needs a non-file sink. Records the rationale (no named customer, no prod store in the connector today, kernel disk cache already covers the common case better, no telemetry signal, the custom-store path is the untested higher-risk surface) and keeps the custom-store design + prototype status under Post-GA. NOTE: the code on this branch still carries the custom-store prototype; scoping the implementation down to the PuPr surface is the follow-up. Co-authored-by: Isaac Signed-off-by: eric-wang-1990 <e.wang@databricks.com>
… control Revert the custom-store surface (the TokenPersistence trait + napi/pyo3 callback bridges) added earlier on this branch, and ship the PuPr surface instead: expose the kernel's existing TokenCacheConfig (enable/disable + passphrase) through the napi and pyo3 bindings. - napi: openSession ConnectionOptions gains tokenCacheEnabled / tokenCachePassphrase; build_auth_config maps them to TokenCacheConfig on the U2M arm. Native contract regenerated with @napi-rs/cli@3.8.2 (also migrates the stale v2-CLI loader to v3). - pyo3: Session gains token_cache_enabled / token_cache_passphrase kwargs, carried on OAuthParams and mapped to TokenCacheConfig in the U2M arm. - Kernel core is unchanged from main (no trait, no callbacks) — TokenCacheConfig already exists; this is purely binding surface. - Caller-supplied custom stores are deferred post-GA; the prototype remains in this branch's history (see docs/designs/PECOBLR-4146-...). Unit tests added for the enable/disable/passphrase mapping in both bindings. Co-authored-by: Isaac Signed-off-by: eric-wang-1990 <e.wang@databricks.com>
eric-wang-1990
temporarily deployed
to
azure-prod
August 22, 2026 06:48 — with
GitHub Actions
Inactive
eric-wang-1990
had a problem deploying
to
azure-prod
August 22, 2026 06:48 — with
GitHub Actions
Failure
eric-wang-1990
had a problem deploying
to
azure-prod
August 22, 2026 06:48 — with
GitHub Actions
Failure
eric-wang-1990
temporarily deployed
to
azure-prod
August 22, 2026 06:48 — with
GitHub Actions
Inactive
eric-wang-1990
had a problem deploying
to
azure-prod
August 22, 2026 06:48 — with
GitHub Actions
Failure
eric-wang-1990
had a problem deploying
to
azure-prod
August 22, 2026 06:48 — with
GitHub Actions
Failure
eric-wang-1990
had a problem deploying
to
azure-prod
August 22, 2026 06:48 — with
GitHub Actions
Failure
eric-wang-1990
had a problem deploying
to
azure-prod
August 22, 2026 06:48 — with
GitHub Actions
Failure
eric-wang-1990
had a problem deploying
to
azure-prod
August 22, 2026 07:11 — with
GitHub Actions
Failure
eric-wang-1990
had a problem deploying
to
azure-prod
August 22, 2026 07:11 — with
GitHub Actions
Failure
eric-wang-1990
had a problem deploying
to
azure-prod
August 22, 2026 07:11 — with
GitHub Actions
Failure
eric-wang-1990
temporarily deployed
to
azure-prod
August 22, 2026 07:11 — with
GitHub Actions
Inactive
…PECOBLR-4146 token-cache entries alongside main v0.2.1 sections) Signed-off-by: eric-wang-1990 <e.wang@databricks.com>
The pyo3 dep enabled `extension-module` unconditionally, which tells the linker NOT to link libpython (symbols are supplied by the host interpreter at wheel load time). That is correct for the built extension but breaks the `cargo test` step in pyo3-checks.yml: the unit-test binary must link libpython, so it failed on Linux CI with a wall of undefined `Py*` symbols (PyEval_RestoreThread, PyGILState_Ensure, ...). main is currently red for the same reason. Make `extension-module` an opt-in crate feature and have maturin turn it on via [tool.maturin] features, so plain `cargo test` links libpython while the wheel build keeps the dynamic-lookup behaviour. Same fix as the in-flight #request-timeout binding PR; verified locally (22 pyo3 unit tests pass, incl. u2m_token_cache_control_maps_to_config). Signed-off-by: eric-wang-1990 <e.wang@databricks.com>
eric-wang-1990
temporarily deployed
to
azure-prod
August 25, 2026 17:54 — with
GitHub Actions
Inactive
eric-wang-1990
temporarily deployed
to
azure-prod
August 25, 2026 17:54 — with
GitHub Actions
Inactive
eric-wang-1990
temporarily deployed
to
azure-prod
August 25, 2026 17:54 — with
GitHub Actions
Inactive
eric-wang-1990
temporarily deployed
to
azure-prod
August 25, 2026 17:54 — with
GitHub Actions
Inactive
eric-wang-1990
temporarily deployed
to
azure-prod
August 25, 2026 17:54 — with
GitHub Actions
Inactive
eric-wang-1990
temporarily deployed
to
azure-prod
August 25, 2026 17:54 — with
GitHub Actions
Inactive
eric-wang-1990
temporarily deployed
to
azure-prod
August 25, 2026 17:54 — with
GitHub Actions
Inactive
eric-wang-1990
temporarily deployed
to
azure-prod
August 25, 2026 17:54 — with
GitHub Actions
Inactive
vikrantpuppala
approved these changes
Aug 25, 2026
…lve pyo3/pyproject.toml (keep extension-module comment; #288 landed the identical fix + request-timeout kwargs, auto-merged in Cargo.toml/session.rs)
eric-wang-1990
temporarily deployed
to
azure-prod
August 25, 2026 20:37 — with
GitHub Actions
Inactive
eric-wang-1990
temporarily deployed
to
azure-prod
August 25, 2026 20:37 — with
GitHub Actions
Inactive
eric-wang-1990
temporarily deployed
to
azure-prod
August 25, 2026 20:37 — with
GitHub Actions
Inactive
eric-wang-1990
temporarily deployed
to
azure-prod
August 25, 2026 20:37 — with
GitHub Actions
Inactive
eric-wang-1990
temporarily deployed
to
azure-prod
August 25, 2026 20:37 — with
GitHub Actions
Inactive
eric-wang-1990
temporarily deployed
to
azure-prod
August 25, 2026 20:37 — with
GitHub Actions
Inactive
eric-wang-1990
temporarily deployed
to
azure-prod
August 25, 2026 20:37 — with
GitHub Actions
Inactive
eric-wang-1990
temporarily deployed
to
azure-prod
August 25, 2026 20:37 — with
GitHub Actions
Inactive
This branch was previously deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What & why
Adds U2M on-disk token-cache control on the kernel path (PECOBLR-4146, PuPr scope). The kernel already owns the U2M token lifetime and, by default, persists the refresh token to an encrypted on-disk cache (
~/.config/databricks-sql-kernel/oauth/,0600, matching JDBCEnableTokenCache=1). This PR lets a caller enable/disable that cache and set its passphrase from the two bindings — the piece needed for the connectors to reconcile their own defaults (Thrift Python/Node default to no on-disk persistence) with the kernel's on-disk default.Caller-supplied custom token stores (DB/keychain/vault via a callback bridge) are deferred post-GA — see
docs/designs/PECOBLR-4146-oauth-token-persistence-design.mdfor the rationale (no named customer, the connector ships no prod store, the kernel disk cache already covers the common case better, and the callback path is the untested higher-risk surface). The custom-store design is fully worked out and prototyped in this branch's earlier commits.How
TokenCacheConfig(enable + passphrase) already exists and is reachable over the C-ABI; this PR is purely binding surface.ConnectionOptionsgainstokenCacheEnabled?: boolean/tokenCachePassphrase?: string;build_auth_configmaps them toTokenCacheConfigon the U2M arm. Omitted ⇒ kernel default; a passphrase with no flag implies enabled. Native contract regenerated with the crate-correct@napi-rs/cli@3.8.2(which also migrates the stale committed v2-CLI loader to v3 — the bulk of theindex.*diff).Session(…)gainstoken_cache_enabled/token_cache_passphrasekwargs, carried onOAuthParamsand mapped toTokenCacheConfigin the U2M arm (the GIL-lessbuild_auth_config_innerstays unit-testable).The default the connector adapters must choose
The kernel defaults on-disk; Thrift defaults in-memory / none. The connector adapters (databricks-sql-nodejs#457, databricks-sql-python#913) should consciously pick per binding — adopt the kernel/JDBC default (fewer logins; token now at rest) or disable-by-default to match Thrift's conservative posture. This PR's enable/disable knob is what makes either choice expressible.
Testing
cargo test --features dyn-symbols(81, incl. a newu2m_token_cache_control_maps_to_config) + clippy, green.--lib+--tests) green + maturin-linked build; the new mapping test runs under Linux CI (cargo testfrompyo3/).This pull request and its description were written by Isaac.