|
| 1 | +# OIDC authentication |
| 2 | + |
| 3 | +[OpenID Connect :octicons-link-external-16:](https://openid.net/developers/how-connect-works/) (or OIDC) authentication allows you to authenticate using tokens issued by an external identity provider. Instead of managing database passwords, you can delegate authentication to centralized identity services. |
| 4 | + |
| 5 | +Percona Distribution for PostgreSQL integrates OIDC authentication using the `pg_oidc_validator` library, which validates OIDC tokens during client authentication. |
| 6 | + |
| 7 | +The library is compatible with any identity provider that implements the OIDC standard. |
| 8 | + |
| 9 | +For configuration details and source code, see the [pg_oidc_validator project :octicons-link-external-16:](https://github.com/Percona-Lab/pg_oidc_validator). |
| 10 | + |
| 11 | +!!! important |
| 12 | + OIDC authentication relies on [PostgreSQL OAuth authentication :octicons-link-external-16:](https://www.postgresql.org/docs/current/auth-oauth.html), introduced in PostgreSQL 18. |
| 13 | + |
| 14 | +## When to use OIDC authentication |
| 15 | + |
| 16 | +OIDC authentication is useful when you want to: |
| 17 | + |
| 18 | +* integrate PostgreSQL with an existing single sign-on (SSO) platform |
| 19 | +* reduce the need to manage database passwords |
| 20 | +* centralize identity management across applications and databases |
| 21 | + |
| 22 | +!!! tip |
| 23 | + OIDC authentication simplifies access management for PostgreSQL when using an identity provider that supports OpenID Connect. |
| 24 | + |
| 25 | +## OIDC authentication architecture |
| 26 | + |
| 27 | +OIDC authentication works as follows: |
| 28 | + |
| 29 | +1. The client obtains an access token from an external identity provider |
| 30 | +2. The client connects to PostgreSQL using OAuth authentication |
| 31 | +3. PostgreSQL forwards the token to the `pg_oidc_validator` module |
| 32 | +4. The validator verifies the token signature and claims |
| 33 | +5. If validation succeeds, PostgreSQL allows the connection |
| 34 | + |
| 35 | +The following diagram shows how OIDC authentication works between the client, the identity provider, and PostgreSQL: |
| 36 | + |
| 37 | +--8<-- "diagrams/oidc/auth-flow.md" |
| 38 | + |
| 39 | +!!! tip |
| 40 | + Before configuring OIDC authentication, ensure that your PostgreSQL deployment can access the identity provider that issues OIDC tokens. |
| 41 | + |
| 42 | +## Set up OIDC authentication |
| 43 | + |
| 44 | +Follow these steps to set up OIDC authentication for your PostgreSQL database. |
| 45 | +{.power-number} |
| 46 | + |
| 47 | +1. Install the `pg_oidc_validator` package. |
| 48 | + |
| 49 | + For more information, see the [Quickstart guide](../../installing.md). |
| 50 | + |
| 51 | + Alternatively, you can build the extension from source: |
| 52 | + |
| 53 | + ```bash |
| 54 | + make USE_PGXS=1 install -j |
| 55 | + ``` |
| 56 | + |
| 57 | + !!! note |
| 58 | + A C++23 compiler and standard library is required to build `pg_oidc_validator`. |
| 59 | + |
| 60 | +2. Edit `postgresql.conf` and add the validator library: |
| 61 | + |
| 62 | + ```ini |
| 63 | + oauth_validator_libraries = 'pg_oidc_validator' |
| 64 | + ``` |
| 65 | + |
| 66 | + !!! note |
| 67 | + This setting tells PostgreSQL to load the OIDC validator during startup. |
| 68 | + |
| 69 | +3. Add an OAuth authentication rule to `pg_hba.conf`: |
| 70 | + |
| 71 | + ```ini |
| 72 | + host all all 192.168.1.0/24 oauth scope="pgadmin-a",issuer=https://oidc.example.com |
| 73 | + ``` |
| 74 | + |
| 75 | + Where: |
| 76 | + |
| 77 | + * `oauth` enables OAuth authentication |
| 78 | + * `scope` is the required OIDC scope |
| 79 | + * `issuer` is the URL of the OIDC identity provider |
0 commit comments