You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Question about default GSS encryption mode in Npgsql 10.0 #6360
After upgrading to .NET 10.0 and Npgsql 10.0, I encountered the following error:
Cannot load library libgssapi_krb5.so.2: cannot open shared object file: No such file or directory
I investigated and found that:
Since .NET 8.0, Microsoft’s official Debian/Alpine container images no longer include Kerberos libraries (docs).
Starting from Npgsql 10.0, the PostgreSQL client defaults to GssEncryptionMode.Prefer (PR #6324).
This combination causes applications running in official .NET container images to fail at startup unless Kerberos libraries are manually installed.
My questions:
Is there any plan to change the default from GssEncryptionMode.Prefer to GssEncryptionMode.Disable, to avoid breaking scenarios where Kerberos is not intended to be used?
If not, should this change be explicitly mentioned in the release notes, so users are aware that Kerberos libraries are now required unless they override the setting?
Thanks for your great work on Npgsql!
Reacted by Joshua Nixon, Oleksii Kavka and Valeriia Nesterova
I’ve investigated the exception further and found that it originates in the .NET runtime’s native interop layer (System.Net.Security.Native/pal_gssapi.c). When libgssapi_krb5.so.2 is missing, the runtime’s native code attempts to call into GSSAPI and fails. This failure is not surfaced as a typical managed DllNotFoundException or EntryPointNotFoundException. Instead, the native layer returns an error code which is then propagated up, and the managed fallback logic in Npgsql never gets a chance to intercept it.
This explains why the exception cannot be caught either by my application code or by Npgsql’s internal try/catch. The error is raised at the runtime boundary, outside of Npgsql’s control.
So while the application continues to work fine once Kerberos/GSSAPI is unavailable (it falls back to password-based authentication), the uncaught exception message is confusing for users. It looks like a hard failure even though functionality is not actually impacted.
@roji I can’t provide a managed stack trace because the error originates in the .NET runtime’s native GSSAPI layer (pal_gssapi.c). It surfaces as an uncaught message rather than a catchable exception, so neither my code nor Npgsql’s try/catch can intercept it. The application still works, but the error message is confusing for users.
Cannot load library libgssapi_krb5.so.2: cannot open shared object file: No such file or directory
Is the above the only line you're getting on your application output? If not, please post the entire output so we have the full picture. Even if you don't have a managed stack trace, the full unmanaged error is still important.
In the meantime, you can of course specify GSS Encryption Mode=Disable on the connection string to disable GSS encryption and make the error messag go away.
From an offline conversation, @vonzshik suggests simply reversing the ordering of things in the GSS encryption setup, so that we send the GSS request to PostgreSQL - and read the response - before we actually start using NegotiateAuthentication (which triggers the underlying error, code). This would restrict the error only to cases where PostgreSQL has been configured for GSS-API, eliminating it for the majority case where users haven't set it up.
Investigated a bit further, and it might be a not so clear-cut solution.
Currently, they way GSS encryption setup works is that we first check whether we can initialize GSS API (that's essentially an attempt to retrieve credentials to send to postgres), and then if and only if we're successful, actually send a request to postgres to ask for GSS Encryption. At this point postgres can either agree (and then handshake happens) or say it doesn't support it. This behavior is in line with libpq and it's explicitly documented there as such.
Now, here is where things are a bit murky. Theoretically we can swap both things around. After all, whether we exit due to postgres not supporting GSS or there being no credentials doesn't matter that much, unless we consider a case where the server does support GSS but the client doesn't, at which point we'll have to drop the connection and recreate it from scratch, but overall that's not the end of the world.
The problem is that there is a difference in behavior between GSS on windows and GSS on linux. On windows, we can always retrieve credentials (which I assume is due to internal workings of windows and to support SSPI). On linux, that's actually not true. As long as you do not have a kerberos token in local cache (kinit), we can't actually retrieve anything. This means that by changing the order to request->credentials we'll force everyone to send a gss encryption request, no matter whether they actually have kerberos enabled or not. While the roundtrip on physical open by itself is also not the end of the world, I can't say for sure whether cloud providers (amazon, azure, etc) do not have kerberos enabled on their postgres servers (and I suspect they actually do for easier setup). This means that in the worst case scenario by default people wouldn't only pay for a roundtrip during physical open, but because there is no backing out of GSS once it's started we would have to completely scrap the connection and start anew, with GSS encryption disabled.
To me it doesn't seems to be a good tradeoff, where the issue isn't even breaking the app, but instead adds a confusing error to stderr/logs. I propose we treat it as an environmental issue and as such improve our documentation (including release notes), so people are aware of it and can act accordingly to remedy it.
Discussed this further internally, and I agree with the above. Our choice here is basically between saving the roundtrip and re-connection on Linux only - when the user isn't actually logged in - and getting rid of the warning where Kerberos isn't installed. Since the former case (connecting from Linux without Kerberos login) seems quite common, it seems preferable to prioritize that over eliminating the warning for when Kerberos isn't installed (the current state of affairs).
Let's see how many people actually have trouble with this, and see what we do as a function of that.
Npgsql internally handles this and falls back to connecting without GSSAPI, so the error is harmless.
Just wanted to note that the above statement isn't exactly true. Since the error message is logged to stderr, it was causing my xunit integration job to fail since it expects a clean stderr.
Is there any overhead from trying to use GSSAPI and failing? Would we see any performance improvements by setting GSS Encryption Mode=Disable (assuming we still use SSL/TLS)?
This issue should be reopened as we continue to see this error in a context of Dockerized .NET app.
The error explicitely says
Cannot load library libgssapi_krb5.so.2
Error: libgssapi_krb5.so.2: cannot open shared object file: No such file or directory
but this file is only available when Kerberos package is installed in Alpine Linux.
The new .net10 images are Ubuntu based and we are still seeing this issue. I tried adding the Ubuntu version of the Kerberos by adding the following line to our Dockerfile
I should add we do not want to go changing connection strings all over to include GSS Encryption Mode=Disable though it is the only solution that works at the moment.
It's great that GSSAPI was added as an option in Npgsql 10, but why was the default changed from Disable to Prefer. That seems to be the issue here. Why is this on by default instead of opt-in?
@rowanmoul unless I'm mistaken, that's also how libpq behaves - GSSAPI is preferred - and we generally align to libpq. Also, specifically with security-related features, it's generally a good idea to have things on by default, and to offer an explicit opt-out (rather than the other way around).
Activity
vonzshik commentedon Dec 1, 2025
Is there a stacktrace for the exception? We do have try/catch around gss encryption and ideally should have retried without it in case it fails.
npgsql/src/Npgsql/Internal/NpgsqlConnector.cs
Lines 601 to 628 in 34f9a48
Varorbc commentedon Dec 1, 2025
I’ve investigated the exception further and found that it originates in the .NET runtime’s native interop layer (
System.Net.Security.Native/pal_gssapi.c). Whenlibgssapi_krb5.so.2is missing, the runtime’s native code attempts to call into GSSAPI and fails. This failure is not surfaced as a typical managedDllNotFoundExceptionorEntryPointNotFoundException. Instead, the native layer returns an error code which is then propagated up, and the managed fallback logic in Npgsql never gets a chance to intercept it.This explains why the exception cannot be caught either by my application code or by Npgsql’s internal
try/catch. The error is raised at the runtime boundary, outside of Npgsql’s control.So while the application continues to work fine once Kerberos/GSSAPI is unavailable (it falls back to password-based authentication), the uncaught exception message is confusing for users. It looks like a hard failure even though functionality is not actually impacted.
https://github.com/dotnet/runtime/blob/3b637728da9d5dc1dc625640bb5d7e436cf0f12a/src/native/libs/System.Net.Security.Native/pal_gssapi.c#L120-L144
roji commentedon Dec 1, 2025
@Varorbc can you please post the full exception and stack trace as requested?
Varorbc commentedon Dec 1, 2025
@roji I can’t provide a managed stack trace because the error originates in the .NET runtime’s native GSSAPI layer (
pal_gssapi.c). It surfaces as an uncaught message rather than a catchable exception, so neither my code nor Npgsql’stry/catchcan intercept it. The application still works, but the error message is confusing for users.roji commentedon Dec 1, 2025
Is the above the only line you're getting on your application output? If not, please post the entire output so we have the full picture. Even if you don't have a managed stack trace, the full unmanaged error is still important.
Varorbc commentedon Dec 1, 2025
Yes, that's all the information I've seen.
roji commentedon Dec 1, 2025
In the meantime, you can of course specify
GSS Encryption Mode=Disableon the connection string to disable GSS encryption and make the error messag go away.Varorbc commentedon Dec 1, 2025
Yes, that's what I'm doing now, the error message disappeared.
roji commentedon Dec 1, 2025
From an offline conversation, @vonzshik suggests simply reversing the ordering of things in the GSS encryption setup, so that we send the GSS request to PostgreSQL - and read the response - before we actually start using NegotiateAuthentication (which triggers the underlying error, code). This would restrict the error only to cases where PostgreSQL has been configured for GSS-API, eliminating it for the majority case where users haven't set it up.
vonzshik commentedon Dec 1, 2025
Investigated a bit further, and it might be a not so clear-cut solution.
Currently, they way GSS encryption setup works is that we first check whether we can initialize GSS API (that's essentially an attempt to retrieve credentials to send to postgres), and then if and only if we're successful, actually send a request to postgres to ask for GSS Encryption. At this point postgres can either agree (and then handshake happens) or say it doesn't support it. This behavior is in line with libpq and it's explicitly documented there as such.
Now, here is where things are a bit murky. Theoretically we can swap both things around. After all, whether we exit due to postgres not supporting GSS or there being no credentials doesn't matter that much, unless we consider a case where the server does support GSS but the client doesn't, at which point we'll have to drop the connection and recreate it from scratch, but overall that's not the end of the world.
The problem is that there is a difference in behavior between GSS on windows and GSS on linux. On windows, we can always retrieve credentials (which I assume is due to internal workings of windows and to support SSPI). On linux, that's actually not true. As long as you do not have a kerberos token in local cache (
kinit), we can't actually retrieve anything. This means that by changing the order to request->credentials we'll force everyone to send a gss encryption request, no matter whether they actually have kerberos enabled or not. While the roundtrip on physical open by itself is also not the end of the world, I can't say for sure whether cloud providers (amazon, azure, etc) do not have kerberos enabled on their postgres servers (and I suspect they actually do for easier setup). This means that in the worst case scenario by default people wouldn't only pay for a roundtrip during physical open, but because there is no backing out of GSS once it's started we would have to completely scrap the connection and start anew, with GSS encryption disabled.To me it doesn't seems to be a good tradeoff, where the issue isn't even breaking the app, but instead adds a confusing error to stderr/logs. I propose we treat it as an environmental issue and as such improve our documentation (including release notes), so people are aware of it and can act accordingly to remedy it.
roji commentedon Dec 1, 2025
Discussed this further internally, and I agree with the above. Our choice here is basically between saving the roundtrip and re-connection on Linux only - when the user isn't actually logged in - and getting rid of the warning where Kerberos isn't installed. Since the former case (connecting from Linux without Kerberos login) seems quite common, it seems preferable to prioritize that over eliminating the warning for when Kerberos isn't installed (the current state of affairs).
Let's see how many people actually have trouble with this, and see what we do as a function of that.
2 remaining items
roji commentedon Dec 2, 2025
@Varorbc done in npgsql/doc#437, thanks for flagging this.
Add info on GSSAPI-related error when Kerberos is not installed (#437)
mattzink commentedon Dec 15, 2025
Just wanted to note that the above statement isn't exactly true. Since the error message is logged to stderr, it was causing my xunit integration job to fail since it expects a clean stderr.
gabynevada commentedon Jan 29, 2026
Another issue is that we we're using the runtime-deps:10.0-noble-chiseled-extra images and from v10 they all started failing with this error.
Had some pain debugging and finding this issue as the images worked fine in previous versions.
jdaigle commentedon Mar 9, 2026
Is there any overhead from trying to use GSSAPI and failing? Would we see any performance improvements by setting
GSS Encryption Mode=Disable(assuming we still use SSL/TLS)?mhkolk commentedon Mar 16, 2026
This issue should be reopened as we continue to see this error in a context of Dockerized .NET app.
The error explicitely says
but this file is only available when Kerberos package is installed in Alpine Linux.
The new .net10 images are Ubuntu based and we are still seeing this issue. I tried adding the Ubuntu version of the Kerberos by adding the following line to our Dockerfile
RUN apt update && apt -y upgrade libkrb5-3as documented here
but the same issue/error still appears.
I should add we do not want to go changing connection strings all over to include
GSS Encryption Mode=Disablethough it is the only solution that works at the moment.rowanmoul commentedon Mar 23, 2026
It's great that GSSAPI was added as an option in Npgsql 10, but why was the default changed from
DisabletoPrefer. That seems to be the issue here. Why is this on by default instead of opt-in?roji commentedon Mar 23, 2026
@rowanmoul unless I'm mistaken, that's also how libpq behaves - GSSAPI is preferred - and we generally align to libpq. Also, specifically with security-related features, it's generally a good idea to have things on by default, and to offer an explicit opt-out (rather than the other way around).
mus65 commentedon Mar 28, 2026
Maybe the runtime is open to just not logging this error, opened dotnet/runtime#126251.
roji commentedon Mar 30, 2026
@mus65 thanks for opening the issue - it seems like the fix to runtime is about to get merged, and this warning will no longer get logged.
Fix container startup: silence GSS noise and persist DataProtection keys
Fix container startup: silence GSS noise and persist DataProtection keys
fix: отключить попытку GSSAPI-шифрования Npgsql к Postgres (joinrpg#4722