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?
Attachments:
0001-libpq-require-encrypted-connections-for-OAUTHBEARER.patchapplication/octet-stream; name=0001-libpq-require-encrypted-connections-for-OAUTHBEARER.patchDownload+104-5
On Tue, Jun 16, 2026 at 1:22 PM Zsolt Parragi <zsolt.parragi@percona.com> 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]/messages/by-id/CAOYmi+mhiTPmNxy9JDKh+pahDxz2OoxAf=-jq+G+YUkHHqAGUA@mail.gmail.com 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]: /messages/by-id/CAOYmi+mhiTPmNxy9JDKh+pahDxz2OoxAf=-jq+G+YUkHHqAGUA@mail.gmail.com
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.
Attachments:
v2-0002-Warn-when-OAuth-is-configured-on-plaintext-capable-H.patchapplication/octet-stream; name=v2-0002-Warn-when-OAuth-is-configured-on-plaintext-capable-H.patchDownload+38-1
v2-0001-libpq-require-encrypted-connections-for-OAUTHBEARER.patchapplication/octet-stream; name=v2-0001-libpq-require-encrypted-connections-for-OAUTHBEARER.patchDownload+99-5
On Wed, Jun 17, 2026 at 12:23 AM Zsolt Parragi
<zsolt.parragi@percona.com> wrote:
* 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
The HTTPS communication uses the web model of security, yes. I was
pretty adamant about that during development.
But the communication with the server uses the Postgres model of
security, which unfortunately puts more requirements on end users.
Using OAuth does not move you into a stronger security model. For now,
it's still up to the DBA to enforce TLS in the HBA, and for the client
to set require_auth and sslmode appropriately. This is true of all
authentication types (which is bad, IMNSHO) so I'd like to strengthen
that for everybody who uses the server and not just OAuth users.
(Having different transport-security defaults for different authn
types is probably not a net win, since users have to keep it all
straight in their heads. It's a similar argument to the one we had re:
HBA configuration -- it's easier to make changes to OAuth in
isolation, but really we want the same functionality/policies to be
available for all of our authentication types. Even getting
sslrootcert=system to behave the way it does was a matter of debate,
though I still think we made the right call there.)
Another thing is that users usually aren't aware that oauthbearer
requires TLS, and just trust the implementation. SCRAM doesn't have
this requirement
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]/messages/by-id/CAH7T-aqV9KVuO2yCpzTM2E0Pz=yJOMhK1PyAGt=od77_OztBVg@mail.gmail.com rather than under a CVE fix.
I'd like to get to the point where that's safe, because I think it's
really strange that you can't safely use a mutual authentication tech
as your sole method of server authentication, but we're not there.
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?
I've asked a colleague who knows more about the cloud-y and k8s cases
to weigh in with their experience here, if possible. All I'll be
capable of is handwaving.
Even within a
"trusted" infrastructure, sending passwords in cleartext seems wrong
to me.
I think it is too. But I don't control other people's infrastructure,
and I can't prove that a lack of TLS is equivalent to cleartext.
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"
I think it's reasonable for a sufficiently informed user to choose
"don't care" as an option. (I just don't think it should be the
*default* for any connection, as it is today. Certainly not a
connection in which a secret is being sent.) So I don't think this
improves things, personally... and if sslmode=system were the global
default, we'd likely not be having this conversation at all.
One big alternative I can think of: I plan to push on file-based libpq
configurationThat 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.
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.
--Jacob
[1]: /messages/by-id/CAH7T-aqV9KVuO2yCpzTM2E0Pz=yJOMhK1PyAGt=od77_OztBVg@mail.gmail.com
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?
Attachments:
t248564_5v3-0001-doc-warn-that-OAuth-over-plaintext-connections-is.patchapplication/octet-stream; name=v3-0001-doc-warn-that-OAuth-over-plaintext-connections-is.patchDownload+25-2
v3-0002-libpq-require-encrypted-connections-for-OAUTHBEAR.patchapplication/octet-stream; name=v3-0002-libpq-require-encrypted-connections-for-OAUTHBEAR.patchDownload+99-5
v3-0003-Warn-when-OAuth-is-configured-on-plaintext-capabl.patchapplication/octet-stream; name=v3-0003-Warn-when-OAuth-is-configured-on-plaintext-capabl.patchDownload+38-1
Zsolt Parragi <zsolt.parragi@percona.com> 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]https://github.com/kubernetes/kubectl/issues/1169 and this happens only when TLS, this that looks like an
error is actually a mandatory requirement following the RFC9293[2]https://datatracker.ietf.org/doc/html/rfc9293#name-reset-generation, 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
On 18 Jun 2026, at 06:54, Zsolt Parragi <zsolt.parragi@percona.com> 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
On Fri, 06 Nov 2026, Daniel Gustafsson <daniel@yesql.se> 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.
On 6 Nov 2026, at 18:44, Zsolt Parragi <zsolt.parragi@percona.com> wrote:
On Fri, 06 Nov 2026, Daniel Gustafsson <daniel@yesql.se> 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