Skip to content

feat(auth): custom credentials provider (AuthConfig::External) - #527

Merged
cathleeny merged 7 commits into
mainfrom
cathleeny/ddf-custom-credential-provider-kernel
Dec 3, 2026
Merged

cathleeny merged 7 commits into
mainfrom
cathleeny/ddf-custom-credential-provider-kernel

Conversation

@cathleeny

@cathleeny cathleeny commented Dec 2, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

Add AuthConfig::External so Python, Node.js and Go applications can supply credentials and extra request headers through their existing providers. The kernel requests fresh headers for each authenticated request and leaves caching and token federation to the provider.

What changes

  • Expose external authentication through pyo3, napi and the C ABI. The external request path is async-only; Python and C callbacks run on Tokio's blocking pool.
  • Provider headers replace configured custom headers with the same name, case-insensitively. Kernel-managed headers, including per-request SEA metadata-routing headers, cannot be overridden; invalid header values fail the request.
  • Provider errors fail the request without a retry. The kernel does not impose a timeout on the provider; callers that need one must enforce it in the provider. Python and Node external auth reject conflicting token or OAuth options.

Testing

Live pyo3 provider case DBSQL Reyden
Connect and query with a counting provider Passed Passed

The real GitHub OIDC federation AUTH-033 case passed in nightly workflows dispatched from a temporary driver-test branch carrying #2423 and a driver_ref input: Python, Go, and Node.js. AUTH-033 itself lands in #2423.

Local checks cover Rust, Python, Node and C bindings, including Node tests against the built native binding and a loopback server. One Rustls mTLS library test also fails on main on the test host. Windows and macOS were not run locally.

This pull request and its description were written by Isaac.

Wire the reserved AuthConfig::External as a per-request header provider so
host drivers can supply and refresh credentials through their existing
provider APIs.

- Kernel: TokenProvider gains headers() (default Authorization: Bearer
  <token()>), and HeaderProviderFn adapts a closure. The provider runs once
  per authenticated request, retries included, with no kernel cache, and is
  not wrapped by the kernel FederationProvider. The open-time preflight
  hands its headers to the first request, so it adds no extra call. Values
  with CR/LF/NUL fail the request; kernel-managed headers are ignored;
  provider errors fail fast as Unauthenticated. Auth headers replace
  same-named custom headers (case-insensitive) on SQL and feature-flag
  requests, as on Thrift. Request paths await the provider on the caller's
  runtime (AuthProvider::request_headers_async), so it can wait on that
  runtime's tasks even on a current-thread runtime.
- pyo3: Session(auth_type="external", header_provider=callable). The GIL
  wait and the call run on tokio's blocking pool. A GC-tracked owner holds
  the callable, and every handle sharing the session links to it, so
  provider cycles through any handles are collected while a reachable
  handle keeps the provider.
- napi: authMode External with an async headerProvider (second openSession
  argument) bridged through a weak ThreadsafeFunction, typed via
  ts_arg_type so the generated index.d.ts matches.
- C ABI: kernel_session_config_set_auth_external with
  kernel_auth_headers_add / kernel_auth_headers_set_error; the callback
  runs on tokio's blocking pool, strings are copied into Rust-owned memory
  and user_data is released exactly once.
- Tests: wiremock (Rust API and C ABI), C smoke test, pyo3 loopback tests.

