Skip to content

PHOENIX-8033 phoenixdb: use native Windows SSPI for SPNEGO instead of requiring MIT Kerberos - #195

Open
AlonSoko wants to merge 2 commits into
apache:masterfrom
AlonSoko:windows-sspi-spnego
Open

AlonSoko wants to merge 2 commits into
apache:masterfrom
AlonSoko:windows-sspi-spnego

Conversation

@AlonSoko

@AlonSoko AlonSoko commented Oct 26, 2026 •

Copy link
Copy Markdown

Problem

On Windows, phoenixdb requires MIT Kerberos for Windows (KfW), even though Windows has Kerberos built in (LSA/SSPI):

  • requests-gssapi (which pulls in gssapi) is an unconditional install requirement.
  • phoenixdb/__init__.py imports gssapi and requests_gssapi at module level, so import phoenixdb fails without a working GSSAPI library, even for BASIC/DIGEST/no authentication.

Changes

  • phoenixdb/__init__.py: the gssapi / requests_gssapi imports move into _get_SPNEGOAuth(), which only runs for authentication='SPNEGO'. On win32 it returns the new SSPI auth class; elsewhere (or if pyspnego is not available) it builds HTTPSPNEGOAuth(opportunistic_auth=True, mech=SPNEGO) exactly as before.
  • phoenixdb/sspi_auth.py (new): HTTPSPNEGOAuthSSPI, a small requests auth class on top of pyspnego, which uses native SSPI on Windows and so the logged-on user's tickets (no KfW, no kinit). It mirrors the current behaviour: an opportunistic Negotiate token for HTTP/<host>, mutual auth disabled. A 401 carrying a server token is answered once on the same connection (multi-leg, e.g. NTLM fallback); a 401 without one is returned as is.
  • setup.py, requirements.txt: platform markers; requests-gssapi on non-Windows, pyspnego on Windows (Python >= 3.8). Python < 3.8 is unchanged.

Linux/macOS behaviour and the public API (connect(..., authentication='SPNEGO'), user as doAs) are unchanged.

Testing

  • Windows 11 (domain-joined, no KfW, no kinit), Python 3.12 x64, against a Kerberized Phoenix Query Server: SELECT 1 and table queries succeed with authentication='SPNEGO'; klist shows the HTTP/<fqdn> service ticket obtained through SSPI.
  • Multi-leg path: loopback test with a real SSPI acceptor (spnego.server), NTLM fallback: 401 + challenge, then 200 on the same connection; a 401 without a token is returned after a single request.
  • macOS: import phoenixdb works without gssapi installed; the existing unit tests that do not need a live Query Server pass.

JIRA: https://issues.apache.org/jira/browse/PHOENIX-8033

On Windows, authenticate through pyspnego (SSPI, the logged on user's
LSA Kerberos tickets) instead of requests-gssapi, so MIT Kerberos no
longer has to be installed. The gssapi and requests_gssapi imports are
now done only when SPNEGO is used, so importing phoenixdb no longer
requires a GSSAPI library.
…ego on Windows

A gssapi package installed without MIT Kerberos for Windows raises
OSError on import. pyspnego only catches ImportError around that import,
so "import spnego" failed with a misleading "Could not find KfW
installation". Raise an error that names the cause and the fix instead.
@AlonSoko

AlonSoko commented Oct 26, 2026 •

Copy link
Copy Markdown
Author

Could a committer please open a PHOENIX JIRA ticket for this (component: python)? I don't have an ASF JIRA account to file it myself. Suggested summary:

phoenixdb: use native Windows SSPI for SPNEGO instead of requiring MIT Kerberos

The PR description above can serve as the ticket description. Once the ticket exists, I'll retitle the PR and prefix the commits with the key. Thanks!

@AlonSoko

Copy link
Copy Markdown
Author

@stoty @richardantal could one of you file the PHOENIX JIRA for this, as asked above? Thanks.

@AlonSoko

Copy link
Copy Markdown
Author

cc @PDavid

@PDavid

PDavid commented Oct 26, 2026

Copy link
Copy Markdown
Contributor

Hi @AlonSoko,
I opened the JIra ticket here for you:
https://issues.apache.org/jira/browse/PHOENIX-8033

@AlonSoko
AlonSoko force-pushed the windows-sspi-spnego branch from 562ed29 to d65508a Compare October 26, 2026 16:10
@AlonSoko AlonSoko changed the title phoenixdb: use native Windows SSPI for SPNEGO (no MIT Kerberos needed) PHOENIX-8033 phoenixdb: use native Windows SSPI for SPNEGO instead of requiring MIT Kerberos Oct 26, 2026
@AlonSoko

Copy link
Copy Markdown
Author

Thanks @PDavid! I've retitled the PR and prefixed the commits with PHOENIX-8033.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants