Skip to content

feat(kernel): support credentials_provider on kernel connections - #1086

Merged
cathleeny merged 6 commits into
mainfrom
cathleeny/ddf-custom-credential-provider-python
Dec 4, 2026
Merged

cathleeny merged 6 commits into
mainfrom
cathleeny/ddf-custom-credential-provider-python

Conversation

@cathleeny

@cathleeny cathleeny commented Dec 2, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

credentials_provider now works with use_kernel=True. Until now, the kernel path raised NotSupportedError. When access_token or auth_type was also set, it silently ignored the provider. The kernel now calls the same provider chain the Thrift path builds, so caching, extra headers, identity_federation_client_id, the token exchange and its fallback all behave as they do on Thrift.

What changes

  • Same chain as Thrift: on the kernel path, credentials_provider is wrapped exactly as on Thrift (TokenFederationProvider(ExternalAuthProvider(...))) and passed to the kernel's per-request header provider.
  • Precedence: credentials_provider takes precedence over access_token and every auth_type, as on Thrift. Combining it with oauth_client_secret or oauth_jwt_key_file raises an ambiguity error instead of picking one.
  • Reyden auto-recovery: a connection rejected on Thrift (KP001) and reopened on the kernel now works for provider connections.
  • Older kernel wheels: with a kernel wheel that lacks this support, use_kernel=True raises NotSupportedError and asks for a newer wheel.
  • Docs: CONNECTION_PARAMETERS.md marks credentials_provider as supported on the kernel, plus one changelog entry.

Differences from Thrift on the kernel path:

  • A provider User-Agent is ignored, and the connector's is kept.
  • An invalid token is refused with HTTP 403 (SEA), where Thrift reports 401.
  • A header-factory error surfaces as OperationalError, where Thrift raises RequestError. Both are databricks.sql.exc.Error.

Testing

Live case (SELECT 1 on the kernel) DBSQL Reyden
Counting provider connects and queries ✅ 197 ms vs kernel PAT 187 ms ✅ 93 ms vs PAT 90 ms
With identity_federation_client_id (exchange refused, falls back) ✅ ✅ 91 ms vs PAT 92 ms
Invalid token refused, no fallback to Thrift ✅ 403 ✅ 403
Real federation exchange, GitHub OIDC (driver-test AUTH-033, Python nightly run) ✅ ✅

That run was dispatched from a temporary driver-test branch carrying PR #2423's AUTH-033 tests; AUTH-033 lands with databricks/databricks-driver-test#2423.

Unit and lint: these all pass.

  • 1,464 unit tests.
  • The suites against a real kernel wheel (5 and 6 tests).
  • 16 mock-server scenarios comparing Thrift and the kernel: refresh, headers, errors, federation, precedence, concurrency and cancel.
  • black and mypy.

Not run: Windows, macOS, and CI jobs that need a push.

