Skip to content

[Kerberos authentication] Add optional GSSAPI and SSPI authentication - #3866

Open
hacetin wants to merge 4 commits into
brianc:masterfrom
hacetin:alperen/kerberos-authentication
Open

hacetin wants to merge 4 commits into
brianc:masterfrom
hacetin:alperen/kerberos-authentication

Conversation

@hacetin

@hacetin hacetin commented Nov 18, 2026 •

Copy link
Copy Markdown

Summary

Add ticket-based authentication to the existing JavaScript driver through the
optional kerberos native binding. Ordinary password connections do not load
the binding.

  • Parse PostgreSQL AuthenticationGSS (7), GSSContinue (8) and SSPI (9), preserving
    opaque binary tokens and framing responses without a C-string terminator.
  • Serialize native context initialization and continuation steps. Resolve
    connect() only after the client context completes and the server accepts
    authentication and reports readiness. Suppress late results after cancellation.
  • Support service-name and database-host overrides, including tunneled
    connections, with platform-appropriate service identities.
  • Fail unsupported or malformed authentication cleanly through Client and Pool,
    while preserving application callback exceptions.
  • Include protocol/session/lifecycle regressions, documentation, and an opt-in
    disposable Linux PostgreSQL/Kerberos/TLS/SSH fixture.

GSS transport encryption is not implemented. gssencmode=require rejects before
opening a socket; prefer does not enable encryption. TLS verification is not
weakened. This does not add credential delegation, automatic password fallback,
or a switch to another driver.

Validation

Final source: e8bc50dfdda975fff0be63911ddf72d751ff063e.

Check Result
TypeScript workspace build Passed
Authentication-related source/test lint Passed
Protocol tests 86 passed on Windows and Linux
Mocked-binding GSS session cases 14 passed on each platform
Scripted whole-Client handshake/lifecycle cases 16 passed on each platform
Unsupported-auth Client/Pool rejection and recovery 3 passed on each platform
Linux pg unit files 26/26 passed
Windows pg unit files 24/26 passed; the same two failures reproduce on unmodified upstream

The Windows unit failures concern existing USER/USERNAME assumptions and
localhost DNS after a test clears the process environment. They were not hidden
or repaired as part of this change.

Seven focused regressions reproduce three defects in the initial candidate:
misinterpreted stream backpressure, readiness overriding an authentication
failure, and application connect exceptions being misclassified as authentication
errors. All seven pass with the final fixes.

The 65,535-byte token limit, rejection above that limit, copied-token ownership
and exact binary response framing were also checked.

Qualification boundaries

Earlier real PostgreSQL/Kerberos evidence belongs to the source tree at
9cad6da07e7d4063b0e4f65108ee7c6a8933a379, not a new real-Kerberos run on the
final follow-up commit. Only public commit-attribution metadata changed when
preparing that source for publication; the tested source tree is identical.
That candidate passed real Linux Kerberos and direct Windows-domain
GSS/Kerberos checks.

Windows SSPI client Kerberos was exercised through an explicitly labeled
AuthenticationGSS-to-AuthenticationSSPI request-code adapter backed by real
PostgreSQL/SPNEGO/KDC and verified TLS. This is not a native Windows-server
SSPI/Kerberos interoperability pass; local native-server SSPI negotiated NTLM.
SSPI success alone must not be described as proof of Kerberos.

Actual VS Code extension-host Kerberos qualification remains incomplete:
the new attempts hit the unmodified startup-readiness guard. Bundled Node
success is not an actual extension-host pass. macOS, ARM, Node 16 execution and
signed native-binary distribution are also unqualified.

This draft is for scoped experimental review, not a claim of production-ready
or complete cross-platform Kerberos support.

hacetin and others added 4 commits November 15, 2026 15:54
Keep parser failures separate from callback exceptions. Add split-packet, Client/Pool rejection and subsequent-connection regression coverage.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Handle binary PostgreSQL GSS negotiation with the optional Kerberos binding, protect context completion and cancellation, and keep GSS transport encryption unsupported. Add real-fixture and protocol/lifecycle tests and document the driver boundary.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Register each protocol regression once and ensure failed fixture teardown cannot report a passing check.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Treat writable-stream backpressure as an accepted authentication token. Ignore readiness after a failed or destroyed connection, and keep application connect callback/listener exceptions outside authentication promise catches. Add whole-Client and Pool regressions for all three boundaries.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
@hacetin
hacetin marked this pull request as ready for review November 19, 2026 10:51
@hacetin

hacetin commented Nov 19, 2026

Copy link
Copy Markdown
Author

Related to #3267, which introduces GSS authentication codes 7/8, optional kerberos integration, binary response framing and protocol tests. This PR additionally handles SSPI authentication code 9, distinguishes Kerberos from SPNEGO mechanism selection, and supports platform-specific service identities. It adds serialized negotiation, client-context/server-acceptance gating, cancellation safeguards, and Client/Pool lifecycle and failure-recovery coverage. Real authentication evidence and remaining qualification limits are documented separately.

Parser-failure containment also overlaps #3843.

@hacetin

hacetin commented Nov 19, 2026

Copy link
Copy Markdown
Author

@brianc @charmander PTAL

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.

1 participant