runtime: SocketsHttpHandler: NTLM auth does not work by default on Unix
HttpClient with credentials explicitly set. SocketHttpHandler throws on NTLM authentication requested by server:
System.ComponentModel.Win32Exception (0x80090020): GSSAPI operation failed with error - An invalid status code was supplied (Unknown error).
at System.Net.Security.NegotiateStreamPal.AcquireCredentialsHandle(String package, Boolean isServer, NetworkCredential credential) in /home/build/github/corefx/src/Common/src/System/Net/Security/NegotiateStreamPal.Unix.cs:line 316
at System.Net.NTAuthentication.Initialize(Boolean isServer, String package, NetworkCredential credential, String spn, ContextFlagsPal requestedContextFlags, ChannelBinding channelBinding) in /home/build/github/corefx/src/Common/src/System/Net/NTAuthentication.Common.cs:line 128
at System.Net.NTAuthentication..ctor(Boolean isServer, String package, NetworkCredential credential, String spn, ContextFlagsPal requestedContextFlags, ChannelBinding channelBinding) in /home/build/github/corefx/src/Common/src/System/Net/NTAuthentication.Common.cs:line 98
at System.Net.Http.AuthenticationHelper.SendWithNtAuthAsync(HttpRequestMessage request, Uri authUri, ICredentials credentials, Boolean isProxyAuth, HttpConnection connection, CancellationToken cancellationToken) in /home/build/github/corefx/src/System.Net.Http/src/System/Net/Http/SocketsHttpHandler/AuthenticationHelper.NtAuth.cs:line 61
at System.Net.Http.HttpConnectionPool.SendWithRetryAsync(HttpRequestMessage request, Boolean doRequestAuth, CancellationToken cancellationToken) in /home/build/github/corefx/src/System.Net.Http/src/System/Net/Http/SocketsHttpHandler/HttpConnectionPool.cs:line 283
at System.Net.Http.AuthenticationHelper.SendWithAuthAsync(HttpRequestMessage request, Uri authUri, ICredentials credentials, Boolean preAuthenticate, Boolean isProxyAuth, Boolean doRequestAuth, HttpConnectionPool pool, CancellationToken cancellationToken) in /home/build/github/corefx/src/System.Net.Http/src/System/Net/Http/SocketsHttpHandler/AuthenticationHelper.cs:line 204
at System.Net.Http.HttpClient.FinishSendAsyncBuffered(Task`1 sendTask, HttpRequestMessage request, CancellationTokenSource cts, Boolean disposeCts) in /home/build/github/corefx/src/Sys
Workarounds:
- Install package called
gss-ntlmssp(plugin into MIT Kerberos GSSAPI layer) - Install Heimdal (alternative Kerberos implementation with NTLM support): https://www.h5l.org/manual/heimdal-1-5-branch/ntlm/
One of the options installed is sufficient to make SocketHttpHandler work for NTLM without any additional changes to CoreFX or the app.
Details: .NET Core 2.0 / 2.1 with libcurl works fine. This is because curl has it’s own implementation but SocketHttpHandler depends on authentication code shared with NegotiateStream class.
The shared authentication depends on GSSAPI and that is typically provided by MIT kerberos. (this is also true for 2.1.300 preview docker images) It does not have ability to do NTLM.
This is follow up on dotnet/runtime#25370 and dotnet/runtime#25368. This may be also related to https://github.com/dotnet/wcf/issues/943
About this issue
- Original URL
- State: closed
- Created 6 years ago
- Reactions: 11
- Comments: 27 (11 by maintainers)
@ncsurfus the
AppContext.SetSwitchworkaround you suggested worked perfectly and saved our project a lot of time. Thanks.I am using
microsoft/dotnet:2.1-aspnetcore-runtimeimage, and I did installgss-ntlmssp. It makes theGSSAPI operation failederror go away.However, then I get
System.PlatformNotSupportedException: No support for channel binding on operating systems other than Windows.Is there another package I’m missing?
Hi folks,
I having some issue getting the workaround working.
Im am using the following to build a docker image.
When I run this overriding the entrypoint i can confirm gss-ntlmssp is installed by attempting to install it again. It tells me the latest is installed.
I still get this thrown tho.
Adding the following stops the error occurring but then my request returns a 401.
Running the exact same code locally on my windows 10 box works perfectly.
We seem to be getting this error all the time for any https site using NTLM even if Extended Protection (i.e. “channel binding”) is OFF.
So, at a minimum, this should get fixed to at least support NTLM connections where channel binding is Off or Accept’d.
I’d also like to note that switching back to the libcurl implementation
AppContext.SetSwitch("System.Net.Http.UseSocketsHttpHandler", false);is what I did as a work-around to get NTLM working properly on Linux… hopefully this can be fixed/implemented.Yes, it would be nice to have specific exception with reason “NTLM is not supported by the underlying OS” with permalink to article with potential workarounds. Assuming we can detect from the GSSAPI error code that the root-cause is missing support for NTLM and nothing else.
Just adding confirmation that upgrading to dotnet 3 fixed this issue for us.
Thanks all.
After looking through this thread and investigating all the mentioned problems, I have split this issue into new issues and will be closing this issue.
New issues:
@AlexanderLeonov we had issues with both NTLM and then with HTTPS connections in .NET Core 2.1 For the NTLM issue we just felled back to using LibCurl implementation of HttpClient using the
AppContext.SetSwitch("System.Net.Http.UseSocketsHttpHandler", false);. Then the NTLM worked fine but we had issues with HTTPS requests to reCaptcha service. THe app was crashing wt Segmentation Fault. We used self-contained mode for the app. The problem was that in our environment (Ubuntu 14.04) theSystem.Net.Http.Native.dllwas linked against libcurl.1.0.0 and our application during run-time was loading the libcurl.1.0.2. Our workaround was to copy libcurl.1.0.0 in our app folder and setting an environmental variable that was adding that folder to the library lookup path.@ncsurfus @greggbjensen I’m having the same issue. In my case though it is strictly tied to connection over https. It works fine if I just change url to http.
Can someone elaborate a bit on this message? What are those “channel bindings” that are not supported on linux? Is there any fix/workaround for this issue? Using http scheme is not an option in our case cause it is a connection over the internet transferring potentially sensitive information.