Repository navigation
Fall back to NTLM in managed SPNEGO when Kerberos credentials are missing on Unix - #131195
Conversation
…sing on Unix When the managed Negotiate (SPNEGO) implementation offers Kerberos as the optimistic mechanism and no usable KDC/TGT is available, the GSS-API reports GSS_S_NO_CRED, which maps to NegotiateAuthenticationStatusCode.UnknownCredentials. Previously this status was only treated as a recoverable optimistic failure on OpenBSD (Heimdal). On Linux (MIT krb5) the same condition aborted the whole exchange instead of falling back to NTLM, so managed NTLM over HTTP failed with 401 whenever a Kerberos mechanism was advertised but no KDC was reachable. Treat UnknownCredentials as a recoverable optimistic failure on all Unix platforms so SPNEGO falls back from Kerberos to NTLM. NTLM remains the last offered mechanism and is guarded by canFallBackToNextMechanism, so a genuine UnknownCredentials from NTLM itself (e.g. missing default credentials) still propagates unchanged. Fixes dotnet#122895 Co-authored-by: Copilot <[email protected]> Copilot-Session: aef7f3d9-743f-4149-acd6-ad2bc62c12d2
|
Azure Pipelines: Successfully started running 4 pipeline(s). 12 pipeline(s) were filtered out due to trigger conditions. There may be pipelines that require an authorized user to comment /azp run to run. |
|
Tagging subscribers to this area: @dotnet/ncl, @bartonjs, @vcsjones |
There was a problem hiding this comment.
Pull request overview
This PR adjusts the managed SPNEGO (Negotiate) optimistic mechanism selection on Unix so that when an initial Kerberos attempt fails with NegotiateAuthenticationStatusCode.UnknownCredentials, the implementation treats it as a recoverable optimistic failure and continues to the next mechanism (NTLM), rather than aborting the whole exchange.
Changes:
- Treat
UnknownCredentialsas a recoverable optimistic failure for non-NTLM mechanisms on Unix, enabling Kerberos → NTLM fallback in managed SPNEGO. - Update the in-code comment describing the rationale for the fallback behavior.
There was a problem hiding this comment.
I don't think we should unconditionally fallback on NegotiateAuthenticationStatusCode.UnknownCredentials. This should only be done if _clientOptions.Credential were the default credentials. If the client sent their own password credentials and Kerberos rejected them then presumably we should still fail instead of trying to fallback to NTLM.
UPD: On a second thought, we would not succeed with the default credentials in managed NTLM either, so fallback in that case doesn't make sense to me either.
Okay, I think I understand the motivation now. If no Kerberos server can be reached with password based credentials and the native implementation returns GSS_S_NO_CRED then possibly we can make the fallback. I'm just not sure if there's any devil in the details where the error could be returned after some Kerberos validation, which could possibly be a downgrade attack.
A downgrade is possible if attacker can prevent clients from reaching the KDC, that is a really strong precondition, so I don't think it is interesting. Besides if downgrade to NTLM is undesired, then server should be configured to refuse it anyway. |
|
while NTLM is discouraged in general, I' wonder if we have something exploit in our documentation ... and if not, should we add some note? |
…sing on Unix (dotnet#131195) ## Summary Fixes dotnet#122895. When the **managed** Negotiate (SPNEGO) implementation offers Kerberos as the optimistic mechanism and no usable KDC/TGT is available, the GSS-API reports `GSS_S_NO_CRED`, which maps to `NegotiateAuthenticationStatusCode.UnknownCredentials`. Previously this status was only treated as a *recoverable* optimistic failure on **OpenBSD** (Heimdal). On **Linux (MIT krb5)** the same condition aborted the whole exchange instead of falling back to NTLM, so managed NTLM over HTTP (e.g. EWS/Exchange with `AppContext.SetSwitch("System.Net.Security.UseManagedNtlm", true)`) failed with **401** whenever a Kerberos mechanism was advertised but no KDC was reachable — the exact scenario in dotnet#122895 on the Ubuntu Noble .NET 10 image with `gss-ntlmssp` installed. This change treats `UnknownCredentials` as a recoverable optimistic failure on **all Unix** platforms, so SPNEGO falls back from Kerberos to NTLM. NTLM remains the last offered mechanism and is guarded by `canFallBackToNextMechanism`, so a genuine `UnknownCredentials` originating from NTLM itself (e.g. missing default credentials, see dotnet#91160) still propagates unchanged. ## Why the previously merged change (dotnet#123003) was not enough dotnet#123003 made `HasSystemNetSecurityNative` (and thus `supportKerberos`) `true` whenever the native GSS-API library loads. That does **not** address the reporter's configuration (with `gss-ntlmssp` installed, `supportKerberos` was already `true`), and on its own it *regresses* the `gss-ntlmssp`-absent configuration, because Kerberos then starts being offered optimistically and hits the same missing-fallback path. The real fix is the fallback change here; combined with dotnet#123003 both configurations work. ## Empirical validation Because a full test host could not be built in the dev environment (an unrelated clang internal compiler crash), the fix was validated by building real `System.Net.Security.dll` variants and running an NTLM/Negotiate HTTP handshake against a reference server on a private copy of the 10.0.9 shared framework: | Variant | `UseManagedNtlm=true`, gss-ntlmssp **absent** | `UseManagedNtlm=true`, gss-ntlmssp **present** (reporter) | |---|---|---| | baseline (no fix) | 200 | **401 (bug)** | | dotnet#123003 only | **401 (regression)** | 401 | | **fallback fix (this PR)** | 200 | **200** | | dotnet#123003 + fallback fix | 200 | 200 | ## Notes - The managed unit test `DefaultNetworkCredentials_NTLM_DoesNotThrow` (which asserts `UnknownCredentials` for the direct `NTLM` package) is unaffected: this change only alters non-NTLM optimistic mechanisms in the SPNEGO path. - Consider backporting to `release/10.0` together with dotnet#123003. > [!NOTE] > This pull request was authored by GitHub Copilot (CLI). Co-authored-by: Copilot <[email protected]> Copilot-Session: aef7f3d9-743f-4149-acd6-ad2bc62c12d2
Summary
Fixes #122895.
When the managed Negotiate (SPNEGO) implementation offers Kerberos as the optimistic mechanism and no usable KDC/TGT is available, the GSS-API reports
GSS_S_NO_CRED, which maps toNegotiateAuthenticationStatusCode.UnknownCredentials. Previously this status was only treated as a recoverable optimistic failure on OpenBSD (Heimdal). On Linux (MIT krb5) the same condition aborted the whole exchange instead of falling back to NTLM, so managed NTLM over HTTP (e.g. EWS/Exchange withAppContext.SetSwitch("System.Net.Security.UseManagedNtlm", true)) failed with 401 whenever a Kerberos mechanism was advertised but no KDC was reachable — the exact scenario in #122895 on the Ubuntu Noble .NET 10 image withgss-ntlmsspinstalled.This change treats
UnknownCredentialsas a recoverable optimistic failure on all Unix platforms, so SPNEGO falls back from Kerberos to NTLM. NTLM remains the last offered mechanism and is guarded bycanFallBackToNextMechanism, so a genuineUnknownCredentialsoriginating from NTLM itself (e.g. missing default credentials, see #91160) still propagates unchanged.Why the previously merged change (#123003) was not enough
#123003 made
HasSystemNetSecurityNative(and thussupportKerberos)truewhenever the native GSS-API library loads. That does not address the reporter's configuration (withgss-ntlmsspinstalled,supportKerberoswas alreadytrue), and on its own it regresses thegss-ntlmssp-absent configuration, because Kerberos then starts being offered optimistically and hits the same missing-fallback path. The real fix is the fallback change here; combined with #123003 both configurations work.Empirical validation
Because a full test host could not be built in the dev environment (an unrelated clang internal compiler crash), the fix was validated by building real
System.Net.Security.dllvariants and running an NTLM/Negotiate HTTP handshake against a reference server on a private copy of the 10.0.9 shared framework:UseManagedNtlm=true, gss-ntlmssp absentUseManagedNtlm=true, gss-ntlmssp present (reporter)Notes
DefaultNetworkCredentials_NTLM_DoesNotThrow(which assertsUnknownCredentialsfor the directNTLMpackage) is unaffected: this change only alters non-NTLM optimistic mechanisms in the SPNEGO path.release/10.0together with Fix detection of System.Net.Security.Native #123003.Note
This pull request was authored by GitHub Copilot (CLI).