Skip to content

feat(kernel): support Negotiate proxy authentication on use_kernel - #1085

Open
cathleeny wants to merge 3 commits into
mainfrom
cathleeny/ddf-kerberos-python
Open

cathleeny wants to merge 3 commits into
mainfrom
cathleeny/ddf-kerberos-python

Conversation

@cathleeny

@cathleeny cathleeny commented Dec 2, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

With use_kernel=True, _proxy_auth_method="negotiate" now works. Before, the kernel path ignored it, and connections through a Kerberos proxy failed with a 407 after about 17 seconds. The Thrift path already supported it and is unchanged.

This is proxy authentication (Kerberos on the proxy's CONNECT), not warehouse Kerberos. It needs the kernel change in databricks/databricks-sql-kernel#526.

What changes

  • Same option, same proxy discovery: the proxy still comes from the environment (HTTPS_PROXY, NO_PROXY). The connector passes the proxy and a token callback to the kernel. Tokens for HTTP@<proxy host> are made with requests-kerberos, as on Thrift.
  • Fails closed: with no valid ticket, or without requests-kerberos installed, connect() raises OperationalError with the reason before sending anything. It never falls back to Basic, a direct connection or another proxy.
  • Unchanged: unset or basic, no proxy, and hosts in NO_PROXY behave as today.
  • Older kernel wheels raise NotSupportedError instead of silently ignoring the option.
  • No new required dependency: requests-kerberos stays optional and is imported only when negotiate is used. Raw tokens that pyspnego logs at DEBUG are filtered out.

Known limit: a proxy with a Kerberos replay cache rejects the first token on each new connection after the first, so each one costs one extra round trip (see #526).

Testing

Live, through a test Kerberos KDC and a squid proxy with the replay cache on, using a kernel wheel built from #526:

Case DBSQL Reyden
negotiate: 6 sequential sessions, then 2 × 4 concurrent queries ✅ 7 tokens rejected by the replay cache, each retried once ✅
Unset and basic unchanged; a NO_PROXY host sends nothing to the proxy ✅ ✅
No ticket, expired ticket, unknown proxy SPN ✅ fail closed, nothing sent to the proxy ✅
Proxy also offers Basic (no downgrade) ✅ only Negotiate is sent ✅
requests-kerberos missing ✅ other connections work; negotiate fails with a clear error ✅
No token in logs at any level ✅ ✅
Connect overhead vs. an unauthenticated proxy ✅ ✅
Total query time vs. Thrift ✅ on a rerun¹ n/a (no Thrift on Reyden)

¹ One run missed by 28 ms and the next passed. The Thrift baseline itself couldn't be timed here: squid's replay cache rejects the token Thrift reuses, and urllib3 keeps retrying. So the check used the stricter of its two limits.

Also run: the unit suite (1,474 passed), the real-kernel tests, black and mypy.

Not run yet: Windows and macOS.

Merge order

This pull request and its description were written by Isaac.

With use_kernel=True and _proxy_auth_method="negotiate", resolve the
system proxy the same way as the Thrift path (getproxies + proxy_bypass)
and pass the kernel the proxy URL, the NO_PROXY list and a callable that
creates a fresh Kerberos token for HTTP@<proxy host> with
requests-kerberos. The kernel calls it at session open and once more on
a proxy 407, and fails closed if it raises. A bypassed host, no proxy,
unset and basic keep today's kernel behavior. The Reyden auto-recovery
path carries the setting onto the kernel. pyspnego's DEBUG records that
print raw tokens are filtered out.

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

Looks good, with one low concern. The Negotiate wiring fails closed as described: errors go through wrap_kernel_exception to OperationalError, and NotSupportedError passes through unchanged. The tests cover routing, stripping user:password from the proxy URL, and filtering tokens out of logs.

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 — Filtering only spnego.* leaves the token exposed at DEBUG because requests-kerberos 0.15 also logs the complete Negotiate header from generate_request_header() under requests_kerberos.kerberos_. Filter that token-bearing record too, and add a regression covering the requests-kerberos logger rather than only the mocked pyspnego output. (Found by GPT-6.1 Sol · the judge couldn't confirm it)

With _proxy_auth_method="negotiate" on use_kernel=True, the macOS and Windows system bypass lists apply only to the workspace host; for other hosts, such as CloudFetch storage, the kernel honors only NO_PROXY.

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

On the High finding in the review above ("requests-kerberos 0.15 also logs the complete Negotiate header from generate_request_header()"): this doesn't apply to this code, so no change.

In requests-kerberos 0.15.0, generate_request_header() (kerberos_.py lines 189–237) builds and returns the header without logging it. It logs only on failure, and then the error, not a token. The lines that log full headers are in authenticate_user() (254, 258) and in the preemptive branch of HTTPKerberosAuth.__call__() (437). Those run only when HTTPKerberosAuth is used as a requests auth handler. The connector never does that: both negotiate_proxy_token() and _generate_negotiate_headers() call generate_request_header(None, host, is_preemptive=True) directly (common/http_utils.py). The live checks agree: with every Python log record captured at level 1 (including requests_kerberos, pyspnego and the kernel via pyo3-log), on DBSQL and Reyden, none of the generated tokens appeared in the logs.

@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.

Brings in credentials_provider on kernel connections and the SOCKS docs. The
only conflict was tests/unit/test_kernel_client.py, where both sides added
tests at the same place; both are kept. KERNEL_REV follows main.

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 Nit

Looks good: 1 low formatting issue. The negotiate wiring matches Thrift's proxy discovery, fails closed on older wheels and leaves unset/basic unchanged. I could not check the claimed OperationalError mapping for a failing callback, because that depends on kernel #526.

Other findings

  • ⚪ Nit — _HOST = ... comes right after the closing ) of the previous test, with no blank lines. That breaks PEP 8 and would fail black --check. Add two blank lines before _HOST. (Found by Claude Opus 5.5 · confirmed by the judge)

This branch was previously deployed

1 inactive deployment
azure-prod — 97277bd2 Deployed Dec 4, 2026 by cathleeny via followup #2900
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