Skip to content

feat(proxy): Kerberos/Negotiate proxy authentication - #526

Open
cathleeny wants to merge 11 commits into
mainfrom
cathleeny/ddf-kerberos-kernel
Open

cathleeny wants to merge 11 commits into
mainfrom
cathleeny/ddf-kerberos-kernel

Conversation

@cathleeny

@cathleeny cathleeny commented Dec 2, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

Adds Kerberos (Negotiate) authentication for HTTP proxies, so connections work through corporate proxies that require Proxy-Authorization: Negotiate on the CONNECT. This is proxy authentication only, not warehouse Kerberos. It is opt-in: the new cargo feature proxy-negotiate is off by default, and existing proxy settings behave as before.

The OSS ODBC driver (databricks/databricks-odbc#528) and the Python connector (databricks/databricks-sql-python#1085) build on this. The Node.js (napi) binding is unchanged and does not expose Negotiate yet; the Node.js driver is out of scope for this feature.

What changes

  • New setting: ProxyConfig::auth = ProxyAuth::Negotiate { service, host, realm }. The target defaults to HTTP/<proxy host> in the default realm. ProxyAuth::NegotiateCallback lets a binding supply the tokens instead.
    • C ABI: kernel_session_config_set_proxy_negotiate(config, service, host, realm).
    • Python binding: Session(proxy_url=..., proxy_bypass_hosts=..., proxy_negotiate_token=<callable>).
  • Credentials: the user's existing Kerberos ticket (credential cache on Linux/macOS, logon session on Windows). No passwords or keytabs.
  • Token handling: the token goes only to the proxy, on the CONNECT. It is never sent to the warehouse or storage, and never logged.
  • Proxy rejects a token (407): the kernel retries that connection once with a fresh token. A second rejection fails the request.
  • Fails closed: with no valid ticket, the session fails before any network traffic with Unauthenticated and the Kerberos reason (for example Ticket expired). It never falls back to Basic, a direct connection or another proxy.
  • Invalid settings (Basic credentials, a socks:// URL, no proxy URL) return InvalidArgument.

Dependency: cross-krb5 0.5, only with proxy-negotiate. It uses the system GSSAPI library on Linux/macOS and SSPI on Windows. The Python wheel does not enable the feature and links no Kerberos library.

Known limit: a proxy with a Kerberos replay cache (for example squid with MIT's replay cache) rejects the first token on each new connection after the first, so each one costs one extra round trip. reqwest 0.12 sends the same proxy header on every connection. The retry is cheap: the TLS setup is reused, so a rebuild takes about 0.3 ms.

Testing

Live, through a test Kerberos KDC and a squid proxy with the replay cache on:

Case DBSQL Reyden
Valid ticket: 6 sequential sessions, then 2 × 4 concurrent queries ✅ 7 tokens rejected by the replay cache, each retried once ✅ 6 rejected, each retried once
CloudFetch download (2 × 200,000 rows) ✅ ✅
No ticket ✅ fails in < 1 ms, nothing sent to the proxy ✅
Expired ticket ✅ fails in < 2 ms, nothing sent to the proxy ✅
No token in TRACE logs ✅ ✅
Connect overhead vs. an unauthenticated proxy ✅ on a rerun¹ ✅

¹ The first DBSQL timing run failed while the test machine was overloaded (load average about 40 on 32 cores). The rerun passed.

Also run:

  • cargo test --workspace: 1,388 passed. It includes the stub-proxy Negotiate tests, which the existing PR jobs run on both TLS backends.
  • The C ABI smoke tests and the Python binding tests (32 cargo test, 38 pytest).
  • The wheel has no Kerberos library dependency (readelf -d).
  • This PR adds no CI job. Real Kerberos tokens through squid are covered by the driver-test kernel nightly (databricks/databricks-driver-test#2422).

Not run yet: Windows (SSPI) and macOS builds.

Merge order

This pull request and its description were written by Isaac.

Authenticate to HTTP proxies with `Proxy-Authorization: Negotiate`
(Kerberos/SPNEGO) on the CONNECT, for parity with the Python connector's
`_proxy_auth_method="negotiate"` and Simba ODBC `ProxyAuthType=2`.

- `ProxyConfig::auth`: `ProxyAuth::Default` (unchanged Basic/none),
  `ProxyAuth::Negotiate { service, host, realm }` (cross-krb5 0.5 behind
  the non-default `proxy-negotiate` feature: system GSSAPI on Unix, SSPI
  on Windows; ambient credentials, no delegation; target defaults to
  `HTTP/<proxy host>`) and `ProxyAuth::NegotiateCallback` (caller tokens,
  used by the Python binding, which links no GSSAPI library).
- A token is created at client build (session open) and once more when
  the proxy answers a CONNECT with 407; only that hop is resent once on
  the rebuilt client, which then serves new requests. A second 407 on
  the same hop fails the request. It never falls back to Basic, a direct
  connection or an env proxy. Every token (session open, the Azure
  tenant redirect probe, 407 rebuilds) is created on the blocking pool,
  never on an async worker.
- A Negotiate client loads its TLS setup once (native-tls: the
  connector; rustls: the OS trust store) and every 407 rebuild reuses
  it, so a rebuild only creates a client with the new token.
- With Negotiate the kernel follows redirects itself with reqwest's
  default rules, so a 407 on a later hop never resends a request the
  server already received. As in reqwest, one request timeout covers
  every hop, the fresh-token rebuild and the final body. The retry
  ladder, U2M OAuth token requests and the feature-flag GET all send
  through `send_once`.
- A token failure fails session open with the GSS major/minor message
  and no network I/O (`Unauthenticated`). Basic credentials, non-http(s)
  proxy URLs or a missing URL with Negotiate are `InvalidArgument`;
  `Negotiate` without the feature is rejected as unsupported.
- C ABI `kernel_session_config_set_proxy_negotiate`; pyo3 `proxy_url`,
  `proxy_bypass_hosts` and `proxy_negotiate_token` kwargs.
- Tests: a stub CONNECT proxy with replay-cache semantics (default PR
  tests, both TLS backends; tunnels, redirects, deadlines, U2M token
  requests, TLS parity of rebuilt clients, slow tokens off the async
  workers), a real MIT KDC + squid `negotiate_kerberos_auth` fixture
  (`ci/proxy/negotiate`, new PR job for both TLS backends), C smoke and
  pyo3 pytest cases.

Signed-off-by: cat23123 <58714163+cat23123@users.noreply.github.com>
Co-authored-by: Isaac <no-reply@databricks.com>
The job ran on every PR, push and merge-queue entry, and its real KDC + squid replay test depended on how many tunnels happened to overlap. Remove the job, ci/proxy/negotiate/{start,stop}.sh and the ignored KDC test. The stub-proxy Negotiate tests still run in the existing PR jobs on both TLS backends, and the driver-test kernel nightly covers real Kerberos tokens through squid.

Co-authored-by: Isaac <no-reply@databricks.com>
Signed-off-by: cat23123 <58714163+cat23123@users.noreply.github.com>
The replay test now holds each origin answer until a wave of six requests has all reached its tunnel, and the deadline test doubles its delays and timeouts. The slow-token test waits on an async signal instead of a 20 ms ticker racing a 500 ms block. Test-only change; proxy code is untouched.

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: 4 low-severity findings and nothing blocking. Validation fails closed, the token is kept out of logs and errors, and the stub-proxy tests are thorough. One gap: the napi binding does not expose the new proxy auth, so the bindings now differ.

This overview is Claude Opus 5.5's initial take; some of its points were set aside by the cross-check judge and GPT-6.1 Sol added findings it doesn't mention — see the findings below.

Other findings

  • ⚪ Nit — After kernel_session_config_set_proxy_negotiate is called, there is no way to clear it on a reused config, and passing all NULLs still selects Negotiate with the default target. Document that the setting is sticky, or add a clear path. (Found by Claude Opus 5.5 · confirmed by the judge)
🔀 1 finding considered and dismissed by the judge
  • 🟡 Medium src/client/http.rs:1209 — The Negotiate redirect-probe branch sends directly through reqwest, so a CONNECT 407 immediately fails Azure tenant discovery instead of receiving the promised
    Judge's evidence: self.build_negotiate_client(redirect).await?

Comment thread src/config.rs Resolved
Comment thread src/client/http.rs Resolved
Comment thread src/client/http.rs Resolved
Comment thread src/client/proxy_negotiate.rs Resolved
- Make NegotiateTokenCallback's inner closure pub(crate); `new` stays the public constructor.
- Pin the CONNECT-407 detection against a real tunnel error from the stub proxy, so a reqwest or hyper-util bump that rewords it fails a test.
- Document why concurrent 407 rebuilds are not coalesced.
- Document that kernel_session_config_set_proxy_negotiate stays on the config.

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: 2 Medium · 3 Low

Looks reasonable: 1 medium and 2 low concerns. The napi binding (napi/src/database.rs:910) doesn't expose Negotiate. If that's intended, the PR or changelog should say so so the bindings don't drift apart.

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 pyo3/src/session.rs Resolved
Comment thread pyo3/src/session.rs Resolved
Comment thread src/client/http.rs Resolved
Comment thread src/client/http.rs Resolved
Comment thread src/client/http.rs Resolved
client::ProxyConfig is re-exported as stable surface for advanced wrappers, so code that builds it with a struct literal needs `..Default::default()` now that it has an `auth` field.

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: 4 Low

Looks solid, with 1 medium and 1 low concern. Fail-closed handling, the hop-by-hop 407 retry and the redaction are well tested. The napi binding still exposes no Negotiate option; either add one or document the difference.

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 src/client/http.rs Resolved
Comment thread pyo3/src/session.rs Resolved
Comment thread src/client/http.rs Resolved
Comment thread Cargo.toml Resolved
… list without a proxy

- Fail closed when the Negotiate token callback runs after interpreter shutdown: use Python::try_attach and return an error instead of attaching during finalization.
- Raise ValueError for proxy_bypass_hosts without proxy_url instead of silently dropping the bypass list, and document the requirement.
- Document that a streaming (non-cloneable) body gets one plain attempt with no 407 retry and no redirect following; all current callers send cloneable JSON or empty bodies.

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

Looks good, with one low concern. I checked every send path. OAuth, feature-flag and SEA traffic all go through send_once, so a proxy 407 gets its fresh-token retry. The C ABI, PyO3 and public-API changes are consistent with each other and documented.

This overview is Claude Opus 5.5's initial take; some of its points were set aside by the cross-check judge and GPT-6.1 Sol added findings it doesn't mention — see the findings below.

🔀 1 finding considered and dismissed by the judge
  • 🟡 Medium src/client/http.rs:1221 — The Negotiate tenant-discovery client still sends directly through reqwest, so a CONNECT 407 immediately fails Azure session opening instead of receiving the pr
    Judge's evidence: self.build_negotiate_client(redirect).await?

Comment thread src/client/http.rs Resolved
Comment thread src/client/http_negotiate_tests.rs Resolved
cathleeny and others added 2 commits December 2, 2026 22:21
reqwest forwards a plain-HTTP request to the proxy with the Negotiate token attached and no tunnel, and a 407 there gets no fresh-token retry. With Negotiate, a plain-HTTP request now fails with InvalidArgument before any I/O, and a redirect to plain HTTP fails with NetworkError before that hop, so the token only ever rides on CONNECT.

Signed-off-by: cat23123 <58714163+cat23123@users.noreply.github.com>
Co-authored-by: Isaac <no-reply@databricks.com>
The second hop now has 1200 ms (redirect) and 800 ms (body) of slack before the deadline, and the deadline still lands at least 800 ms before the request could finish, so a per-hop timeout restart is still caught.

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

Looks solid: 2 low concerns. The token goes only on CONNECT, fails closed, and the 407 retry is scoped to the failing redirect hop, with thorough stub-proxy tests. The gaps are edge cases in the plain-HTTP guard.

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 src/client/http.rs Resolved
Comment thread src/client/http.rs Resolved
Comment thread src/client/http.rs Resolved
The Azure tenant-discovery probe sends through its own client, so it now applies the same https-only rule as send_once. The Negotiate docs also say the rule covers hosts on the bypass list.

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

Review-body findings that had no inline thread:

  • Nit, kernel_session_config_set_proxy_negotiate is sticky on a reused config: documented in 7ee5f85 (header and Rust docs). A later call replaces the target, and a new config is the way to drop Negotiate.
  • The napi binding doesn't expose Negotiate: intended, because the Node.js driver is out of scope for this feature. The PR description says so.
  • The redirect-probe retry finding the judge dismissed: the probe now refuses plain HTTP (148200e). Its single-use fresh token needs no retry; see the probe thread.

This branch was successfully deployed

1 active (outdated) deployment
azure-prod — 889e7399 Deployed Dec 2, 2026 by oss-reviewer-bot[bot] via followup #5094
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.

1 participant