Require SSL connection to postgres for oauth
Require SSL connection to postgres for oauth
Hello
The Oauthbearer RFC states that connections should require TLS:
OAUTHBEARER: OAuth 2.0 bearer tokens, as described in [RFC6750].
RFC 6750 uses Transport Layer Security (TLS) [RFC5246] to
secure the protocol interaction between the client and the
resource server.
....
Additionally, for the two
mechanisms specified in this document, TLS MUST be used for
OAUTHBEARER to protect the bearer token; for OAUTH10A, the use of TLS
is RECOMMENDED.
However, postgres currently does not enforce this, as it allows oauth
with any connection type. On the client side, we require HTTPS to the
identity provider, but there's no similar check for the connection to
the postgres server.
What do you think about extending the already existing
OAUTHDEBUG=UNSAFE... libpq flags to require something like
"UNSAFE:plaintext-server" if somebody really wants to use it over a
plaintext protocol?
See attached patch: without this flag we only allow TLS connections or
unix sockets (which should be a safe exception since they are local).
We could argue that we should also allow GSSAPI, but for now I left it
out because:
1. The RFC doesn't mention it.
2. Is GSSAPI+oauthbearer a realistic use case?
I added the client-side flag because I think it's the more important
part of this fix: protecting clients from accidentally sending an
access token over a plaintext connection. Should we also add a
matching warning on the server side during startup or HBA reload if we
find OAuth entries that do not use SSL?
Re: Require SSL connection to postgres for oauth
От:
Jacob Champion <jacob.champion@enterprisedb.com>
Дата:
On Tue, Jun 16, 2026 at 1:22 PM Zsolt Parragi wrote: > Additionally, for the two > mechanisms specified in this document, TLS MUST be used for > OAUTHBEARER to protect the bearer token; for OAUTH10A, the use of TLS > is RECOMMENDED. Yeah. Implementing this was discussed in-person a few times (not sure if it made the lists), and IIRC the reaction at the time was neutral-to-negative. Historically, Postgres lets you send credentials in plaintext and assumes you know what you're doing. But things change, and I wouldn't mind enforcing this if there's consensus. We would still need to consider compatibility, though. I keep hearing people talk about running infrastructure within "trusted" TCP (I assume via a mesh or cloud VPN of some sort?) and I don't know that they should be made to use a debug flag. > What do you think about extending the already existing > OAUTHDEBUG=UNSAFE... libpq flags to require something like > "UNSAFE:plaintext-server" if somebody really wants to use it over a > plaintext protocol? One big alternative I can think of: I plan to push on file-based libpq configuration [1] again for PG20, after multiple PGConf.dev conversations for independent features ended up at "it'd be really nice if we could configure this behavior outside of a connection string". This would fit really nicely there: we could make the default stricter while still giving people an easy out if they don't like it, *and* we could discuss applying it to all secrets. But a simpler way to toggle it for OAuth would be a good first step and fallback, if that doesn't land. > See attached patch: (reminder to register in CF if you haven't already) > We could argue that we should also allow GSSAPI We should allow gssenc, yeah, unless you know of a reason that gssenc+OAuth doesn't work today? (If it doesn't, that's unintentional and I need to look into it.) > Should we also add a > matching warning on the server side during startup or HBA reload if we > find OAuth entries that do not use SSL? IMO, yes (especially if the client default were to change). In fact we could consider adding that regardless of whether the client side change gets committed. Thanks, --Jacob [1] https://postgr.es/m/CAOYmi%2BmhiTPmNxy9JDKh%2BpahDxz2OoxAf%3D-jq%2BG%2BYUkHHqAGUA%40mail.gmail.com
Re: Require SSL connection to postgres for oauth
> Historically, Postgres lets you send credentials > in plaintext and assumes you know what you're doing. Yes, but if we look at the oauth part: * It requires OAUTHDEBUG=UNSAFE to use http instead of https to get the token. The documentation makes it clear that this option is unsafe because it transmits authentication data in clear-text * We also want to add a reminder to the unsafe trace output that warns users that the trace contains sensitive authentication data, do not share it with others * But then if the configuration specifies a plaintext connection to postgres, it silently accepts and uses it. It isn't mentioned anywhere that this is a bad idea. Another thing is that users usually aren't aware that oauthbearer requires TLS, and just trust the implementation. SCRAM doesn't have this requirement, so we can't even say something like "use TLS with SASL", it depends on the mechanism. > We would still need to consider compatibility, though. I keep hearing > people talk about running infrastructure within "trusted" TCP (I > assume via a mesh or cloud VPN of some sort?) and I don't know that > they should be made to use a debug flag. Is this a common-enough use case to think about? Even within a "trusted" infrastructure, sending passwords in cleartext seems wrong to me. I used OAUTHDEBUG because I wanted to keep backward compatibility (but my main reasoning was easier testing, not actual production use), and it was an already existing environment variable also used by the http/https switch. I didn't want to introduce a new environment variable for this purpose, and I also didn't want to introduce a new connection option. As an alternative idea, what do you think about requiring an explicitly specified sslmode=disable in the connection string? That would also fit into the error message of my current patch, we could even modify it to "consider sslmode=require or specify sslmode=disable to override" > One big alternative I can think of: I plan to push on file-based libpq > configuration That would definitely be a better fit, but I was hoping this could be fixed even in earlier branches, as this can be potentially dangerous. However, given the compatibility concern that seems unlikely. > We should allow gssenc, yeah, unless you know of a reason that > gssenc+OAuth doesn't work today? (If it doesn't, that's unintentional > and I need to look into it.) No, I only left it out from it because the RFC explicitly requires TLS. v2 also permits gss. > IMO, yes (especially if the client default were to change). In fact we > could consider adding that regardless of whether the client side > change gets committed. Also attached 0002, which adds the server side warning.
Re: Require SSL connection to postgres for oauth
> It absolutely *does* have that requirement! If you need connection > security, do NOT use SCRAM without authenticated transport encryption. > Untrusted connection without TLS isn't part of the supported security > model, which is why strengthening SCRAM for those use cases is > discussed in public [1] rather than under a CVE fix. I was referring to the rfc, as SCRAM explicitly allows non-TLS connections, it just recommends using it. Oauthbearer explicitly requires it. So allowing users to use scram on plaintext without warnings looks acceptable to me, but it's questionable for oauth. > But the communication with the server uses the Postgres model of > security, which unfortunately puts more requirements on end users. > ... > Since it was an explicit decision rather than an oversight, I think > you'd have a hard time overcoming the backport barrier without a > really strong consensus. I added another patch which is only a documentation improvement, that's the new 0001. The documentation is very clear about "password" being insecure over plaintext connections, but there's no such mention for oauth. This aims to fix that at all places where oauth is mentioned. This, or this together with the server side warning should be an improvement for all versions, even without the client side change. 0002 and 0003 are the previous patches unchanged. > so I'd like to strengthen > that for everybody who uses the server and not just OAuth users. What do you think about adding a similar server-side warning/info message for plaintext+password and ident too in 0003?
Re: Require SSL connection to postgres for oauth
От:
"Jonathan Gonzalez V." <jonathan.abdiel@gmail.com>
Дата:
Zsolt Parragi writes: >> We would still need to consider compatibility, though. I keep hearing >> people talk about running infrastructure within "trusted" TCP (I >> assume via a mesh or cloud VPN of some sort?) and I don't know that >> they should be made to use a debug flag. > > Is this a common-enough use case to think about? Even within a > "trusted" infrastructure, sending passwords in cleartext seems wrong > to me. This case is really common, specially now that people is knowing more and more about managing network with eBPF and using tools like Cilium. But what really worries me more about these kind of situation it's the reason why that exists. For example, there's some special documented cases when you use Kubernetes that using an TLS connection may kill your connection[1] and this happens only when TLS, this that looks like an error is actually a mandatory requirement following the RFC9293[2], so not having a backward compatibility will be a mistake and will lead a lot of users to not being able to use OAuth when using more than one psql client over the same tunnel. so I think it is a really common situation that someone will be using Oauth without TLS If you want to look outside the Kubernetes world, the same apply for any cloud service providing some kind of virtual port-forward over a websocket, which basically it's the same connection, and if you have any kind of firewall, the connection will also get a RST which will basically will the connection. So yes, keeping the non-TLS connections I think it's a must. [1] https://github.com/kubernetes/kubectl/issues/1169 [2] https://datatracker.ietf.org/doc/html/rfc9293#name-reset-generation -- Jonathan Gonzalez V. EDB https://www.enterprisedb.com
Re: Require SSL connection to postgres for oauth
> On 18 Jun 2026, at 06:54, Zsolt Parragi wrote: > I added another patch which is only a documentation improvement, > that's the new 0001. The documentation is very clear about "password" > being insecure over plaintext connections, but there's no such mention > for oauth. I cam absolutely get behind an improvement of the docs for master through 18 for this, ideally in time for the next minors. The attached .txt (intentionally not a .diff or .patch since I didn't re-send your full patchset) massages your 0001 to make it more consistent with the rest of the documentation. > 0002 and 0003 are the previous patches unchanged. I am intrerested in raising the security model for postgres connections, but as mentioned here and elsewhere it does require careful study of common container environments like Kubernetes which may be impacted. For v19 I don't see it as a realistic change (and I think it was too late even when initially raised, even though it was a lot earlier in the cycle than now), but hopefully we can raise the bar in v20. -- Daniel Gustafsson
Re: Require SSL connection to postgres for oauth
От:
Zsolt Parragi <zsolt.parragi@percona.com>
Дата:
On Fri, 06 Nov 2026, Daniel Gustafsson wrote: > The attached .txt > (intentionally not a .diff or .patch since I didn't re-send your full patchset) > massages your 0001 to make it more consistent with the rest of the > documentation. Thanks, it looks good to me. > For v19 I don't see it as > a realistic change (and I think it was too late even when initially raised, > even though it was a lot earlier in the cycle than now), but hopefully we can > raise the bar in v20. Yes, when I originally submitted the thread I thought this was a bug/oversight as I didn't find any mention of it being intentional. Since it was intentional, it was definitely too late in June. I simply kept all 3 parts there so that they don't get forgotten, as I think 0003 should be a good improvement without breaking any use cases.
Re: Require SSL connection to postgres for oauth
От:
Daniel Gustafsson <daniel@yesql.se>
Дата:
> On 6 Nov 2026, at 18:44, Zsolt Parragi wrote: > > On Fri, 06 Nov 2026, Daniel Gustafsson wrote: >> The attached .txt >> (intentionally not a .diff or .patch since I didn't re-send your full patchset) >> massages your 0001 to make it more consistent with the rest of the >> documentation. > > Thanks, it looks good to me. Thanks for looking, I'll apply it later tonight when back at the laptop. >> For v19 I don't see it as >> a realistic change (and I think it was too late even when initially raised, >> even though it was a lot earlier in the cycle than now), but hopefully we can >> raise the bar in v20. > > Yes, when I originally submitted the thread I thought this was a > bug/oversight as I didn't find any mention of it being intentional. > Since it was intentional, it was definitely too late in June. I simply > kept all 3 parts there so that they don't get forgotten, as I think > 0003 should be a good improvement without breaking any use cases. +1. -- Daniel Gustafsson