Repository navigation
Fix NegotiateAuthentication to surface TargetUnknown status for unknown SPNs - #126623
Conversation
…nknown SPN - Windows: Add SecurityStatusPalErrorCode.TargetUnknown mapping to NegotiateAuthenticationStatusCode.TargetUnknown - Unix: Handle GSS_S_FAILURE with KRB5KDC_ERR_S_PRINCIPAL_UNKNOWN minor status to return TargetUnknown Agent-Logs-Url: https://github.com/dotnet/runtime/sessions/cf7ddabe-e0b2-43dc-b16d-ea550f2e080a Co-authored-by: wfurt <[email protected]>
|
Tagging subscribers to this area: @dotnet/ncl, @bartonjs, @vcsjones |
|
Can we add enterprise tests for this? |
|
@copilot can you add some tests for this change? Using either FakeNtlmServer or KerberosExecutor |
Co-authored-by: rzikm <[email protected]>
Added |
There was a problem hiding this comment.
Pull request overview
This PR fixes NegotiateAuthentication status-code mapping so that an unknown target SPN surfaces as NegotiateAuthenticationStatusCode.TargetUnknown (instead of GenericFailure) across both Windows (SSPI) and Unix (GSSAPI/Kerberos).
Changes:
- Windows: map
SecurityStatusPalErrorCode.TargetUnknowntoNegotiateAuthenticationStatusCode.TargetUnknown. - Unix: treat
GSS_S_FAILURE+ Kerberos minor status for “server principal unknown” asTargetUnknown. - Tests: add a Kerberos functional test that authenticates to an unregistered SPN and asserts
TargetUnknown.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| src/libraries/System.Net.Security/tests/FunctionalTests/NegotiateAuthenticationKerberosTest.cs | Adds regression test asserting unknown SPN returns TargetUnknown. |
| src/libraries/System.Net.Security/src/System/Net/NegotiateAuthenticationPal.Windows.cs | Fixes SSPI error-to-status mapping for TargetUnknown. |
| src/libraries/System.Net.Security/src/System/Net/NegotiateAuthenticationPal.Unix.cs | Adds Kerberos-specific mapping from GSS_S_FAILURE minor status to TargetUnknown. |
…wn SPNs (#126623) `NegotiateAuthentication` returned `GenericFailure` instead of `TargetUnknown` when the target SPN does not exist in the KDC — both on Windows (SSPI) and Unix (GSSAPI/Kerberos). ## Description **Windows** (`NegotiateAuthenticationPal.Windows.cs`): `SecurityStatusPalErrorCode.TargetUnknown` was missing from the `SecurityStatusPalErrorCode` → `NegotiateAuthenticationStatusCode` switch, causing it to fall through to `default` (`GenericFailure`). **Unix** (`NegotiateAuthenticationPal.Unix.cs`): `GSS_S_FAILURE` was unhandled in `GetErrorCode`. When the major status is `GSS_S_FAILURE` and the minor status is `KRB5KDC_ERR_S_PRINCIPAL_UNKNOWN` (`0x96C73A07` — the `com_err`-based Kerberos error, identical in MIT and Heimdal Kerberos), the method now returns `TargetUnknown`. ```csharp // Before: returned GenericFailure when target SPN doesn't exist // After: var client = new NegotiateAuthentication(new NegotiateAuthenticationClientOptions { TargetName = "HTTP/nonexistent-server.example.com" }); client.GetOutgoingBlob(null, out var statusCode); // statusCode == NegotiateAuthenticationStatusCode.TargetUnknown ✓ ``` **Test** (`NegotiateAuthenticationKerberosTest.cs`): Added `Client_UnknownSPN_ReturnsTargetUnknown` using `KerberosExecutor`. The test spins up a fake in-process KDC with a registered service and user, then attempts Kerberos authentication (`Package = "Kerberos"`) to an unregistered SPN (`HTTP/nonexistent.linux.contoso.com`). This exercises the `GSS_S_FAILURE`/`KRB5KDC_ERR_S_PRINCIPAL_UNKNOWN` code path and asserts that `GetOutgoingBlob` returns `NegotiateAuthenticationStatusCode.TargetUnknown`. --------- Co-authored-by: copilot-swe-agent[bot] <[email protected]> Co-authored-by: wfurt <[email protected]> Co-authored-by: rzikm <[email protected]>
NegotiateAuthenticationreturnedGenericFailureinstead ofTargetUnknownwhen the target SPN does not exist in the KDC — both on Windows (SSPI) and Unix (GSSAPI/Kerberos).Description
Windows (
NegotiateAuthenticationPal.Windows.cs):SecurityStatusPalErrorCode.TargetUnknownwas missing from theSecurityStatusPalErrorCode→NegotiateAuthenticationStatusCodeswitch, causing it to fall through todefault(GenericFailure).Unix (
NegotiateAuthenticationPal.Unix.cs):GSS_S_FAILUREwas unhandled inGetErrorCode. When the major status isGSS_S_FAILUREand the minor status isKRB5KDC_ERR_S_PRINCIPAL_UNKNOWN(0x96C73A07— thecom_err-based Kerberos error, identical in MIT and Heimdal Kerberos), the method now returnsTargetUnknown.Test (
NegotiateAuthenticationKerberosTest.cs): AddedClient_UnknownSPN_ReturnsTargetUnknownusingKerberosExecutor. The test spins up a fake in-process KDC with a registered service and user, then attempts Kerberos authentication (Package = "Kerberos") to an unregistered SPN (HTTP/nonexistent.linux.contoso.com). This exercises theGSS_S_FAILURE/KRB5KDC_ERR_S_PRINCIPAL_UNKNOWNcode path and asserts thatGetOutgoingBlobreturnsNegotiateAuthenticationStatusCode.TargetUnknown.