Skip to content

GSS/SSPI authentication fails with SecurityQosFailed on .NET 11 when Windows falls back to NTLM #6660

Closed

Description

@wickedmachinator

On .NET 11 RC1, Windows integrated authentication to a PostgreSQL server configured with sspi fails when the Negotiate package falls back to NTLM, for example with Host=localhost, a host given by IP address, or a server without a registered postgres/ SPN:

Npgsql.NpgsqlException: Error while authenticating GSS/SSPI: SecurityQosFailed

The same Npgsql 10.0.3 binary connects on .NET 10, and psql connects to the same server as the same user.

Cause

AuthenticateGSS (src/Npgsql/Internal/NpgsqlConnector.Auth.cs) creates the NegotiateAuthentication with mutual authentication required:

var clientOptions = new NegotiateAuthenticationClientOptions
{
  TargetName = targetName,
  RequireMutualAuthentication = true
};

NTLM does not authenticate the server, so the requirement cannot be met. On .NET 10, GetOutgoingBlob continued anyway. On .NET 11, it returns NegotiateAuthenticationStatusCode.SecurityQosFailed for the server's challenge, and Npgsql throws.

libpq does not require mutual authentication on Windows. Its SSPI path (pg_SSPI_continue in src/interfaces/libpq/fe-auth.c) calls InitializeSecurityContext with ISC_REQ_ALLOCATE_MEMORY only. Only its GSSAPI path sets GSS_C_MUTUAL_FLAG.

Repro

pg_hba.conf, with the Windows account mapped to the role admin:

host    all    admin    127.0.0.1/32    sspi    include_realm=0
host    all    admin    ::1/128         sspi    include_realm=0
using System.Runtime.InteropServices;
using Npgsql;

const string cs = "Host=localhost;Port=5432;Database=test;Username=admin";

foreach (var mutual in new[] { true, false })
{
  var builder = new NpgsqlDataSourceBuilder(cs);
  builder.UseNegotiateOptionsCallback(o => o.RequireMutualAuthentication = mutual);
  try
  {
	  await using var source = builder.Build();
	  await using var connection = await source.OpenConnectionAsync();
	  Console.WriteLine($"{RuntimeInformation.FrameworkDescription}, mutual={mutual}: connected");
  }
  catch (Exception e)
  {
	  Console.WriteLine($"{RuntimeInformation.FrameworkDescription}, mutual={mutual}: {e.Message}");
  }
}
Runtime RequireMutualAuthentication = true (Npgsql's setting) false
.NET 10.0.12 connected connected
.NET 11.0.0-rc.1.26425.128 Error while authenticating GSS/SSPI: SecurityQosFailed connected
new NpgsqlConnection(cs).Open() fails the same way as the first column on .NET 11. GSS Encryption Mode makes no difference; Prefer and Disable behave the same.

Environment

  • Npgsql 10.0.3
  • .NET 11.0.0-rc.1.26425.128 and .NET 10.0.12
  • Windows 11 (10.0.26200), x64
  • PostgreSQL 18.0 for Windows (x86_64-windows, MSVC build)

Suggestion

Requiring mutual authentication only when it can be provided, for example not when the Negotiate package is used through SSPI, would match libpq on Windows and restore the .NET 10 behavior. The workaround today, UseNegotiateOptionsCallback, exists only on the data source builders, so an application that opens NpgsqlConnection from a connection string cannot apply it.

Activity

  1. self-assigned this
    on Oct 2, 2026
  2. added theissue type on Oct 2, 2026
  3. added this to the 10.0.4 milestone on Oct 2, 2026
  4. vonzshik commented on Oct 2, 2026

    @vonzshik
    Contributor

    Ugh. Yeah, I only looked at what libpq did for kerberos but didn't check sspi path. Will fix it for 10.0.4 and 11. Thanks!

  5. wickedmachinator commented on Oct 2, 2026

    @wickedmachinator
    Author

    Ugh. Yeah, I only looked at what libpq did for kerberos but didn't check sspi path. Will fix it for 10.0.4 and 11. Thanks!

    thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions