-
-
Notifications
You must be signed in to change notification settings - Fork 966
Add support for OAuth #2400
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Add support for OAuth #2400
Conversation
Postgres 18 introduces support for OAuth authentication.
|
I wonder how this could even be tested? Is it possible to mock an OAuth provider or would tests need to actually spin up a real one? |
We'll need a fake oidc implementation for example https://github.com/oauth2-proxy/mockoidc And a postgres 18 with the native validation library for example https://github.com/UnAfraid/pg_oidc_validator_go |
|
You don't need a OAuth provider to test the interaction between pgx and Postgres. On the client side all interactions with an OAuth Provider will be implemented in the OAuthTokenProvider function. On the server side Postgres doesn't talk to an OAuth provider either but just passes the token to an OAuth validator module https://www.postgresql.org/docs/current/oauth-validators.html. I think the only thing we have to test is whether the token properly arrives at the server resp. in the module. For this a dummy module could be used. I implemented such a module here https://github.com/dvob/pg_dummy_validator. Usually Postgres passes the token to the module/validator and the module returns if the token is authenticated and to which user it maps. In my dummy module I just take the token string and return it to Postgres as authenticated user (e.g. if token is I suggest we copy this dummy module to In What do you think? The thing which is not entirely clear to me is how you conditionally test features which are only available in PG18 like this OAuth stuff? Do we use |
There is a |
This function would already require a connection but I think the main thing to test is establishing the connection using OAuth. So I introduced Further I implemented the changes described above to introduce testing for OAuth. I tested the |
Postgres 18 introduces support for OAuth authentication. This PR does implement support for it. Also see #2382
Related links:
Currently it uses OAuth SASL for authentication if the OAuthTokenProvider is configured and the server offers
OAUTHBEARER.I'm not sure if this selection of the SASL auth mechanism is too primitive? Should this be configurable as well?
On the other hand I'm not sure if it is even possible that Postgres returns multiple SASL mechanisms. If I configure SCRAM and OAUTH in pg_hba.conf it seems it only returns the first match.
Also currently tests are missing.