pgsql: Add support for OAUTHBEARER SASL mechanism - Mailing list pgsql-committers

From Daniel Gustafsson
Subject pgsql: Add support for OAUTHBEARER SASL mechanism
Date
Msg-id E1tl8m6-000KH7-0J@gemulon.postgresql.org
Whole thread Raw
List pgsql-committers
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

Branch
------
master

Details
-------
https://git.postgresql.org/pg/commitdiff/b3f0be788afc17d2206e1ae1c731d8aeda1f2f59

Modified Files
--------------
.cirrus.tasks.yml                                  |   15 +-
config/programs.m4                                 |   65 +
configure                                          |  332 +++
configure.ac                                       |   41 +
doc/src/sgml/client-auth.sgml                      |  252 ++
doc/src/sgml/config.sgml                           |   26 +
doc/src/sgml/filelist.sgml                         |    1 +
doc/src/sgml/installation.sgml                     |   27 +
doc/src/sgml/libpq.sgml                            |  445 +++
doc/src/sgml/oauth-validators.sgml                 |  414 +++
doc/src/sgml/postgres.sgml                         |    1 +
doc/src/sgml/protocol.sgml                         |  133 +-
doc/src/sgml/regress.sgml                          |   10 +
meson.build                                        |  100 +
meson_options.txt                                  |    3 +
src/Makefile.global.in                             |    1 +
src/backend/libpq/Makefile                         |    1 +
src/backend/libpq/auth-oauth.c                     |  894 ++++++
src/backend/libpq/auth.c                           |   10 +-
src/backend/libpq/hba.c                            |   64 +-
src/backend/libpq/meson.build                      |    1 +
src/backend/libpq/pg_hba.conf.sample               |    4 +-
src/backend/utils/adt/hbafuncs.c                   |   19 +
src/backend/utils/misc/guc_tables.c                |   12 +
src/backend/utils/misc/postgresql.conf.sample      |    3 +
src/include/common/oauth-common.h                  |   19 +
src/include/libpq/auth.h                           |    1 +
src/include/libpq/hba.h                            |    7 +-
src/include/libpq/oauth.h                          |  101 +
src/include/pg_config.h.in                         |    9 +
src/interfaces/libpq/Makefile                      |   11 +-
src/interfaces/libpq/exports.txt                   |    3 +
src/interfaces/libpq/fe-auth-oauth-curl.c          | 2883 ++++++++++++++++++++
src/interfaces/libpq/fe-auth-oauth.c               | 1163 ++++++++
src/interfaces/libpq/fe-auth-oauth.h               |   46 +
src/interfaces/libpq/fe-auth.c                     |   36 +-
src/interfaces/libpq/fe-auth.h                     |    3 +
src/interfaces/libpq/fe-connect.c                  |   48 +-
src/interfaces/libpq/libpq-fe.h                    |   85 +
src/interfaces/libpq/libpq-int.h                   |   13 +-
src/interfaces/libpq/meson.build                   |    5 +
src/makefiles/meson.build                          |    1 +
src/test/authentication/t/001_password.pl          |    8 +-
src/test/modules/Makefile                          |    1 +
src/test/modules/meson.build                       |    1 +
src/test/modules/oauth_validator/.gitignore        |    4 +
src/test/modules/oauth_validator/Makefile          |   40 +
src/test/modules/oauth_validator/README            |   13 +
src/test/modules/oauth_validator/fail_validator.c  |   47 +
src/test/modules/oauth_validator/magic_validator.c |   48 +
src/test/modules/oauth_validator/meson.build       |   85 +
.../modules/oauth_validator/oauth_hook_client.c    |  293 ++
src/test/modules/oauth_validator/t/001_server.pl   |  594 ++++
src/test/modules/oauth_validator/t/002_client.pl   |  154 ++
src/test/modules/oauth_validator/t/OAuth/Server.pm |  140 +
src/test/modules/oauth_validator/t/oauth_server.py |  391 +++
src/test/modules/oauth_validator/validator.c       |  143 +
src/test/perl/PostgreSQL/Test/Cluster.pm           |   22 +-
src/tools/pgindent/pgindent                        |   14 +
src/tools/pgindent/typedefs.list                   |   11 +
60 files changed, 9278 insertions(+), 39 deletions(-)


pgsql-committers by date:

Previous
From: Jeff Davis
Date:
Subject: pgsql: Transfer statistics during pg_upgrade.
Next
From: Andrew Dunstan
Date:
Subject: pgsql: Ignore blank lines in pgindent exclude files