Add support for OAuth 2.0 with PostgreSQL 18#693
Open
jeltz wants to merge 3 commits intoged:masterfrom
Open
Conversation
Since the buitt-in OAuth hooks in libpq can return timerfd and not jsut a socket when you ask for the current file descriptor we are waiting on we need to make sure to use the right Ruby class to wrap the file descriptor, if it is not a valid socket we should use IO.
Async is not supported yet
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Hi, I have hacked on this patch for some time now and feel like now is a good time to get some external input so I do not waste too much time on things the project would not like. The patch is not yet in a state where it is ready to be merged, but I think it is ready for input on architecture and design decisions. I also have several open questions.
I do not expect you to have answers to all the questions below, I mostly include them so I do not forget them myself.
Background
PostgreSQL 18 added support for OAuth 2.0 in the server, libpq and the psql client. See documentation at [1] and [2] for some further information.
So since libpq has added support for it I also think we should expose that support in the pg gem.
Current state of the patch
The patch should work and be stable but is missing polish and and some features, and CI is not entirely happy yet. See the new test cases for more details on how it is used. But here is a simple example: As you can see the current interface is pretty rough and intentionally close to the API exposed by libpq. Returning true for example means that we do not fall through to the built-in default handler.
The first of the three patches just fixes the code so it is no longer broken with the builtin OAuth hooks, the second implements the actual feature and the third just tries to fix the CI a bit.
Since PostgreSQL does not ship with any OAuth validator module which can be used by driver authors I wrote my own quick dummy one which worked very well until I had to make it compile on the full CI matrix. 😅
Things left to do
Open questions
About interface/implementation
-1to signal error? E.g. by letting people returntrue|false|nil?About naming
PG.set_auth_data_hookactually bePG::Connection.set_auth_data_hook?pg.c?connection_spec,rb.And the test validator is surprisingly complex to build in the CI environment.
Trying it out
To try it out for real you need the install a validator module, and here I am only familiar with our own: pg_oic_validator which comes with a Docker Compose file for setting it all up. I know there are others like keycloak-oauth-validator but I do not know how easy or tricky they are to set up.