Skip to content

feat(kernel): custom authenticators and token providers on the kernel backend - #610

Open
cathleeny wants to merge 8 commits into
mainfrom
cathleeny/ddf-custom-credential-provider-go
Open

cathleeny wants to merge 8 commits into
mainfrom
cathleeny/ddf-custom-credential-provider-go

Conversation

@cathleeny

@cathleeny cathleeny commented Dec 2, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

Custom authenticators and token providers now work with the kernel backend. Previously rejected authenticators no longer return ErrNotSupportedByKernel, so callers using that error to fall back to Thrift stop doing so. Providers run on each kernel request, as on Thrift; PAT, M2M and U2M are unchanged.

What changes

  • WithAuthenticator, WithTokenProvider, WithExternalToken, WithStaticToken and WithFederatedTokenProvider[AndClientID] use the kernel's External auth callback.
  • Federated tokens refresh on each request, matching the current Thrift cadence (one exchange per request, no cache).
  • Authenticate receives a synthetic POST to the Thrift endpoint. Provider failures fail only that operation; the pooled session stays usable. A server 401 still evicts the session, while a 403 does not.
  • Differences from Thrift: provider errors fail fast; providers receive context.Background() (kernel issue #537); the kernel ignores its managed headers, including User-Agent, Accept-Encoding and SEA routing headers.

Testing

Previously run live:

Case DBSQL Reyden
All five provider options, connect and query Pass Pass
Federated fallback and invalid credentials Pass Pass
Real federation exchange (Go nightly) Pass Pass

Not run for this re-pin: live tests, Windows, macOS and arm.

Merge order

This PR pins merged kernel 6d6c1e4 with the matching header. The bindings module moves at the joint kernel and driver release.

Whichever of this PR and #616 merges second should update the federation documentation and tests: after #616, the one-exchange-per-request, no-cache wording no longer applies.

This pull request and its description were written by Isaac.

… backend

Route every authenticator that is not PAT, M2M or U2M through the kernel's
new per-request credentials callback (kernel_session_config_set_auth_external)
instead of rejecting it. This covers WithAuthenticator(custom),
WithTokenProvider, WithExternalToken, WithStaticToken and
WithFederatedTokenProvider[AndClientID].

- A cgo.Handle, held in C memory, reaches the authenticator from an exported
  trampoline. On each kernel request it calls Authenticate on a fresh POST to
  the Thrift endpoint URL and passes back every header it set. The kernel's
  release callback deletes the handle once the session or config is gone.
- Federated providers are no longer a one-time PAT snapshot taken at
  connect. The driver's own FederationProvider now runs per request, as on
  Thrift (an RFC 8693 exchange per request, no cache, fallback on refusal),
  and the kernel's own federation does not run for this mode.
- NUL bytes are rejected in Go before the C boundary. The kernel rejects CR
  and LF and ignores the headers it manages.
- An authenticator error fails the request at once with its message, and
  the session stays usable (it is local, nothing was sent). Thrift retried it
  under WithRetries.
- PAT, M2M and U2M mappings are unchanged.

KERNEL_REV moves to the kernel change that adds the setter
(fb18a18215fc11fd58e40a5451b2ce073de0abbb), and its C header is copied. The
header also carries kernel main's revocation setter declaration, which the
driver does not use.

Signed-off-by: Cathleen Yan <58714163+cathleeny@users.noreply.github.com>
Co-authored-by: Isaac <no-reply@databricks.com>
cathleeny and others added 3 commits December 2, 2026 20:23
The request URL an external authenticator sees appended cfg.Port even when
WithServerHostname already carried a port, so host "127.0.0.1:43337" became
"https://127.0.0.1:43337:443/..." and every custom provider failed to parse it.
A non-default port in the host now wins, as it does in the kernel's own
endpoint, and is not appended a second time.

Signed-off-by: Cathleen Yan <58714163+cathleeny@users.noreply.github.com>
Co-authored-by: Isaac <no-reply@databricks.com>
Signed-off-by: Cathleen Yan <58714163+cathleeny@users.noreply.github.com>
Co-authored-by: Isaac <no-reply@databricks.com>
Resolves the CHANGELOG.md conflict with the Go 1.26.11 minimum-version entry by keeping both entries.

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 · 1 Nit

Solid design with good coverage: 1 medium and 2 low concerns. The change can't merge until the bindings pin catches up with the new ABI symbols.

Other findings

  • ⚪ Nit — A Thrift connection with a custom authenticator that gets re-opened on the kernel by Reyden recovery now resolves to AuthExternal instead of failing. This is probably the intended outcome, but no test or doc covers it. Add a connector_reyden_test case that checks the kernel config gets AuthExternal with the same authenticator. (Found by Claude Opus 5.5 · confirmed by the judge)

Comment thread CHANGELOG.md Resolved
Brings in the SOCKS proxy support from HTTPS_PROXY (ba98d6e). KERNEL_REV now pins kernel 159a2ff, which contains both the SOCKS change and External auth, and the C header is copied from that commit. Both changelog entries and CONNECTION_PARAMETERS.md rows are kept.

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 High

Not ready to merge: 1 high blocker (bindings pin). The External auth bridge, handle lifetime, local provider-failure classification and request-URL construction look correct and are well tested. No driver_e2e_test.go coverage was added for the new provider paths; that could be follow-up work.

Comment thread KERNEL_REV 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.

Nice work moving every non-PAT/OAuth authenticator onto the per-request callback. The cgo handle lifetime, panic containment and pooled-session handling look right to me. I left two inline gaps against Thrift behavior that I think should be addressed (request context and error identity), plus one optional note.

Description fixes:

  • "A server 401 or 403 still evicts the connection" isn't right for 403. The kernel maps 403 to PermissionDenied, and isSessionFatal has no case for it, so a 403 leaves the connection in the pool, both before and after this PR. Suggest: "A server 401 still evicts the connection; a 403 leaves it in the pool, as before."
  • The testing table lists "Real federation exchange, GitHub OIDC (driver-test AUTH-033 in CI)". AUTH-033 isn't on databricks-driver-test main yet, and databricks/databricks-driver-test#2423 has no CI checks at its current head, so I couldn't find that run. Could you link it, or mark it pending #2423?
  • If you take the context fix inline, the "Authenticate gets context.Background()" difference can come out.

Comment thread internal/backend/kernel/auth.go Resolved
Signed-off-by: Cathleen Yan <58714163+cathleeny@users.noreply.github.com>
Co-authored-by: Isaac <no-reply@databricks.com>
@cathleeny

Copy link
Copy Markdown
Collaborator Author

Thanks for the review. Updated the description to correct 401/403 pooling and link the Go nightly AUTH-033 run and its temporary branch; the test lands in databricks/databricks-driver-test#2423. The background-context difference remains documented and is tracked in databricks/databricks-sql-kernel#537.

  • Context: kept context.Background() because overlapping callbacks cannot safely use a session-wide context pointer; the inline reply has details.
  • Error identity: 1bb3dbe restores it on an exact, nonempty message match, with same-text collision limitations.
  • Eviction: 1bb3dbe names the kernel messages and regression test; a structural C ABI marker is a possible follow-up.

@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 concern. The callback lifecycle, error wrapping and session-eviction logic are sound and well tested. This can't merge yet: go.mod must move to bindings that export kernel_session_config_set_auth_external, because v1.5.0 lacks it and the kernel-tagged build would fail to link with only KERNEL_REV bumped.

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

Comment thread CHANGELOG.md Resolved
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 High · 1 Nit

Looks good, with one low concern: the CHANGELOG entry needs a behavior-change label. The cgo handle lifecycle, the nil-safe wrapProviderFailure, the local-failure exception for session eviction and the request URL match Thrift, and tests cover them. The auth docs omit Accept-Encoding and the SEA routing headers from the ignored list (nit).

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 — The new callback ABI is used while consumer builds still select the unchanged v1.5.0 bindings, so bumping KERNEL_REV and passing source-built tests does not establish that the shipped archive supports these symbols and semantics. Publish and pin matching bindings before merging these calls, and verify a normal tagged build without the local archive override. (Found by GPT-6.1 Sol · the judge couldn't confirm it)
  • ⚪ Nit — The entry changes existing behavior without the Behavior change: label. Custom authenticators no longer return ErrNotSupportedByKernel, and federated providers switch from one connect-time snapshot to a per-request exchange. Label the entry and state the fallback-detection effect. (Found by Claude Opus 5.5 · confirmed by the judge)

@cathleeny

Copy link
Copy Markdown
Collaborator Author

Per the release model, the bindings module moves at the joint kernel and driver release; this PR pins merged kernel 6d6c1e4. The changelog already summarizes the new support and federation refresh in two sentences; the description covers the behavior differences and the newly reserved headers.

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

Mostly solid: 1 high, 1 low. The callback bridge, eviction classification and tests look correct. The main risk is that the bindings pin hasn't moved along with the new ABI symbols.

Comment thread KERNEL_REV Resolved
Comment thread CHANGELOG.md Resolved

This branch has not been deployed

No deployments
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