SqlClient: Kerberos authentication doesn't work with NuGet package 2.1.0

Can’t authenticate with SQL Server 2014 using new 2.1.0. Switching back to 1.1.3 works.

Exception:

Cannot authenticate using Kerberos. Ensure Kerberos has been initialized on the client with 'kinit' and a Service Principal Name has been registered for the SQL Server to allow Kerberos authentication.
ErrorCode=InternalError, Exception=Interop+NetSecurityNative+GssApiException: GSSAPI operation failed with error - Unspecified GSS failure.  Minor code may provide more information (Server not found in Kerberos database).
   at System.Net.Security.NegotiateStreamPal.GssInitSecurityContext(SafeGssContextHandle& context, SafeGssCredHandle credential, Boolean isNtlm, SafeGssNameHandle targetName, GssFlags inFlags, Byte[] buffer, Byte[]& outputBuffer, UInt32& outFlags, Int32& isNtlmUsed)
   at System.Net.Security.NegotiateStreamPal.EstablishSecurityContext(SafeFreeNegoCredentials credential, SafeDeleteContext& context, String targetName, ContextFlagsPal inFlags, SecurityBuffer inputBuffer, SecurityBuffer outputBuffer, ContextFlagsPal& outFlags)
   at Microsoft.Data.SqlClient.SNI.SNIProxy.GenSspiClientContext(SspiClientContextStatus sspiClientContextStatus, Byte[] receivedBuff, Byte[]& sendBuff, Byte[] serverName)
   at Microsoft.Data.SqlClient.SNI.TdsParserStateObjectManaged.GenerateSspiClientContext(Byte[] receivedBuff, UInt32 receivedLength, Byte[]& sendBuff, UInt32& sendLength, Byte[] _sniSpnBuffer)
   at Microsoft.Data.SqlClient.TdsParser.SNISSPIData(Byte[] receivedBuff, UInt32 receivedLength, Byte[]& sendBuff, UInt32& sendLength)

Image configuration:

FROM mcr.microsoft.com/dotnet/aspnet:5.0.0-buster-slim AS base
RUN sed -i 's/DEFAULT@SECLEVEL=2/DEFAULT@SECLEVEL=1/g' /etc/ssl/openssl.cnf && \
	sed -i 's/MinProtocol = TLSv1.2/MinProtocol = TLSv1/g' /etc/ssl/openssl.cnf && \
	sed -i 's/DEFAULT@SECLEVEL=2/DEFAULT@SECLEVEL=1/g' /usr/lib/ssl/openssl.cnf && \
	sed -i 's/MinProtocol = TLSv1.2/MinProtocol = TLSv1/g' /usr/lib/ssl/openssl.cnf

About this issue

  • Original URL
  • State: closed
  • Created 4 years ago
  • Reactions: 35
  • Comments: 15 (8 by maintainers)

Commits related to this issue

Most upvoted comments

Same problem (Except using TLSv1.0), regression in 2.1.0

image dotnet SqlClient version result
3.1 bionic 3.1 2.0.1 Success
3.1 bionic 3.1 2.1 Exception
5.0 focal 5.0 2.0.1 Success
5.0 focal 5.0 2.1 Exception

@karinazhou to izolate the issue even more it was introduced between preview1 and preview2. Your PR#629 is before that. My guess is src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/SqlClient/SqlSecurityUtility.cs from #699 where aes256-cts was removed. This is exactly the cipher I use in my service.keytab.

@karinazhou I can confirm, that your patch is working.

@mashbrno Could you try this nuget package to see if it fixes your issue? I test it locally and it works for me.

Nuget.zip

@karinazhou Of course I didn’t share my Active Directory neither whole SQL server with it. Feel free to generate your valid credentials with this commands:

printf "%b"   "addent -password -p myUser@AD.DATA3S.COM -k 1 -e   aes256-cts-hmac-sha1-96\npassword\nwrite_kt service.keytab" |   ktutil

You will also need to modify krb5.conf to match your setup.

@mashbrno I tried with your sample app on my side but I got the Server not found or not accessible exception with SqlClient 2.0.1. I look into the launch.sh and execute the first line. It looks like the key tab file is missing in my docker container. Did I miss some configuration?

root@1f04b264eefd:/etc# user=`klist -k service.keytab | grep 1 | sed -n -e 's/^.* //p'`
klist: Key table file 'service.keytab' not found while starting keytab scan