Merge order

  • The kernel PR (feat(auth): custom credentials provider (AuthConfig::External) databricks-sql-kernel#527) is merged; this PR pins KERNEL_REV to the merged kernel commit 6d6c1e4.
  • The kernel and its drivers are released together. The databricks-sql-kernel floor in pyproject.toml and poetry.lock moves at that joint release, not in this PR.
  • Until that release, the currently published kernel wheel still raises NotSupportedError for credentials_provider on use_kernel=True.

This pull request and its description were written by Isaac.

On use_kernel=True the connector now builds the same provider chain as
Thrift (TokenFederationProvider wrapping ExternalAuthProvider) and passes
it to the kernel's external auth as a per-request header provider, so
header caching, token federation with identity_federation_client_id and
exchange fallback behave as on Thrift. credentials_provider takes
precedence over access_token and every auth_type (azure-sp-m2m included),
as on Thrift; paired with oauth_client_secret or oauth_jwt_key_file it is
rejected as ambiguous before any flow is chosen. The connector keeps its
HTTP client for these connections so the federation exchange works, and
an older kernel wheel without header_provider raises NotSupportedError.
KERNEL_REV pins the kernel commit that adds the header provider.

Signed-off-by: Cathleen Yan <58714163+cathleeny@users.noreply.github.com>
Co-authored-by: Isaac <no-reply@databricks.com>
@cathleeny
cathleeny marked this pull request as ready for review December 3, 2026 00:51

@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 High · 1 Low

Looks good, with one low test-coverage concern. Routing, precedence, the Session provider chain, the Reyden recovery path and keeping the http_client all match Thrift. A live token-federation exchange is still untested, as the PR says.

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

  • 🟠 High — Disputed by the cross-check judge (it quotes raise NotSupportedError( "credentials_provider requires a newer databricks-sql-kernel " "wheel that accepts a header provider."); a human should decide. Original finding: The declared kernel dependency still permits 1.5.0, which lacks header_provider, so a supported installation can reject this new feature and provider-based Reyden recovery despite the source revision bump. Before merging, complete the stated release dependency by raising the kernel floor to the first supporting release and updating poetry.lock and KERNEL_REV. (Found by GPT-6.1 Sol · disputed by the judge)

Comment thread tests/unit/test_kernel_client.py Resolved
@cathleeny

Copy link
Copy Markdown
Collaborator Author

On the review-bot High about the databricks-sql-kernel floor: agreed that 1.5.0 is still allowed and lacks header_provider. Until a release has it, a kernel connection with credentials_provider raises NotSupportedError asking for a newer wheel, so it fails clearly rather than silently. This is a release-ordering dependency, not something this PR can fix on its own. The merge order is: databricks/databricks-sql-kernel#527 first, then a kernel release (PyPI wheel), then a follow-up on this PR that bumps the pins to that release before it merges. That bump raises the floor in pyproject.toml/poetry.lock and re-pins KERNEL_REV.

Automated reply from the driver feature factory (Isaac). Not reviewed by a human.

Resolves the KERNEL_REV conflict with the SOCKS docs change by pinning kernel 159a2ff (databricks/databricks-sql-kernel#527), which includes both SOCKS and the external header provider.

Signed-off-by: Cathleen Yan <58714163+cathleeny@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

Looks good, with 1 low concern. Routing, precedence, the ambiguity guards, the old-wheel gating and Reyden recovery all match the Thrift chain. One gap: no connect()-level test checks that a kernel connection with credentials_provider builds the HTTP client the token exchange needs.

This overview is Claude Opus 5.5's initial take; some of its points were set aside by the cross-check judge — see the findings below.

🔀 1 finding considered and dismissed by the judge
  • 🟡 Medium src/databricks/sql/backend/kernel/client.py:483 — The locked kernel remains 1.5.0, which lacks header-provider support, so installing the currently packaged dependency still rejects the newly supported credenti
    Judge's evidence: raise NotSupportedError( "credentials_provider requires a newer databricks-sql-kernel " "wheel that accepts a header pro…

Comment thread src/databricks/sql/client.py Resolved
The old-kernel test's fake Session lacked enable_geospatial_support, so
the geospatial guard raised a NotSupportedError with the same
"newer databricks-sql-kernel" text before the header_provider guard
could be checked. Removing the header_provider guard left the test
passing. Add the kwarg to the fake and match on the
"credentials_provider requires a newer databricks-sql-kernel" message.

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

Copy link
Copy Markdown
Collaborator Author

Release-gated and expected; no change in this round. Review 6161786736 (the disputed High) and review 6162310109 (the dismissed Medium on the same pin) both raise the kernel floor, poetry.lock and KERNEL_REV finding. It needs a kernel release that includes header_provider, so it cannot land on this PR first. The merge order is unchanged from the earlier reply on this PR (#1086 (comment)): databricks/databricks-sql-kernel#527 merges first, then the kernel and bindings releases, then the pin bump on this PR.

Review 6162310109's Low (connect-level HTTP-client test) is the same item as the inline comment: not pushed in this round as a test-coverage Low. The inline Low from the same review (tests/unit/test_kernel_client.py) is fixed in 1b20932.

Automated reply from the driver feature factory (Isaac). Not reviewed by a human.

@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: 2 Low · 1 Nit

Looks good: 1 medium and 1 low concern. The kernel routing, the old-wheel gate, and the per-connection lock around the shared federation state are sound and match Thrift. Shipping this still needs a released kernel wheel and a raised dependency floor, as the PR description says.

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 — Kernel connections that pass both credentials_provider and access_token or auth_type='azure-sp-m2m' now use the provider, which changes behavior, and the changelog doesn't say so. Add a note about the new precedence to the entry. (Found by Claude Opus 5.5 · confirmed by the judge)

Comment thread src/databricks/sql/client.py Resolved
@cathleeny

Copy link
Copy Markdown
Collaborator Author

Acknowledged as a changelog Nit; no code change under the bot-loop rule. Accepted decision D8 intentionally makes kernel precedence match Thrift (src/databricks/sql/auth/auth.py:18-19). CONNECTION_PARAMETERS.md:96 and this PR description's Precedence bullet already state that credentials_provider wins over access_token and auth_type. The changelog entry uses its two user-facing sentences for the new support and required kernel release; detailed precedence stays in the docs and PR body, per the accepted changelog decision.

Automated reply from the driver feature factory (Isaac). Not reviewed by a human.

@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. Routing credentials_provider through the same TokenFederationProvider(ExternalAuthProvider(...)) chain as Thrift, with Thrift's precedence, looks right. I left two optional inline notes.

One description fix: the testing table lists "Real federation exchange, GitHub OIDC (driver-test AUTH-033 in CI)" as passing. AUTH-033 isn't on databricks-driver-test main yet, and databricks/databricks-driver-test#2423 shows no CI checks at its current head, so I couldn't find that run. Could you link it, or mark the row as pending #2423?

Comment thread tests/unit/test_kernel_auth_bridge.py Resolved
Replace the sleep-based overlap test with the event-based version from
review: the first add_headers call blocks on a release event, so the
second call provably cannot enter while the first is in flight — the
test now fails deterministically without the serialization lock
instead of only almost-always.

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

Copy link
Copy Markdown
Collaborator Author

Thanks @aakash-saravanan-db. All three points addressed:

  • AUTH-033 run link: the testing table now links the Python nightly run — it was dispatched from a temporary driver-test branch carrying PR #2423's AUTH-033 tests; AUTH-033 lands with databricks/databricks-driver-test#2423.
  • Old-kernel-wheel check (client.py): keeping it for now — the databricks-sql-kernel floor can't move until kernel#527 is merged and released, and until then a supported install can still resolve an older wheel. It matches the existing port / max_connections checks and will be dropped in the same release-gated commit that raises the floor.
  • Lock test determinism: replaced with your event-based version in 84d527b; verified it fails deterministically with the lock removed and passes with it.

This comment was written by Isaac.

@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 good, with one low-severity test gap. Routing, the precedence and ambiguity checks, and the gate for older kernel wheels all match Thrift's get_auth_provider. Merge is still blocked on a released kernel wheel plus the KERNEL_REV and dependency-floor bumps, which the PR description already lists.

Comment thread src/databricks/sql/client.py Resolved
Add test_kernel_credentials_provider_keeps_python_http_client: on
use_kernel=True with a credentials_provider the connector still builds
a UnifiedHttpClient and hands it to the session, the federation-
wrapped provider chain and the kernel, as on Thrift. Verified the test
fails with the gate removed (TokenFederationProvider raises on
http_client=None). The no-provider control case is covered by
test_kernel_http_client_lifecycle[explicit].

Co-authored-by: Isaac <no-reply@databricks.com>
Signed-off-by: Cathleen Yan <58714163+cathleeny@users.noreply.github.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).

✅ No issues identified.

🔀 2 findings considered and dismissed by the judge
  • 🔵 Low src/databricks/sql/backend/kernel/auth_bridge.py:176 — The lock is held for the whole add_headers call, which includes the user's header factory and any federation token exchange. A provider whose headers aren't c
    Judge's evidence: The kernel calls it on every authenticated request, possibly from several kernel threads at once, so calls are serialize…
  • 🟡 Medium src/databricks/sql/backend/kernel/client.py:483 — The dependency floor still permits kernel 1.5.0 and the lockfile selects it, so locked installations reject every connection using the newly supported provider
    Judge's evidence: raise NotSupportedError( "credentials_provider requires a newer databricks-sql-kernel " "wheel that accepts a header pro…

KERNEL_REV moves from the #527 branch head 159a2ff to the commit
merged into kernel main, 6d6c1e4. That picks up the external-auth
conflict guard (Session rejects credential/OAuth/JWT/Azure/
federation/token-cache kwargs alongside auth_type="external"),
async-only external auth in the kernel core, reserved SEA
per-request routing headers, and the Volume and LZ4 config changes
that landed on kernel main in between. The connector passes only
auth_type="external" plus header_provider on the provider path, so
no connector change is needed.

Verified against the wheel built from 6d6c1e4: the full unit suite
(1465 passed), the real-kernel session (5) and async-reader (6)
suites, black and mypy.

Also drops the kernel-release sentence from the changelog entry; the
kernel floor and lockfile move at the joint kernel and driver
release, not here.

Co-authored-by: Isaac <no-reply@databricks.com>
Signed-off-by: Cathleen Yan <58714163+cathleeny@users.noreply.github.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

Looks good, with one low concern. Routing works end to end: session.py builds the provider chain, auth_options forwards the provider, the bridge gives it precedence, the old-wheel check is in place, and Reyden recovery reuses the Thrift http_client.

Comment thread CHANGELOG.md Resolved
@cathleeny
cathleeny added this pull request to the merge queue Dec 4, 2026
Merged via the queue into main with commit 31b3ba4 Dec 4, 2026
56 checks passed

This branch was previously deployed

1 inactive deployment
azure-prod — d2fe5c67 Deployed Dec 3, 2026 by cathleeny via followup #2899
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