Re: [PoC] Federated Authn/z with OAUTHBEARER

From: Jacob Champion <jacob(dot)champion(at)enterprisedb(dot)com>
To: Daniel Gustafsson <daniel(at)yesql(dot)se>
Cc: Peter Eisentraut <peter(at)eisentraut(dot)org>, Antonin Houska <ah(at)cybertec(dot)at>, PostgreSQL Hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: [PoC] Federated Authn/z with OAUTHBEARER
Date: 2025-02-07 05:48:19
Message-ID: CAOYmi+nHG7oy+ybHH72WjiXAQG3tE6v_at-K9ebRy2oqo92V+A@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On Thu, Feb 6, 2025 at 2:02 PM Daniel Gustafsson <daniel(at)yesql(dot)se> wrote:
> Attached is a v46 which is v45 minus the now committed patch.

Thank you! Attached is v47, which creeps ever closer to the finish line.

For ease of review, v47-0001 is identical to v46-0001. The new changes
are split into separate fixup! commits which I'll squash in the next
round. They're ordered roughly in order of increasing complexity:

- 0002 removes and/or rewrites TODO comments that I do not plan to implement.
- 0003 makes the kqueue implementation register a one-shot timer
rather than a repeating timer, to match the epoll implementation.

- 0004 fixes a bug in backend cleanup:

I noticed that there was a "private state cookie changed" error in
some of the test logs, but none of the tests had actually failed.
Changing that to a PANIC revealed that before_shmem_exit() is too late
to run the cleanup function, since the state allocation has already
been released. I've swapped that out for a reset callback.

- 0005 warns at configure time if libcurl doesn't have a nonblocking
DNS implementation.
- 0006 augments bare Asserts during client-side JSON parsing with code
that will fail gracefully in production builds as well.
- 0007 escapes binary data during the printing of libcurl debug
output. (If you're having a bad enough day to need the debug spray,
you're probably not in the mood for the sound of a hundred BELs.)
- 0008 parses and passes through the expires_in and optional
verification_uri_complete fields from the device endpoint to any
custom user prompt. (We do not use them ourselves, at the moment. But
after seeing some nice demos of RHEL/PAM/sssd support for device flow
QR codes at FOSDEM, I think we're definitely going to want to make
those available to devs.)

- 0009 is gold-plating for the OAUTH_STEP_WAIT_INTERVAL state:

If PQconnectPoll client calls us early while we're waiting for the
ping interval to expire, we will immediately send the next request
even if we should be waiting. That bothers me a bit, because if our
implementation gets a tempban from an OAuth provider because one of
our clients accidentally implemented a busy-loop, I think we're likely
to get the blame. Ideally we should kick back up to the caller and
tell them to wait longer, instead.

Checking to see if the timer has expired is easy enough for
epoll/timerfd, but I wasn't able to find an easy way to do that with a
single kqueue. Instead, I split the kqueue in two and treat the second
one as the timer. (If it becomes readable, the timer has expired.)
There is an additional advantage in that I get to remove some `#ifdef
HAVE_SYS_EPOLL_H` sections; the two implementations are closer in
spirit now.

Thanks,
--Jacob

Attachment Content-Type Size
since-v46.diff.txt text/plain 1.5 KB
v47-0001-Add-OAUTHBEARER-SASL-mechanism.patch application/octet-stream 299.4 KB
v47-0002-fixup-Add-OAUTHBEARER-SASL-mechanism.patch application/octet-stream 3.3 KB
v47-0003-fixup-Add-OAUTHBEARER-SASL-mechanism.patch application/octet-stream 935 bytes
v47-0004-fixup-Add-OAUTHBEARER-SASL-mechanism.patch application/octet-stream 2.6 KB
v47-0005-fixup-Add-OAUTHBEARER-SASL-mechanism.patch application/octet-stream 6.3 KB
v47-0006-fixup-Add-OAUTHBEARER-SASL-mechanism.patch application/octet-stream 5.1 KB
v47-0007-fixup-Add-OAUTHBEARER-SASL-mechanism.patch application/octet-stream 2.3 KB
v47-0008-fixup-Add-OAUTHBEARER-SASL-mechanism.patch application/octet-stream 8.8 KB
v47-0009-fixup-Add-OAUTHBEARER-SASL-mechanism.patch application/octet-stream 10.8 KB
v47-0010-XXX-fix-libcurl-link-error.patch application/octet-stream 1.1 KB
v47-0011-DO-NOT-MERGE-Add-pytest-suite-for-OAuth.patch application/octet-stream 212.4 KB

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Amit Kapila 2025-02-07 05:52:54 Re: Introduce XID age and inactive timeout based replication slot invalidation
Previous Message Amit Kapila 2025-02-07 05:47:21 Re: Conflict detection for update_deleted in logical replication