fix: add actionable guidance for TLS certificate failures - #356
David Levy (dlevy-msft-sql) wants to merge 25 commits into
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #356 +/- ##
===========================================
+ Coverage 81.66% 96.31% +14.65%
===========================================
Files 34 91 +57
Lines 7056 75317 +68261
===========================================
+ Hits 5762 72539 +66777
- Misses 1027 2758 +1731
+ Partials 267 20 -247
Flags with carried forward coverage won't be shown. Click here to find out more.
🚀 New features to boost your workflow:
|
1785b05 to
dc54c9d
Compare
There was a problem hiding this comment.
Pull request overview
Improves the driver’s TLS handshake failure diagnostics by wrapping handshake errors with actionable guidance (including relevant GODEBUG workarounds) for known Go crypto/tls policy changes, helping users self-remediate certificate-related failures.
Changes:
- Add
wrapTLSError()intds.goto recognize specific TLS/cert failure strings and append remediation guidance. - Apply the wrapper at both TLS handshake sites (
getTLSConn()and the standard encryption path inconnect()), ensuring proper error wrapping (%w). - Add unit tests covering the known patterns and default behavior.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| tds.go | Introduces wrapTLSError() and uses it at both TLS handshake call sites to enrich errors with guidance. |
| tds_unit_test.go | Adds unit tests validating wrapping behavior, message contents, and errors.Is unwrapping. |
The following TLS handshake error is fixed by newer versions of mssql (refer to microsoft/mssql-docker#895 (comment)) ``` TLS Handshake failed: tls: failed to parse certificate from server: x509: negative serial number ``` Based on microsoft/go-sqlcmd#755 (comment), newer versions of mssql don't have this problem. And there're changes going to mssql driver side to make this error more explicit microsoft/go-mssqldb#356. --------- Co-authored-by: Lunny Xiao <xiaolunwen@gmail.com> Co-authored-by: Giteabot <teabot@gitea.io>
The following TLS handshake error is fixed by newer versions of mssql (refer to microsoft/mssql-docker#895 (comment)) ``` TLS Handshake failed: tls: failed to parse certificate from server: x509: negative serial number ``` Based on microsoft/go-sqlcmd#755 (comment), newer versions of mssql don't have this problem. And there're changes going to mssql driver side to make this error more explicit microsoft/go-mssqldb#356. --------- Co-authored-by: Lunny Xiao <xiaolunwen@gmail.com> Co-authored-by: Giteabot <teabot@gitea.io>
|
Refuted: Go 1.25's |
…ix/tls-handshake-error-guidance
|
The Evidence
I built the test binary from
Same instruction count, same sequence, same mnemonics. Every one of the 205 differing lines is a relocation operand: 80 Local A/B on those same two binaries,
No regression locally. The PR side is marginally faster. Why CI sees itThe job builds the baseline from a separate Runs: job What I did not changeI did not widen the 15% threshold and did not add |
|
Third reproduction, now on head Same benchmark, same magnitude (+22.32%, +23.60%, +22.01% across three runs on three different heads), everything else Nothing in this PR touches |
Problem
TLS handshake failures caused by invalid certificates or obsolete TLS configuration provide little remediation guidance:
Root cause
The driver returned the underlying TLS error without identifying the server-side certificate or TLS configuration change needed to resolve it.
Solution
Recognize these certificate and TLS failures and put permanent server-side remediation first. The errors recommend replacing invalid certificates or updating obsolete TLS configuration. Where supported, they also identify
GODEBUGsettings as temporary compatibility options.Changes
tds.gowrapTLSError, apply it at both TLS handshake sites, and preserve wrapped errors with%wtds_unit_test.goTesting
go build ./...go test -count=1 -run 'TestWrapTLSError|TestGetTLSConnHandshakeError|TestConnectNonStrictTLSHandshakeError' .Related issues
Closes #302
Closes #217