-
Notifications
You must be signed in to change notification settings - Fork 321
Avoid unintended SPN generation for non-integrated authentication on native SNI path #3929
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
|
@copilot please review. |
|
@paulmedynski I've opened a new pull request, #3931, to work on those changes. Once the pull request is ready, I'll request review from you. |
mdaigle
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice work figuring out this issue!
src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/TdsParserStateObjectNative.windows.cs
Outdated
Show resolved
Hide resolved
src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/TdsParserStateObjectNative.windows.cs
Show resolved
Hide resolved
src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/TdsParserStateObjectNative.windows.cs
Outdated
Show resolved
Hide resolved
...t.Data.SqlClient/tests/UnitTests/Microsoft/Data/SqlClient/TdsParserStateObjectNativeTests.cs
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
This PR fixes a performance regression introduced in PR #2790 where SPN (Service Principal Name) generation was inadvertently triggered for non-integrated authentication modes (e.g., SQL authentication) on the native SNI path. The fix ensures that SPN generation only occurs when using integrated security (SSPI/Kerberos), preventing unnecessary DNS lookups and connection delays.
Changes:
- Extracted SPN normalization logic into a new
NormalizeServerSpnmethod that returnsstring.Emptyfor integrated security (to trigger generation) ornullfor SQL auth (to prevent generation) - Updated
CreatePhysicalSNIHandleto conditionally setresolvedSpnonly when a valid SPN exists - Added comprehensive unit tests to verify the normalization logic
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/TdsParserStateObjectNative.windows.cs |
Introduces NormalizeServerSpn method to prevent unintended SPN generation for non-integrated auth and updates SPN handling in CreatePhysicalSNIHandle |
src/Microsoft.Data.SqlClient/tests/UnitTests/Microsoft/Data/SqlClient/TdsParserStateObjectNativeTests.cs |
Adds unit tests covering all SPN normalization scenarios for both integrated and SQL authentication |
...t.Data.SqlClient/tests/UnitTests/Microsoft/Data/SqlClient/TdsParserStateObjectNativeTests.cs
Outdated
Show resolved
Hide resolved
...t.Data.SqlClient/tests/UnitTests/Microsoft/Data/SqlClient/TdsParserStateObjectNativeTests.cs
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
...t.Data.SqlClient/tests/UnitTests/Microsoft/Data/SqlClient/TdsParserStateObjectNativeTests.cs
Show resolved
Hide resolved
...t.Data.SqlClient/tests/UnitTests/Microsoft/Data/SqlClient/TdsParserStateObjectNativeTests.cs
Show resolved
Hide resolved
Codecov Report✅ All modified and coverable lines are covered by tests.
Additional details and impacted files@@ Coverage Diff @@
## main #3929 +/- ##
===========================================
- Coverage 90.82% 67.54% -23.29%
===========================================
Files 6 263 +257
Lines 316 66205 +65889
===========================================
+ Hits 287 44715 +44428
- Misses 29 21490 +21461
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
Description
Potentially fixes #3523.
This PR fixes a connection performance regression introduced by PR #2790, where SPN generation could be triggered for non-integrated authentication modes such as SQL authentication on the native SNI path.
SPN (Service Principal Name) generation is only relevant for Integrated Security (SSPI/Kerberos). After PR #2790, empty
serverSPNvalues could reach native SNI even when Integrated Security was not in use, causing unnecessary SPN composition and potential DNS lookups.This change ensures that SPN generation is only triggered when authentication mode is integrated security(SSPI/Kerberos.
Issues
#3523
Testing
Added unit test for the SPN normalization logic.
Used the repro from #3523.
The regression was reproducible under a specific network topology:
Client machine connected directly to the main router
SQL Server machine connected via a Wi-Fi extender (which itself connects to the main router)
In this setup, SqlConnection.Open() using SQL authentication and an IP-based data source (for example, tcp:,1433) could take ~5 seconds.
Without the fix
With the fix