mirror of
https://github.com/postgres/postgres.git
synced 2025-10-25 13:17:41 +03:00
Add support for OAUTHBEARER SASL mechanism
This commit implements OAUTHBEARER, RFC 7628, and OAuth 2.0 Device Authorization Grants, RFC 8628. In order to use this there is a new pg_hba auth method called oauth. When speaking to a OAuth- enabled server, it looks a bit like this: $ psql 'host=example.org oauth_issuer=... oauth_client_id=...' Visit https://oauth.example.org/login and enter the code: FPQ2-M4BG Device authorization is currently the only supported flow so the OAuth issuer must support that in order for users to authenticate. Third-party clients may however extend this and provide their own flows. The built-in device authorization flow is currently not supported on Windows. In order for validation to happen server side a new framework for plugging in OAuth validation modules is added. As validation is implementation specific, with no default specified in the standard, PostgreSQL does not ship with one built-in. Each pg_hba entry can specify a specific validator or be left blank for the validator installed as default. This adds a requirement on libcurl for the client side support, which is optional to build, but the server side has no additional build requirements. In order to run the tests, Python is required as this adds a https server written in Python. Tests are gated behind PG_TEST_EXTRA as they open ports. This patch has been a multi-year project with many contributors involved with reviews and in-depth discussions: Michael Paquier, Heikki Linnakangas, Zhihong Yu, Mahendrakar Srinivasarao, Andrey Chudnovsky and Stephen Frost to name a few. While Jacob Champion is the main author there have been some levels of hacking by others. Daniel Gustafsson contributed the validation module and various bits and pieces; Thomas Munro wrote the client side support for kqueue. Author: Jacob Champion <jacob.champion@enterprisedb.com> Co-authored-by: Daniel Gustafsson <daniel@yesql.se> Co-authored-by: Thomas Munro <thomas.munro@gmail.com> Reviewed-by: Daniel Gustafsson <daniel@yesql.se> Reviewed-by: Peter Eisentraut <peter@eisentraut.org> Reviewed-by: Antonin Houska <ah@cybertec.at> Reviewed-by: Kashif Zeeshan <kashi.zeeshan@gmail.com> Discussion: https://postgr.es/m/d1b467a78e0e36ed85a09adf979d04cf124a9d4b.camel@vmware.com
This commit is contained in:
@@ -437,6 +437,17 @@ struct pg_conn
|
||||
* cancel request, instead of being a normal
|
||||
* connection that's used for queries */
|
||||
|
||||
/* OAuth v2 */
|
||||
char *oauth_issuer; /* token issuer/URL */
|
||||
char *oauth_issuer_id; /* token issuer identifier */
|
||||
char *oauth_discovery_uri; /* URI of the issuer's discovery
|
||||
* document */
|
||||
char *oauth_client_id; /* client identifier */
|
||||
char *oauth_client_secret; /* client secret */
|
||||
char *oauth_scope; /* access token scope */
|
||||
char *oauth_token; /* access token */
|
||||
bool oauth_want_retry; /* should we retry on failure? */
|
||||
|
||||
/* Optional file to write trace info to */
|
||||
FILE *Pfdebug;
|
||||
int traceFlags;
|
||||
@@ -505,7 +516,7 @@ struct pg_conn
|
||||
* the server? */
|
||||
uint32 allowed_auth_methods; /* bitmask of acceptable AuthRequest
|
||||
* codes */
|
||||
const pg_fe_sasl_mech *allowed_sasl_mechs[1]; /* and acceptable SASL
|
||||
const pg_fe_sasl_mech *allowed_sasl_mechs[2]; /* and acceptable SASL
|
||||
* mechanisms */
|
||||
bool client_finished_auth; /* have we finished our half of the
|
||||
* authentication exchange? */
|
||||
|
||||
Reference in New Issue
Block a user