diff options
author | Daniel Gustafsson | 2025-02-20 15:25:17 +0000 |
---|---|---|
committer | Daniel Gustafsson | 2025-02-20 15:25:17 +0000 |
commit | b3f0be788afc17d2206e1ae1c731d8aeda1f2f59 (patch) | |
tree | 4935e9d745787830d57941771dd2e63b49236ae5 /config | |
parent | 1fd1bd871012732e3c6c482667d2f2c56f1a9395 (diff) |
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 <[email protected]>
Co-authored-by: Daniel Gustafsson <[email protected]>
Co-authored-by: Thomas Munro <[email protected]>
Reviewed-by: Daniel Gustafsson <[email protected]>
Reviewed-by: Peter Eisentraut <[email protected]>
Reviewed-by: Antonin Houska <[email protected]>
Reviewed-by: Kashif Zeeshan <[email protected]>
Discussion: https://postgr.es/m/[email protected]
Diffstat (limited to 'config')
-rw-r--r-- | config/programs.m4 | 65 |
1 files changed, 65 insertions, 0 deletions
diff --git a/config/programs.m4 b/config/programs.m4 index 7b55c2664a6..061b13376ac 100644 --- a/config/programs.m4 +++ b/config/programs.m4 @@ -274,3 +274,68 @@ AC_DEFUN([PGAC_CHECK_STRIP], AC_SUBST(STRIP_STATIC_LIB) AC_SUBST(STRIP_SHARED_LIB) ])# PGAC_CHECK_STRIP + + + +# PGAC_CHECK_LIBCURL +# ------------------ +# Check for required libraries and headers, and test to see whether the current +# installation of libcurl is thread-safe. + +AC_DEFUN([PGAC_CHECK_LIBCURL], +[ + AC_CHECK_HEADER(curl/curl.h, [], + [AC_MSG_ERROR([header file <curl/curl.h> is required for --with-libcurl])]) + AC_CHECK_LIB(curl, curl_multi_init, [], + [AC_MSG_ERROR([library 'curl' does not provide curl_multi_init])]) + + # Check to see whether the current platform supports threadsafe Curl + # initialization. + AC_CACHE_CHECK([for curl_global_init thread safety], [pgac_cv__libcurl_threadsafe_init], + [AC_RUN_IFELSE([AC_LANG_PROGRAM([ +#include <curl/curl.h> +],[ + curl_version_info_data *info; + + if (curl_global_init(CURL_GLOBAL_ALL)) + return -1; + + info = curl_version_info(CURLVERSION_NOW); +#ifdef CURL_VERSION_THREADSAFE + if (info->features & CURL_VERSION_THREADSAFE) + return 0; +#endif + + return 1; +])], + [pgac_cv__libcurl_threadsafe_init=yes], + [pgac_cv__libcurl_threadsafe_init=no], + [pgac_cv__libcurl_threadsafe_init=unknown])]) + if test x"$pgac_cv__libcurl_threadsafe_init" = xyes ; then + AC_DEFINE(HAVE_THREADSAFE_CURL_GLOBAL_INIT, 1, + [Define to 1 if curl_global_init() is guaranteed to be thread-safe.]) + fi + + # Warn if a thread-friendly DNS resolver isn't built. + AC_CACHE_CHECK([for curl support for asynchronous DNS], [pgac_cv__libcurl_async_dns], + [AC_RUN_IFELSE([AC_LANG_PROGRAM([ +#include <curl/curl.h> +],[ + curl_version_info_data *info; + + if (curl_global_init(CURL_GLOBAL_ALL)) + return -1; + + info = curl_version_info(CURLVERSION_NOW); + return (info->features & CURL_VERSION_ASYNCHDNS) ? 0 : 1; +])], + [pgac_cv__libcurl_async_dns=yes], + [pgac_cv__libcurl_async_dns=no], + [pgac_cv__libcurl_async_dns=unknown])]) + if test x"$pgac_cv__libcurl_async_dns" != xyes ; then + AC_MSG_WARN([ +*** The installed version of libcurl does not support asynchronous DNS +*** lookups. Connection timeouts will not be honored during DNS resolution, +*** which may lead to hangs in client programs.]) + fi +])# PGAC_CHECK_LIBCURL |