Skip to content

Service principal name on linux uses instance name instead of port when using SSRP #3566

Description

@Hakon

Describe the bug

We're connecting to an SQL server using Data Source=<server>\<instance>; Integrated Security = true from linux. This first requests a port number from SSRP, and then requests a service ticket from kerberos.
Seeing from packet trace we see that the SPN requested uses instance name in the port field similar to issue #2187.

This is a problem because we cannot self-register SPNs for machines using instance name instead of port number in AD, so developer machines using connection string Data Source=.\SQLEXPRESS; Integrated Security = true (using our self-made SSRP-daemon) fails to fetch the ticket due to the incorrect principal name.

If i specify port number after the instance name, the SPN requested does not reference instance name but instead uses port number so this leads me to believe there is a bug in what SPN is requested when the port is resolved through SSRP.

To reproduce

Connect to an sql server named instance without port number so that SSRP is invoked. Using packet trace we observe that the ticket requested specifies instance name.

Expected behavior

I expect the service ticket requested to specify the port number per the docs similar to the issue #2187

Further technical details

Microsoft.Data.SqlClient version: 6.1.0-preview2.25178.5 (from nuget.org)
.NET target: .NET 8.0
SQL Server version: Any
Operating system: Ubuntu 25.04

Activity

  1. self-assigned this
    on Sep 16, 2025
  2. removed their assignment
    on Oct 28, 2025
  3. moved this from To triage to Backlog in SqlClient Boardon Nov 20, 2025
  4. moved this from Backlog to Needs Response in SqlClient Boardon Nov 21, 2025
  5. moved this from Needs Response to To triage in SqlClient Boardon Apr 1, 2026
  6. added a commit that references this issue on Apr 10, 2026
    da6afed
  7. moved this from To triage to In progress in SqlClient Boardon Apr 10, 2026
  8. paulmedynski commented on Apr 10, 2026

    @paulmedynski
    Contributor

    Root Cause Analysis

    This is the same class of bug as #2187, which was fixed in PR #2240 but only for the Protocol.TCP case.

    The Bug

    In SniProxy.netcore.cs — GetSqlServerSPNs(), the SPN postfix (port vs instance name) is selected with:

    postfix = dataSource.ResolvedProtocol == DataSource.Protocol.TCP
        ? dataSource.ResolvedPort.ToString()
        : dataSource.InstanceName;

    When connecting with Data Source=server\instance (no tcp: prefix), ResolvedProtocol is Protocol.None — not Protocol.TCP. The connection logic in CreateConnectionHandle correctly treats Protocol.None as TCP (falls through to CreateTcpHandle, which resolves the port via SSRP and sets ResolvedPort). But GetSqlServerSPNs only checked for Protocol.TCP exactly, so it took the else branch and used the instance name instead of the resolved port.

    The same issue applies to Protocol.Admin (DAC connections), which also uses TCP and resolves ports via SSRP.

    The Fix

    Inverted the condition: only Named Pipes (Protocol.NP) should use the instance name in the SPN. All other protocols use the resolved port:

    postfix = dataSource.ResolvedProtocol == DataSource.Protocol.NP
        ? dataSource.InstanceName
        : dataSource.ResolvedPort.ToString();

    Draft PR: #4180

  9. added this to the 7.1.0-preview1 milestone on Apr 10, 2026
  10. added a commit that references this issue on Apr 10, 2026
    f027453
  11. self-assigned this
    on Apr 29, 2026
  12. moved this from In progress to Done in SqlClient Boardon Jun 26, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

Projects

Relationships

None yet

Development

No branches or pull requests

Issue actions