Add GSSAPI (Kerberos) authentication and GSS encryption - #12
Merged
Merged
Conversation
Phase 1: GSSAPI authentication. Auth codes 7 and 9 run the gss_init_sec_context token exchange through SASLAuth.GSSAPI (the system Kerberos library, as libpq), sending GSSResponse messages and feeding back code-8 continuations. Options krbsrvname (default postgres) and gssdelegation, with PGKRBSRVNAME and PGGSSDELEGATION. Phase 2: GSS encryption (gssencmode, default disable). GSSENCRequest is sent before SSLRequest when a ticket can be acquired; on G the framed handshake runs and every message is gss_wrap'ed under the 16 KiB packet limit through a new GSSConn transport; N falls through to sslmode under prefer and fails under require; a GSS attempt the server accepted but that then fails is retried once without GSS under prefer, as libpq does. Cancel requests use GSS encryption when the connection they cancel does. Side finding (CVE-2024-10977 pattern): the server's ErrorResponse to SSLRequest or GSSENCRequest is no longer read or displayed; the connection fails with libpq's fixed message instead. Tests: a scripted GSS mechanism and scripted server cover negotiation, chunked framing, cancel, deadlines, authentication, and every error path on all CI platforms; a Kerberos fixture runs an MIT KDC inside the PostgreSQL container for a real round trip on Linux. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
…rder The bind-mounted temp dir is 0700 on Linux, so the postgres user could not read the keytab and hba file from it; keep the server's files in a container-local directory and export only the ticket cache. In the docs job, pin SASLAuth before developing the package so the resolve succeeds. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
quinnj
commented
Sep 18, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Kerberos support for Postgres.jl through the operating system's GSSAPI library (the same library libpq uses), with no new binary dependency. Mechanism bindings come from registered SASLAuth 1.1.0; this PR is the protocol side.
GSSAPI authentication (auth codes 7, 8, 9): the
gss_init_sec_contexttoken exchange withGSSResponsemessages, mutual authentication required (anAuthenticationOkbefore the context completes is refused). New optionskrbsrvname(defaultpostgres) andgssdelegation, plusPGKRBSRVNAME/PGGSSDELEGATION.GSS encryption (
gssencmode:disable(default),prefer,require;PGGSSENCMODE):GSSENCRequestbeforeSSLRequest, only when a ticket can be acquired; framed handshake; every messagegss_wraped and chunked under the 16 KiB packet limit through a newAPI.GSSConntransport;Nfalls through tosslmodeunderprefer; a GSS attempt the server accepted but that then fails is retried once without GSS underprefer, as libpq does.cancel_query!uses GSS encryption when the connection it cancels does. Message flow, limits, and error texts mirror libpq'sfe-auth.c/fe-secure-gssapi.c/fe-connect.c.CVE-2024-10977 pattern: the server's
ErrorResponsetoSSLRequest(existing path) orGSSENCRequest(new) is no longer read or shown; the connection fails with libpq's fixed message.Also: the keyword constructor now defaults
userto the OS login name (PGUSER/USER/USERNAME), as the DSN path already did, soPostgres.Connection(host=...)works for ticket holders.Design notes
gssencmodedefaults todisablerather than libpq'sprefer:preferwould silently replace TLS with GSS encryption for anyone holding a ticket. Documented in the support policy.API.GSSConn.ctxis the concreteSASLAuth.GSSAPI.Context, as requested in review. The scripted protocol tests replace native entry points temporarily and use realContextobjects; they restore system-library lookup before the live Kerberos fixtures.mainpreserves startupoptionsacross plain, TLS, and GSS connections and reconnects. The release version is 2.1.0.Test plan
test/gssapi.jl: scripted native GSS entry points plus a scripted server on a loopback port coverG/N/Enegotiation forpreferandrequire, the framed handshake, chunked framing both ways, the prefer re-dial, startup errors over GSS, no-credential behavior, auth codes 7/8/9 incl. prematureAuthenticationOk, server rejection, duplicate request, cancel over GSS,wait_for_notificationdeadlines on the GSS transport, and the SSLRequestEpath. Runs on every CI platform.Kerberos Fixture(Linux Docker jobs): an MIT KDC inside the PostgreSQL container,hostgssencandhostnogssencrules, real GSSAPI authentication and GSS encryption verified throughpg_stat_gssapi, 100 KB results and 70 KB parameters across packets, cancel over GSS, and unknown-principal failures. Passed locally on macOS (Heimdal client) against Docker.c9c190d: Julia/platform matrix, PostgreSQL 14–18, both authentication modes, documentation, and coverage. CI uses registered SASLAuth 1.1.0.🤖 Generated with Claude Code
Co-authored by Codex