Mastering UseManagedNtlm on .NET 10 & .NET 8

I recently needed to make call to a API which use NTLM auth. It worked like a charm on Windows but I struggle on Linux Containers. You could find some tips on the Internet to install the gss-ntlmssp native lib in order to help but be careful, there’s also a strange behavior for the actual version (1.2.0-1build3) through apt-get for aspnet10 noble.

Reminder

The EWS WebService answer add these headers at first request :

WWW-Authenticate: Negotiate
WWW-Authenticate: NTLM

It means .NET will try 2 different authentication, first Negotiate, then NTLM

  1. Negotiate => will use Interop (gss-ntlmssp for Linux)
  2. NTLM => will use Managed (if UseManagedNtlm=true)

On Linux, if the lib gss-ntlmssp is not installed,

.NET 10 (via Linux Noble)

UseManagedNtlmgss-ntlmsspResultRemarks
FalseNot installedFail1. Cannot use Interop for Negotiate
2. Cannot use Interop for NTLM
False1.2.1-build3 (apt-get)Fail1. Use Interop for Negotiate
2. Cannot use Interop for NTLM
False1.3.1 (compiled from sources)Fail1. Use Interop for Negotiate
2. Cannot use Interop for NTLM
True1.2.1-build3 (apt-get)Fail1. Use Interop for Negotiate
2. Use Managed for NTLM

the gss-ntlmssp version seems broken
True1.3.1 (compiled from sources)Ok1. Use Interop for Negotiate
2. Use Managed for NTLM
TrueNot installedOk1. Use Managed for NTLM

Will only work for NTLM, no Kerberos

Solution

Based on my dig, in order to make Negotiate and NTLM and Kerberos you need to :

  • 1. Compile and install gss-ntlmssp latest version 1.3.1
  • 2. Enable UseManagedNtlm by AppSwitch in your code
if (OperatingSystem.IsLinux())
{
    // We need to do that to be able to authenticate on Linux with EWS that uses NTLM under the hood
    AppContext.SetSwitch("System.Net.Security.UseManagedNtlm", true);
}
  • 3. install these extra libs
    • libgssapi-krb5-2
    • krb5-user
    • libkrb5-3

Ce contenu a été publié dans Non classé. Vous pouvez le mettre en favoris avec ce permalien.