Re: [PoC] Federated Authn/z with OAUTHBEARER
Jacob Champion <jacob.champion@enterprisedb.com>
Commits
GET /api/v1/messages/:b64id/commits
the thread's linked commits as JSON, with link sources.
API reference →
-
meson: Fix install-quiet after clean
- a9ffb35274fb 18.0 landed
- 4ae03be54734 19 (unreleased) landed
-
oauth: Run Autoconf tests with correct compiler flags
- 3d23f68c5529 18.0 landed
- 990571a08b66 19 (unreleased) landed
-
Link libpq with libdl if the platform needs that.
- 4df477153a6b 19 (unreleased) landed
- 7bd752c1fb8e 18.0 landed
-
Doc: correct spelling of meson switch.
- 3faac9d14063 16.9 landed
- 766d2e673342 17.5 landed
- ac557793d478 18.0 landed
-
oauth: Correct SSL dependency for libpq-oauth.a
- 3db68212a393 18.0 landed
-
oauth: Fix Autoconf build on macOS
- 4ea1254f35b2 18.0 cited
-
oauth: Move the builtin flow into a separate module
- b0635bfda053 18.0 landed
-
Remove a stray "pgrminclude" annotation
- 764d501d24ba 18.0 cited
-
oauth: Simplify copy of PGoauthBearerRequest
- 1cf4c56480f8 18.0 landed
-
oauth: Improve validator docs on interruptibility
- 873c0fd67872 18.0 landed
-
oauth: Disallow synchronous DNS in libcurl
- d7e40845f923 18.0 landed
-
oauth: Fix postcondition for set_timer on macOS
- 434dbf6907ec 18.0 landed
-
oauth: Use IPv4-only issuer in oauth_validator tests
- 8d9d5843b55f 18.0 landed
-
Work around OAuth/EVFILT_TIMER quirk on NetBSD.
- c301a0a74a8a 18.0 landed
-
oauth: Fix incorrect const markers in struct
- 03366b61dfe5 18.0 landed
-
Add missing entry to oauth_validator test .gitignore
- 2c53dec7f440 18.0 landed
-
cirrus: Temporarily fix libcurl link error
- 9d9a71002a1c 18.0 landed
-
Add support for OAUTHBEARER SASL mechanism
- b3f0be788afc 18.0 landed
-
libpq: Handle asynchronous actions during SASL
- a99a32e43ed7 18.0 landed
-
require_auth: prepare for multiple SASL mechanisms
- f8d8581ed882 18.0 landed
-
Move PG_MAX_AUTH_TOKEN_LENGTH to libpq/auth.h
- e21d6f297158 18.0 landed
-
Make SASL max message length configurable
- 6d16f9debae0 18.0 landed
-
jsonapi: fully initialize dummy lexer
- 41b023946dfd 18.0 landed
-
common/jsonapi: support libpq as a client
- 0785d1b8b2fa 18.0 landed
-
Remove fe_memutils from libpgcommon_shlib
- f1976df5eaf2 18.0 landed
-
Revert ECPG's use of pnstrdup()
- f0096ef13be2 13.17 landed
- 3557185538fe 14.14 landed
- 2de129b356bf 15.9 landed
- ee2997c678d8 16.5 landed
- e9e05c655069 17.0 landed
- 5388216f6adc 18.0 landed
-
Explicitly require password for SCRAM exchange
- adcdb2c8dda4 17.0 landed
-
Refactor SASL exchange to return tri-state status
- 24178e235ea5 17.0 landed
Attachments
- v50-0001-Add-OAUTHBEARER-SASL-mechanism.patch (application/octet-stream) patch v50-0001
- v50-0002-fixup-Add-OAUTHBEARER-SASL-mechanism.patch (application/octet-stream) patch v50-0002
- v50-0003-fixup-changes-to-sanitize_char-et-al.patch (application/octet-stream) patch v50-0003
- v50-0004-XXX-fix-libcurl-link-error.patch (application/octet-stream) patch v50-0004
On Thu, Feb 13, 2025 at 2:56 PM Daniel Gustafsson <daniel@yesql.se> wrote:
> To make it easier for you to see what I mean I have implemented most of the
> comments and attached as a fixup patch, from which you can cherry-pick hunks
> you agree with. Those I didn't implement should be marked as such below.
>
> As we discussed off-list I took the liberty of squashing the previous fixup
> patches into a single one, and squashed your fixes for my comments against v47
> into 0001. All of my proposals are in 0004.
Great! I have attached v50; 0001 has almost all of v49 squashed in,
0002 has my changes on top (includes a pgindent/pgperltidy), and 0003
holds the only part I don't like (see below). 0004 contains the
FreeBSD hack that I suspect we'll need to merge in until Cirrus images
are updated.
> + The organization, product vendor, or other entity which develops and/or
> + administers the OAuth servers and clients for a given application.
> Since we define terminology here, shouldn't this be "OAuth resource servers"?
The resource server is Postgres for our purposes; I've changed it to
"authorization servers".
> + Since a misbehaving validator might let unauthorized users into the database,
> + correct implementation is critical. See
> "Don't make any bugs" isn't very helpful advice =) Expanded on it slightly.
Hmm, I think the overloading of "validate" in the replacement text
could be confusing. I guess my point is less "don't write bugs" and
more "a bug here has extreme impact"? I've taken another shot at it;
see what you think.
> + The server has ensured that the token is well-formed syntactically, but no
> "server" is an overloaded nomenclature here, perhaps using libpq instead to
> clearly indicate that it's postgres and not an OAuth server.
I've replaced this with "PostgreSQL" to match up with Peter's earlier
feedback (we were using "libpq" to describe the backend and he wanted
to avoid that).
> +sanitize_char(char c)
> +{
> + static char buf[5];
> With the multithreading work on the horizon we should probably avoid static
> variables like these to not create work for our future selves? The code isn't
> as neat when passing in a buffer/length but it avoids the need for a static or
> threadlocal variable. Or am I overthinking this?
This is the only part of the feedback patch that I'm not a fan of,
mostly because it begins to diverge heavily from the SCRAM code it
copied from. I don't disagree with the goal of getting rid of the
static buffers, but I would like to see them modified at the same time
so that we can refactor easily if/when a third SASL mechanism shows
up. (Maybe with a psprintf() rather than buffers?)
> + p++;
> + if (*p != ',')
> If the SASL exchange, are we certain that a rogue client cannot inject a
> message which trips us past the end of string? Should we be doublecheck when
> advancing p across the message?
The existing != checks will bail out if they get to the end of the
string. It relies on byte-at-a-time advancement for safety, as well as
the SASL code higher in the stack that ensures that the input buffer
is always null terminated. (SCRAM relies on that too.) If we ever
jumped farther than a byte, we'd need stronger checks, but at the
moment I don't think this change helps us.
> In load_validator_library we don't explicitly verify that the required callback
> is defined in the returned structure, which seems like a cheap enough belts and
> suspenders level check.
Yeah, there's a later check at time of use, but it's not as
user-friendly. I've adjusted the new error message to make it a bit
closer to the logical plugin wording.
> + if (parsed < 1)
> + return actx->debugging ? 0 : 1;
> Is 1 second a sane lower bound on interval for all situations? I'm starting to
> wonder if we should be more conservative here, or even make it configurable in
> some way? The default if not set of 5 seconds is quite a lot higher than 1.
Mmm, maybe it should be made configurable, but one second seems like a
long time from a CPU perspective. Maybe it would be applicable to
embedded clients? But only if some provider out there actually starts
using smaller intervals than their clients can stand... Should we wait
to hear from someone who is interested in configuring it?
> + parsed = parse_json_number(expires_in_str);
> + parsed = round(parsed);
> Shouldn't we floor() the value here to ensure we never report an expiration
> time longer than the actual expiration?
Sounds reasonable. Done in 0002.
> register_socket() doesn't have an error catch for the case when neither epoll
> nor kqeue is supported. Shouldn't it set actx_error() here as well? (Not done
> in my review patch.)
Done.
> + if (actx->curl_err[0])
> + {
> + size_t len;
> +
> + appendPQExpBuffer(&conn->errorMessage, " (%s)", actx->curl_err);
> Should this also qualify that the error comes from outside of postgres?
> Something like "(libcurl:%s)" to match? I haven't changed this in the attached
> since I'm still on the fence, but I'm leanings that we probably should.
> Thoughts?
Done. More context is probably better than less here.
> - * We only support one mechanism at the moment, so rather than deal with a
> + * We only support two mechanisms at the moment, so rather than deal with a
> While there's nothing incorrect about this comment, I have a feeling we won't
> support more mechanisms than we can justify having a simple array for anytime
> soon =)
Yeah. My goal was mostly to justify the use of the (unusual)
static-length list to future readers.
Thank you so much for the reviews!
--Jacob