Skip to content

Ensure correct SPN when calling SspiContextProvider #3347

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

Open
wants to merge 21 commits into
base: main
Choose a base branch
from

Conversation

twsouthwick
Copy link
Member

@twsouthwick twsouthwick commented May 14, 2025

This change does the following:

  • Only initialize when handshake is complete
  • The serverSpn field is now local to the method
  • Adds some bookkeeping to ensure we're only using the SPN that has previously generated a context once one has been created.
  • Reworks the SNI pathways on .NET Core to only return the SPN that is needed. On .NET Core, it was returning an array but only using a single value from that. This refactors that to be more readable to just return the value used.

See comment: See #2454 (comment)

Part of #2253

@twsouthwick twsouthwick force-pushed the reset-negotiate branch 2 times, most recently from 5610fa9 to 6ee0ae5 Compare May 15, 2025 18:11
@twsouthwick twsouthwick requested a review from a team as a code owner May 15, 2025 18:11
This change also adds some book keeping to ensure we're only using the spn that has previously generated a context once one has been created.
Copy link

codecov bot commented May 16, 2025

Codecov Report

Attention: Patch coverage is 77.35849% with 12 lines in your changes missing coverage. Please review.

Project coverage is 58.79%. Comparing base (832e8da) to head (3ca3de6).
Report is 7 commits behind head on main.

Files with missing lines Patch % Lines
...crosoft/Data/SqlClient/SSPI/SspiContextProvider.cs 73.68% 5 Missing ⚠️
...ata/SqlClient/SSPI/NegotiateSspiContextProvider.cs 70.00% 3 Missing ⚠️
...nt/netfx/src/Microsoft/Data/SqlClient/TdsParser.cs 66.66% 2 Missing ⚠️
...tcore/src/Microsoft/Data/SqlClient/SNI/SNIProxy.cs 80.00% 1 Missing ⚠️
.../netcore/src/Microsoft/Data/SqlClient/TdsParser.cs 80.00% 1 Missing ⚠️

❗ There is a different number of reports uploaded between BASE (832e8da) and HEAD (3ca3de6). Click for more details.

HEAD has 1 upload less than BASE
Flag BASE (832e8da) HEAD (3ca3de6)
addons 1 0
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #3347      +/-   ##
==========================================
- Coverage   65.12%   58.79%   -6.34%     
==========================================
  Files         300      293       -7     
  Lines       65379    65213     -166     
==========================================
- Hits        42578    38340    -4238     
- Misses      22801    26873    +4072     
Flag Coverage Δ
addons ?
netcore 62.93% <78.72%> (-5.41%) ⬇️
netfx 59.73% <75.86%> (-6.65%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Copy link
Contributor

@paulmedynski paulmedynski left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some comments about handling multipe and single SPNs.

Copy link
Contributor

@paulmedynski paulmedynski left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Whoops - hit Comment instead of Request Changes

paulmedynski
paulmedynski previously approved these changes May 16, 2025
@twsouthwick twsouthwick changed the title Reset negotiateAuth if SNI doesn't work Rework initialization and calling of SspiContextProvider to ensure correct SPN May 16, 2025
@twsouthwick twsouthwick changed the title Rework initialization and calling of SspiContextProvider to ensure correct SPN Ensure correct SPN when calling SspiContextProvider May 16, 2025
paulmedynski
paulmedynski previously approved these changes May 20, 2025
paulmedynski
paulmedynski previously approved these changes May 23, 2025
@paulmedynski
Copy link
Contributor

Looks like some legitimate test failures for net8.0 and net9.0:

     System.InvalidCastException : Unable to cast object of type 'Microsoft.Data.SqlClient.SNI.ResolvedServerSpn' to type 'System.String'.
    Stack Trace:
       at Microsoft.Data.SqlClient.ManualTesting.Tests.InstanceNameTest.GetSPNInfo(String dataSource, String inInstanceName) in /_/src/Microsoft.Data.SqlClient/tests/ManualTests/SQL/InstanceNameTest/InstanceNameTest.cs:line 215

paulmedynski
paulmedynski previously approved these changes May 23, 2025
@twsouthwick twsouthwick requested a review from mdaigle May 23, 2025 20:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants