runtime icon indicating copy to clipboard operation
runtime copied to clipboard

HttpClient sends NTLM ticket, even though it only has Negotiate credentials

Open tornie2 opened this issue 6 years ago • 3 comments

We are puzzled that HttpClient will use NTLM token for authorization, even though will only give the handler Negotiate credentials

Our application is in net461. We create our client with this code

         _credentials = new CredentialCache { { _uri, "Negotiate", CredentialCache.DefaultNetworkCredentials } };
         var handler = new WebRequestHandler { Credentials = _credentials, UnsafeAuthenticatedConnectionSharing = true, MaxConnectionsPerServer = 100, UseProxy = false };
         var httpClient = new HttpClient(handler) { BaseAddress = _uri };

When we access a node directly without a load-balancer, we can nicely see a Negotiate authorization.

However when we access the system through the load-balancer, the Authorization in the request contains a Negotiate item, but when we open the token (base64 decode it), we can see that it actually is a NTLM-token

The challenge from the server has this header: Proxy-Authenticate NTLM, Negotiate, Bearer

The response to the service looks something like this. Authorization says Negotiate, but when we decode the token, it is ntlm Authorization Negotiate TlRMTVNT..... Host syst-smfbasic:15000 CorrelationId 72395ff4-4fa9-4d5d-88c1-0d96b49da63c

Why will webrequesthandler generate an NTLM-token when we specifically ask for Negotiate, and write Negotiate in the header, when it actually is NTLM?

And why only when we use a load-balancer?

tornie2 avatar Dec 16 '19 12:12 tornie2

Why will webrequesthandler generate an NTLM-token when we specifically ask for Negotiate, and write Negotiate in the header, when it actually is NTLM?

In general, this behavior is by-design.

Windows implements the Negotiate scheme to send either Kerberos or NTLM. It is something that is "negotiated". NTLM is used instead of Kerberos if the server/proxy is not domain joined, or a local account is used etc. This is called "NTLM fallback". Specially, Windows will use a base64 raw NTLM token (or a GSS-API wrapped NTLM token) for the 'Negotiate' scheme.

See: https://blogs.msdn.microsoft.com/dsnotes/2015/12/30/negotiate-vs-ntlm/

When we access a node directly without a load-balancer, we can nicely see a Negotiate authorization.

In your scenario, it is likely that the load balancer is interfering with the use of Kerberos. It's possible you need additional SPNs (Service Principal Name) defined.

These scenarios are difficult to diagnose and we recommend contacting Product Support who can provide detailed steps to help you diagnose your network.

If NTLM is something that you want to prevent completely, there are ways to disable NTLM support in your Windows clients/servers.

davidsh avatar Dec 16 '19 14:12 davidsh

Here are some additional resources to help diagnose Kerberos issues on Windows: https://blogs.technet.microsoft.com/askds/2012/07/27/kerberos-errors-in-network-captures/

davidsh avatar Dec 17 '19 02:12 davidsh

Thanks David I will work with our network- and AD-team to locate the problem.

tornie2 avatar Dec 17 '19 06:12 tornie2