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 reads the cache path literally and only checks the misspelled KRBCCNAME.
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 default cache.
Limitation
gokrb5 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 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
go.mod adds gokrb5/v8 and its dependencies as indirect requirements, pulled in by go-mssqldb/integratedauth/krb5. The additional older /go.mod-only lines in go.sum are part of that module graph: go mod tidy produces them, and go list -m all fails with "missing go.sum entry" without them.
Testing
Unit tests for cache path resolution and connection-string parameters.
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.
🟢 Approval recommended
No active review issues are recorded for the Kerberos authentication change.
No open issues 🎉
1 file not reviewed
internal/translations/catalog.go: Generated file
Review effort: Balanced
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 reads the cache path literally and only checks the misspelledKRBCCNAME.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 default cache.Limitation
gokrb5 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 with
GOOS=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
go.modaddsgokrb5/v8and its dependencies as indirect requirements, pulled in bygo-mssqldb/integratedauth/krb5. The additional older/go.mod-only lines ingo.sumare part of that module graph:go mod tidyproduces them, andgo list -m allfails with "missing go.sum entry" without them.Testing
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.