You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
feat: use Kerberos for -E trusted connections on Linux and macOS - #822
On Linux and macOS, -E (trusted connection) previously fell back to NTLM and failed with Login failed for user ''. It now uses the go-mssqldb krb5 authenticator with the ticket obtained from kinit.
Following the direction discussed in #468, there are no new flags. Configuration comes from environment variables:
KRB5_CONFIG (default /etc/krb5.conf)
KRB5CCNAME (default /tmp/krb5cc_<uid>). A FILE: prefix is stripped, because the driver uses the cache path literally.
Windows keeps SSPI. Behaviour is unchanged when -E is not used.
Clear errors are returned for unsupported cache types (API:, KCM:, KEYRING:, DIR:) and for a missing credential cache file.
Limitation
The krb5 library used by go-mssqldb (go-krb5/krb5) only reads FILE: credential caches. The macOS default API: cache and the KCM:/KEYRING: defaults on Fedora/RHEL therefore need kinit -c FILE:... or KRB5CCNAME pointing at a file cache. Clients that use native GSSAPI (for example the vscode-mssql extension, see its KERBEROS_HELP.md) do not have this limitation. This is documented in the README.
Localization
The two new error messages go through the localizer, and the catalogs are regenerated against current main with GOOS=windows go generate ./... in internal/translations so Windows-only strings are preserved. gotext extracts every string in the scanned packages, so the regeneration also picks up two strings that already exist on main but were missing from the catalog ("Do not strip the "mssql: " prefix from error messages" and the ASCII table format option). No existing entries or translations are removed; the new entries fall back to English until translated.
Dependencies
Kerberos comes from go-mssqldb's integratedauth/krb5 package (go-mssqldb v1.12.0, which uses the community-maintained go-krb5/krb5). This PR adds no module requirements of its own: the only go.mod change relative to main is that github.com/go-krb5/krb5, github.com/go-krb5/x and github.com/go-crypt/x now appear as indirect requirements, because the new import makes them part of the build. The corresponding go.sum lines (including gorilla/securecookie and gorilla/sessions, which are /go.mod-level entries of that module graph) are what go mod tidy produces.
Testing
Unit tests for cache path resolution, plus a test that builds the -E connection string and creates the krb5 authenticator through the driver.
Manually verified on macOS against SQL Server 2014 SP3 in an Active Directory domain: sys.dm_exec_connections.auth_scheme returns KERBEROS. The missing-ticket and unsupported-cache error paths were also checked.
golangci-lint run --new-from-rev=main reports no new issues on darwin, linux and windows; go test ./... against SQL Server 2022 in Docker shows no failures beyond those already present on main.
The reason will be displayed to describe this comment to others. Learn more.
🟡 Changes recommended
Kerberos setup failures can silently leave the previous connection active, risking queries against the wrong server, while explicit SQL password authentication can incorrectly trigger Kerberos setup.
This PR adds Kerberos ticket-cache authentication for sqlcmd -E on Linux and macOS, addressing the trusted-connection failures described in #468 and #595 while preserving Windows SSPI behavior.
Changes:
Configure Kerberos through environment variables without adding flags.
Add cache validation, connection-string tests, and Kerberos dependencies.
Document setup and file-cache limitations on Linux and macOS.
File
Description
README.md
Documents Kerberos configuration and supported cache types.
pkg/sqlcmd/sqlcmd.go
Applies Kerberos settings to trusted connections.
pkg/sqlcmd/kerberos.go
Registers Kerberos authentication and resolves configuration and cache paths.
pkg/sqlcmd/kerberos_test.go
Tests cache handling, connection parameters, and provider registration.
go.sum
Adds checksums for Kerberos-related dependencies.
go.mod
Declares indirect dependencies required by Kerberos authentication.
Regenerate and commit missing translation artifacts
pkg/sqlcmd/kerberos.go:57
Please regenerate and commit the translation artifacts for this error and the missing-cache error at line 65, as required by the repository's localization guidance. Without those entries, the new messages remain outside the translation catalog and fall back to English regardless of SQLCMD_LANG. Use the Windows generation path described in the PR and check that existing platform-specific strings are preserved.
The reason will be displayed to describe this comment to others. Learn more.
🟡 Changes recommended
The Kerberos test assertion still passes when the krb5 provider is missing because it checks for the wrong error message, leaving provider registration unprotected against regressions.
The reason will be displayed to describe this comment to others. Learn more.
🟡 Changes recommended
The new test fails on Windows because credentialCachePath treats drive-letter paths as unsupported cache types; it needs the same Windows skip as the other Unix-only tests.
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
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
On Linux and macOS,
-E(trusted connection) previously fell back to NTLM and failed withLogin failed for user ''. It now uses the go-mssqldb krb5 authenticator with the ticket obtained fromkinit.Fixes #468
Related: #595
Approach
Following the direction discussed in #468, there are no new flags. Configuration comes from environment variables:
KRB5_CONFIG(default/etc/krb5.conf)KRB5CCNAME(default/tmp/krb5cc_<uid>). AFILE:prefix is stripped, because the driver uses the cache path literally.Windows keeps SSPI. Behaviour is unchanged when
-Eis not used.Clear errors are returned for unsupported cache types (
API:,KCM:,KEYRING:,DIR:) and for a missing credential cache file.Limitation
The krb5 library used by go-mssqldb (go-krb5/krb5) only reads
FILE:credential caches. The macOS defaultAPI:cache and theKCM:/KEYRING:defaults on Fedora/RHEL therefore needkinit -c FILE:...orKRB5CCNAMEpointing at a file cache. Clients that use native GSSAPI (for example the vscode-mssql extension, see its KERBEROS_HELP.md) do not have this limitation. This is documented in the README.Localization
The two new error messages go through the localizer, and the catalogs are regenerated against current
mainwithGOOS=windows go generate ./...ininternal/translationsso Windows-only strings are preserved.gotextextracts every string in the scanned packages, so the regeneration also picks up two strings that already exist onmainbut were missing from the catalog ("Do not strip the "mssql: " prefix from error messages" and the ASCII table format option). No existing entries or translations are removed; the new entries fall back to English until translated.Dependencies
Kerberos comes from go-mssqldb's
integratedauth/krb5package (go-mssqldb v1.12.0, which uses the community-maintained go-krb5/krb5). This PR adds no module requirements of its own: the onlygo.modchange relative tomainis thatgithub.com/go-krb5/krb5,github.com/go-krb5/xandgithub.com/go-crypt/xnow appear as indirect requirements, because the new import makes them part of the build. The correspondinggo.sumlines (includinggorilla/securecookieandgorilla/sessions, which are/go.mod-level entries of that module graph) are whatgo mod tidyproduces.Testing
-Econnection string and creates the krb5 authenticator through the driver.sys.dm_exec_connections.auth_schemereturnsKERBEROS. The missing-ticket and unsupported-cache error paths were also checked.golangci-lint run --new-from-rev=mainreports no new issues on darwin, linux and windows;go test ./...against SQL Server 2022 in Docker shows no failures beyond those already present onmain.