Signed-off-by: cat23123 <58714163+cat23123@users.noreply.github.com>
Co-authored-by: Isaac <no-reply@databricks.com>
Resolves the NEXT_CHANGELOG.md conflict with the SOCKS proxy entry (#518) by keeping both entries.

Signed-off-by: cat23123 <58714163+cat23123@users.noreply.github.com>

Co-authored-by: Isaac <no-reply@databricks.com>

@oss-reviewer-bot oss-reviewer-bot Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔀 Cross-reviewed: two independent reviews (Claude Opus 5.5 · GPT-6.1 Sol), checked by a judge model (Claude Sonnet 5.5).

Verdict: 3 Low · 1 Nit

Looks good: 3 low concerns. The kernel, pyo3 and C ABI wiring is careful and well tested (primed preflight, blocking-pool callbacks, GC links, release semantics). The gaps are small: FFI panic containment, Accept-Encoding handling, and napi test coverage.

This overview is Claude Opus 5.5's initial take; GPT-6.1 Sol added findings it doesn't mention — see the findings below.

Other findings

  • ⚪ Nit — The new extern "C" entry points are not wrapped in catch_ffi, so a panic would unwind through the host's C callback frame. The body only pushes to a Vec and copies strings, so the risk is small, and the other session setters don't use catch_ffi either. Wrap the body in catch_ffi for safety. (Found by Claude Opus 5.5 · confirmed by the judge)

Comment thread src/auth/external.rs Resolved
Comment thread napi/src/database.rs Resolved
Comment thread pyo3/src/auth.rs Resolved
Signed-off-by: cat23123 <58714163+cat23123@users.noreply.github.com>
Co-authored-by: Isaac <no-reply@databricks.com>

@oss-reviewer-bot oss-reviewer-bot Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔀 Cross-reviewed: two independent reviews (Claude Opus 5.5 · GPT-6.1 Sol), checked by a judge model (Claude Sonnet 5.5).

Verdict: 1 Medium · 3 Low · 1 Nit

Looks solid overall: 1 medium and 3 low concerns. The kernel, C ABI and pyo3 paths are well tested and the GIL and runtime handling is careful; the napi bridge is the main gap in coverage.

This overview is Claude Opus 5.5's initial take; GPT-6.1 Sol added findings it doesn't mention — see the findings below.

Other findings

  • ⚪ Nit — HeaderProviderFn::token strips only the exact-case Bearer prefix, so a provider returning bearer x fails token() while headers() works. Match the scheme case-insensitively. (Found by Claude Opus 5.5 · confirmed by the judge)

Comment thread napi/src/database.rs Resolved
Comment thread src/c_abi/session.rs Resolved
Comment thread src/auth/external.rs Resolved
Comment thread pyo3/src/session.rs Resolved

@aakash-saravanan-db aakash-saravanan-db left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approving. The External provider wiring, header validation, and callback lifetimes across PyO3, N-API and the C ABI look right to me. The inline comments are optional cleanups plus one coverage note.

One description fix: the Summary's line about a real GitHub OIDC federation exchange passing from the Python and Go drivers cites "driver-test AUTH-033 in CI". I couldn't find that run. AUTH-033 isn't on databricks-driver-test main yet, and databricks/databricks-driver-test#2423 has no CI checks at its current head. Could you link the run, or reword it to say the case is pending in #2423?

Comment thread src/client/http.rs Resolved
Comment thread src/auth/external.rs Resolved
Comment thread src/feature_flags/mod.rs Resolved
Comment thread napi/src/database.rs Resolved
Signed-off-by: cat23123 <58714163+cat23123@users.noreply.github.com>
Co-authored-by: Isaac <no-reply@databricks.com>
@cathleeny

Copy link
Copy Markdown
Collaborator Author

Thanks for the review. I added the Python, Go and Node.js AUTH-033 run links and their temporary-branch provenance to the description. In 672d14e, provider headers can no longer override SEA routing headers; External is async-only; the collision tests share their fixture; and the real napi binding has loopback resolve/reject and idle-exit coverage. My earlier claim that the Node driver unit test used a real binding was incorrect; it uses a fake binding.

Signed-off-by: cat23123 <58714163+cat23123@users.noreply.github.com>
Co-authored-by: Isaac <no-reply@databricks.com>

@oss-reviewer-bot oss-reviewer-bot Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔀 Cross-reviewed: two independent reviews (Claude Opus 5.5 · GPT-6.1 Sol), checked by a judge model (Claude Sonnet 5.5).

Verdict: 1 Low · 1 Nit

Looks good, with 2 low concerns. The async-only External path, the header validation and replacement rules, and release of the C/Python callbacks are well designed and well tested at the unit, wiremock and binding tiers.

Other findings

  • ⚪ Nit — The rustdoc on kernel_session_config_set_auth_external lists only eight ignored kernel-managed headers. The C header, TokenProvider::headers and KERNEL_MANAGED_HEADERS also ignore three per-request SEA routing headers. Add those three headers to the rustdoc. (Found by Claude Opus 5.5 · confirmed by the judge)

Comment thread napi/src/database.rs Resolved
Signed-off-by: cat23123 <58714163+cat23123@users.noreply.github.com>
Co-authored-by: Isaac <no-reply@databricks.com>
@cathleeny

Copy link
Copy Markdown
Collaborator Author

Thanks for the re-review. In dc6b454, Node external auth rejects conflicting credential options, and the C callback rustdoc now lists all three kernel-managed SEA routing headers. The Node driver’s External path does not forward those conflicting options.

@oss-reviewer-bot oss-reviewer-bot Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔀 Cross-reviewed: two independent reviews (Claude Opus 5.5 · GPT-6.1 Sol), checked by a judge model (Claude Sonnet 5.5).

Verdict: 1 Low

Looks solid: 1 medium concern. External auth is wired consistently across Rust, PyO3, napi and the C ABI, with good wiremock, FFI and GC-cycle coverage; the one gap is that a hung host provider has no time limit.

Comment thread src/client/http.rs Resolved

This branch was successfully deployed

1 active deployment
azure-prod — dc6b4541 Deployed Dec 3, 2026 by cathleeny via followup #5245
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants