Skip to content
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

NTLM support with Kestrel #14951

Closed
tornie2 opened this issue Oct 12, 2019 · 10 comments
Closed

NTLM support with Kestrel #14951

tornie2 opened this issue Oct 12, 2019 · 10 comments
Labels
area-auth Includes: Authn, Authz, OAuth, OIDC, Bearer

Comments

@tornie2
Copy link

tornie2 commented Oct 12, 2019

We were excited to see that NTLM and Negotiate are now supported in with Kestrel, as described here
https://docs.microsoft.com/en-us/aspnet/core/security/authentication/windowsauth?view=aspnetcore-3.0&tabs=visual-studio

However we have only been able to make this work with Negotiate, not NTLM.

Basically we have done what is described in the above article.
Added authentication to services:

        services.AddAuthentication(NegotiateDefaults.AuthenticationScheme).AddNegotiate();

and added Authentication to the pipeline
We also have our own simple check for authorization in the pipeline

        app.UseAuthentication();
        app.UseMiddleware<ValidateAuthentication>();

The ValidateAuthentication middleware is very simple:

internal class ValidateAuthentication : IMiddleware
{
    public async Task InvokeAsync(HttpContext context, RequestDelegate next)
    {
        if (context.User.Identity.IsAuthenticated)
            await next(context);
        else
            await context.ChallengeAsync();
    }
}

When a challenge is sent, we only see Negotiate

   WWW-Authenticate Negotiate

We would have expected NTLM as well. Something like

   WWW-Authenticate Negotiate,NTLM

Why is NTLM not supported by our Kestrel host as well?

The applications is tested on a Windows 10 machine in an enterprise environment using AD as identity system.

@jkotalik
Copy link
Contributor

Not 100% sure, but can you try calling the AddNegotiate overload that takes an auth scheme? https://github.com/aspnet/AspNetCore/blob/master/src/Security/Authentication/Negotiate/src/NegotiateExtensions.cs#L41

And there you can pass in Negotiate,NTLM.

@Tratcher to confirm.

@jkotalik jkotalik added the area-auth Includes: Authn, Authz, OAuth, OIDC, Bearer label Oct 14, 2019
@Tratcher
Copy link
Member

@jkotalik no, auth scheme is the internal identifier, not the header.

@Tratcher Tratcher self-assigned this Oct 14, 2019
@Tratcher
Copy link
Member

https://github.com/aspnet/AspNetCore/blob/21c9e2cc954c10719878839cd3f766aca5f57b34/src/Security/Authentication/Negotiate/src/NegotiateHandler.cs#L359
The challenge is not configurable for a variety of reasons:

  • This first version of the auth handler was focused exclusively on enabling Kerberos auth on Linux (via Negotiate). Anything else that happens to work is a bonus (e.g. Negotiate on Windows works).
  • Negotiate includes implicit fallback support for NTLM when required which is adequate for many scenarios.
  • NTLM is a very outdated protocol and should only be used as a Negotiate fallback, not directly.

FYI the new UseAuthorization middleware can replace your ValidateAuthentication middleware if you set the fallback policy to require auth.

What client and scenario do you have that requires direct NTLM usage?

@Tratcher Tratcher removed their assignment Oct 14, 2019
@tornie2
Copy link
Author

tornie2 commented Oct 15, 2019

Ok. Thanks @Tratcher

If your support is only for Negotiate, and has only been verified on Linux, then I think your documentation is a little misleading.

I understand from your reply that NTLM support from your side is about to end. We have a task in our organization then to move away from NTLM.

@Tratcher
Copy link
Member

only been verified on Linux,

We tested Windows too, but the windows support wasn't new functionality, that was already supported via other code paths.

I understand from your reply that NTLM support from your side is about to end. We have a task in our organization then to move away from NTLM.

NTLM will never go away completely, but you'd do best to avoid it.

@analogrelay
Copy link
Contributor

We don't have plans to add support for NTLM in Kestrel. If this kind of legacy support is necessary for you, there are still servers that support it (IIS and HttpSysServer). We have no plans to bring this legacy forward to Kestrel though.

@tornie2
Copy link
Author

tornie2 commented Oct 19, 2019

@anurse
Perfectly understandable. Of course you need to ditch legacy technologies at some point.

Only I still recommend that you revisit your documentation

This is not correct:

The Microsoft.AspNetCore.Authentication.Negotiate NuGet package can be used with Kestrel to support Windows Authentication using Negotiate, Kerberos, and NTLM on Windows, Linux, and macOS.

@analogrelay
Copy link
Contributor

Only I still recommend that you revisit your documentation

Fair point. NTLM is, I believe, still supported on Windows because the native components we use support it. We should update that to indicate that we don't support NTLM on Linux. (At least that's my understanding, @Tratcher can confirm in the docs PR I'm about to open :))

@Tratcher
Copy link
Member

CoreFx recently identified a bug that was preventing NTLM from working via Negotiate on Linux, they'll get that working at some point.

The point at issue here is that NTLM is not directly supported on any platform because you can't make NTLM the auth header challenge, you can only use it as a Negotiate fallback.

@tornie2
Copy link
Author

tornie2 commented Oct 22, 2019

@anurse
What @Tratcher describes is exactly the problem we ran in to. We are using C# HttpClient with NTLM credentials, and it will not respond to a challange with Negotiate only.

My understanding of NTLM, is that it is based on challange / response. I don't see how NTLM could work at all, if there is no challange?

@dotnet dotnet locked as resolved and limited conversation to collaborators Dec 2, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-auth Includes: Authn, Authz, OAuth, OIDC, Bearer
Projects
None yet
Development

No branches or pull requests

4 participants