-
Notifications
You must be signed in to change notification settings - Fork 302
Integrated security on Linux requires a port number or protocol prefix in the connection string #627
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
Comments
I do see this documentation: https://docs.microsoft.com/en-us/previous-versions/system-center/configuration-manager-2007/bb632649(v=technet.10)?redirectedfrom=MSDN#required-communication-protocols But I'm not sure if that would mean there's no support for Named Pipes for Kerberos in driver. @saurabh500 |
Hi @cheenamalhotra, I'm trying to connect with TCP here, not with named pipes. |
This is TCP, default connection mechanism is Named Pipes for driver. |
Also - If you disable Named Pipes & Shared Memory on your target server, then driver will default to TCP. |
Oh OK, I thought that the driver first tried to connect with TCP and then tried named pipes if TCP failed. I guess I'd still expect the driver to try TCP if named pipes fail or to only try TCP if Kerberos is not supposed to work with named pipes. |
I checked with the server admin, and it turns out that named pipes are actually disabled on this server. I also made a quick check with
Which confirms that named pipes are disabled. I made sure that |
There's also Shared Memory protocol which is chosen default if you're connecting to SQL Server on the same machine. You can try to disable that to ensure you connect only with TCP. But as you said |
Thanks! That SQL Server is on a different machine, so I did not ask the server admin if the shared memory protocol is enabled or not. |
We do rely on the port number to create the SPN to authenticate to failing which we create a default SPN. I quickly browsed the code at https://github.com/dotnet/SqlClient/blob/master/src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/SqlClient/SNI/SNIProxy.cs#L344 With Kerberos Auth (which is the only kind of integrated auth supported on Linux in the driver) we construct the SPN of the server using the connectivity information in the following format. MSSQLSVC/hostname_with_reverse_dnsLookup:port If no port is specified then we try For SQL running on default port, we expect that the SQL Server admin has registered the SPN MSSQLSVC/hostname_with_reverse_dnsLookup in the AD along with MSSqlSvc/hostname_with_reverse_dnsLookup:1433 MSSQLSVC/hostname_with_reverse_dnsLookup On Windows this is not a problem because the Kerberos auth fails and the driver falls back to NTLM and there is no SPN in the picture there. Hence it seems more seamless, but for Kerberos we do depend on the SPN for SQL to be registered correctly. |
Hi @saurabh500, The server was initially registered with SPNs which all included the port number - the admin told me this was the best practice. Then we tried adding SPNs without the port, but the SqlClient didn't seem to connect better with this change. We only tested that quickly though, so we may have missed something. I'll show your message to the server admin on Monday, and I guess we'll double-check if the SPN without the port number was registered properly, and also if we are really inadvertently using NTLM on Windows. |
Hello @ltrzesniewski
Sounds good and it will be interesting to know more about this experiment.
I have observed that it takes sometimes for the new SPN registration to propagate, but I don't know what causes it. How long did you wait to try integrated authentication after you registered the SPN without the port number? I do agree that an SPN without a port number may not be desirable. @cheenamalhotra |
Yes, we were aware there's a propagation time, and we waited a few minutes after the change, but maybe that wasn't enough. We'll double check that. |
Here are the additional test results. Adding SPNs without the port number: The other day, we have added the following SPNs without the port number:
That didn't work. But the So today, we added the SPNs with
That SPN config allows SqlClient to connect fine from Linux when using the I can see the NTLM on Windows: We ran the following query on our servers, where Windows clients are connected using connection strings with SELECT auth_scheme FROM sys.dm_exec_connections None of the connected clients used NTLM (except for a single shared-memory connection). All SPNs configured on these servers include the port number. Summary To sum up, if we have a SQL Server with port numbers in all of its SPNs, and a connection string in the form
What is your recommendation as to the SPN configuration? Are we supposed to add SPNs without the port number, or should SqlClient be able to connect with this configuration? |
Hi @saurabh500
I checked with ODBC team internally, and they default to 1433 if no port is specified. If no port is specified, we should probably try: @ltrzesniewski |
Could you test again with this driver:
|
Thanks @cheenamalhotra ! I can confirm that this version works fine on Linux, and connects to a server with the port number in its SPN, when using a connection string like Will this change be backported to System.Data.SqlClient as well? |
Thanks for confirming. It depends on the impact of the issue and the bar is very high for backporting fixing to S.D.S since it's now in LTS servicing mode. Are you/your organization dependent on this issue and is it a blocker? |
No worries, it's not a blocker since adding Thanks! |
@cheenamalhotra i agree with bug evaluation. |
Describe the bug
When trying to use SqlClient on Linux with integrated security, I noticed that the following connection string:
Data Source=SQL_TEST;Integrated Security=true
Would result in the following error when trying to connect:
This connection string works fine on Windows.
The intriguing part is that the following connection strings work just fine on Linux as well:
Data Source=SQL_TEST,1433;Integrated Security=true
Data Source=tcp:SQL_TEST;Integrated Security=true
The machine is correctly configured and attached to the Active Directory with Kerberos. The user has a valid TGT.
After a quick look at the code, I guess the following condition may need to be updated:
SqlClient/src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/SqlClient/SNI/SNIProxy.cs
Line 336 in ead806e
Here's the full stack trace:
To reproduce
This can be reproduced with a simple test program run on Linux (just replace
SQL_TEST
with a valid SQL Server host name):Expected behavior
I expect the
Data Source=SQL_TEST;Integrated Security=true
connection string to work exactly the same way asData Source=SQL_TEST,1433;Integrated Security=true
on Linux.Further technical details
Microsoft.Data.SqlClient version: 2.0.0
.NET target: .NET Core 3.1
SQL Server version: SQL Server 2019
Operating system: Ubuntu 18.04 LTS
The text was updated successfully, but these errors were encountered: