diff options
author | Daniel Gustafsson <dgustafsson@postgresql.org> | 2025-02-20 16:25:17 +0100 |
---|---|---|
committer | Daniel Gustafsson <dgustafsson@postgresql.org> | 2025-02-20 16:25:17 +0100 |
commit | b3f0be788afc17d2206e1ae1c731d8aeda1f2f59 (patch) | |
tree | 4935e9d745787830d57941771dd2e63b49236ae5 /meson.build | |
parent | 1fd1bd871012732e3c6c482667d2f2c56f1a9395 (diff) | |
download | postgresql-b3f0be788afc17d2206e1ae1c731d8aeda1f2f59.tar.gz postgresql-b3f0be788afc17d2206e1ae1c731d8aeda1f2f59.zip |
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
Diffstat (limited to 'meson.build')
-rw-r--r-- | meson.build | 100 |
1 files changed, 100 insertions, 0 deletions
diff --git a/meson.build b/meson.build index 7dd7110318d..574f992ed49 100644 --- a/meson.build +++ b/meson.build @@ -856,6 +856,101 @@ endif ############################################################### +# Library: libcurl +############################################################### + +libcurlopt = get_option('libcurl') +if not libcurlopt.disabled() + # Check for libcurl 7.61.0 or higher (corresponding to RHEL8 and the ability + # to explicitly set TLS 1.3 ciphersuites). + libcurl = dependency('libcurl', version: '>= 7.61.0', required: libcurlopt) + if libcurl.found() + cdata.set('USE_LIBCURL', 1) + + # Check to see whether the current platform supports thread-safe Curl + # initialization. + libcurl_threadsafe_init = false + + if not meson.is_cross_build() + r = cc.run(''' + #include <curl/curl.h> + + int main(void) + { + 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; + }''', + name: 'test for curl_global_init thread safety', + dependencies: libcurl, + ) + + assert(r.compiled()) + if r.returncode() == 0 + libcurl_threadsafe_init = true + message('curl_global_init is thread-safe') + elif r.returncode() == 1 + message('curl_global_init is not thread-safe') + else + message('curl_global_init failed; assuming not thread-safe') + endif + endif + + if libcurl_threadsafe_init + cdata.set('HAVE_THREADSAFE_CURL_GLOBAL_INIT', 1) + endif + + # Warn if a thread-friendly DNS resolver isn't built. + libcurl_async_dns = false + + if not meson.is_cross_build() + r = cc.run(''' + #include <curl/curl.h> + + int main(void) + { + 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; + }''', + name: 'test for curl support for asynchronous DNS', + dependencies: libcurl, + ) + + assert(r.compiled()) + if r.returncode() == 0 + libcurl_async_dns = true + endif + endif + + if not libcurl_async_dns + warning(''' +*** 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.''') + endif + endif + +else + libcurl = not_found_dep +endif + + + +############################################################### # Library: libxml ############################################################### @@ -3045,6 +3140,10 @@ libpq_deps += [ gssapi, ldap_r, + # XXX libcurl must link after libgssapi_krb5 on FreeBSD to avoid segfaults + # during gss_acquire_cred(). This is possibly related to Curl's Heimdal + # dependency on that platform? + libcurl, libintl, ssl, ] @@ -3721,6 +3820,7 @@ if meson.version().version_compare('>=0.57') 'gss': gssapi, 'icu': icu, 'ldap': ldap, + 'libcurl': libcurl, 'libxml': libxml, 'libxslt': libxslt, 'llvm': llvm, |