pg_oidc_validator
pg_oidc_validator : OAuth and OIDC token validator for PostgreSQL 18
Overview
| ID | Extension | Package | Version | Category | License | Language |
|---|---|---|---|---|---|---|
| 7170 | pg_oidc_validator | pg_oidc_validator | 1.1.0 |
SEC | Apache-2.0 | C++ |
| Attribute | Has Binary | Has Library | Need Load | Has DDL | Relocatable | Trusted |
|---|---|---|---|---|---|---|
| --sL--- | No | Yes | Yes | No | no | no |
| Relationships | |
|---|---|
| See Also | oidc_validator pg_session_jwt pgjwt login_hook sslinfo sslutils pgsodium pguecc |
Packages
| Type | Repo | Version | PG Major Compatibility | Package Pattern | Dependencies |
|---|---|---|---|---|---|
| EXT | PIGSTY | 1.1.0 |
18 17 16 15 14 | pg_oidc_validator |
- |
| RPM | PIGSTY | 1.1.0 |
18 17 16 15 14 | pg_oidc_validator_$v |
- |
| DEB | PIGSTY | 1.1.0 |
18 17 16 15 14 | postgresql-$v-pg-oidc-validator |
- |
| Linux / PG | PG18 | PG17 | PG16 | PG15 | PG14 |
|---|---|---|---|---|---|
| el8.x86_64 | N/A | N/A | N/A | N/A | N/A |
| el8.aarch64 | N/A | N/A | N/A | N/A | N/A |
| el9.x86_64 | N/A | N/A | N/A | N/A | N/A |
| el9.aarch64 | N/A | N/A | N/A | N/A | N/A |
| el10.x86_64 | PIGSTY 1.1.0 | N/A | N/A | N/A | N/A |
| el10.aarch64 | PIGSTY 1.1.0 | N/A | N/A | N/A | N/A |
| d12.x86_64 | PIGSTY 1.1.0 | N/A | N/A | N/A | N/A |
| d12.aarch64 | PIGSTY 1.1.0 | N/A | N/A | N/A | N/A |
| d13.x86_64 | PIGSTY 1.1.0 | N/A | N/A | N/A | N/A |
| d13.aarch64 | PIGSTY 1.1.0 | N/A | N/A | N/A | N/A |
| u22.x86_64 | PIGSTY 1.1.0 | N/A | N/A | N/A | N/A |
| u22.aarch64 | PIGSTY 1.1.0 | N/A | N/A | N/A | N/A |
| u24.x86_64 | PIGSTY 1.1.0 | N/A | N/A | N/A | N/A |
| u24.aarch64 | PIGSTY 1.1.0 | N/A | N/A | N/A | N/A |
| u26.x86_64 | PIGSTY 1.1.0 | N/A | N/A | N/A | N/A |
| u26.aarch64 | PIGSTY 1.1.0 | N/A | N/A | N/A | N/A |
Source
github.com/percona/pg_oidc_validator
pg_oidc_validator-1.1.0.tar.gz
Install
Make sure PGDG and PIGSTY repo available:
Install this extension with pig:
Config this extension to shared_preload_libraries:
This extension does not need CREATE EXTENSION DDL command
Usage
Sources:
- pg_oidc_validator 1.1.0 README
- pg_oidc_validator 1.1.0 Keycloak example
- pg_oidc_validator 1.1.0 validator source
- PostgreSQL 18 OAuth authentication
- PostgreSQL 18 libpq OAuth support
pg_oidc_validator 1.1.0 is a PostgreSQL 18 OAuth validator module that validates JWT access tokens against an OpenID Connect provider. It is a server library with no control file or SQL extension, so do not run CREATE EXTENSION.
Configure the Server
Load the module in postgresql.conf, then restart PostgreSQL:
Add an OAuth rule to pg_hba.conf; the issuer and required scope must match the provider. Use hostssl outside a strictly local test:
Reload PostgreSQL after HBA or validator-setting changes; adding the module to oauth_validator_libraries itself requires a restart.
The default authenticated identity claim is sub. To return another stable string claim for role matching, configure:
Version 1.1.0 also provides pg_oidc_validator.discovery_url_override. It changes where discovery metadata and JWKS are fetched without changing the issuer used to validate the JWT iss claim; this is useful when an OIDC provider has different internal and external URLs. Both validator settings are reloadable with SIGHUP.
Without map= in the HBA rule, the selected claim must exactly equal the requested PostgreSQL role. Use a named pg_ident.conf mapping when provider identities and database roles differ; the validator does not create roles.
Connect with libpq
An OAuth-capable libpq client can start the provider’s device authorization flow:
Use oauth_client_secret only when the registered client requires it. The client identifier, requested scope, issuer, and provider configuration must agree.
Provider and Security Boundaries
- Keycloak must enable the OAuth 2 device flow for command-line clients.
- Microsoft Entra ID requires a tenant-specific v2 issuer and custom scopes; use the full scope name in
pg_hba.conf. - Google is not usable through libpq’s built-in device flow, though custom clients may work.
- Dex does not emit OAuth scopes; an explicitly empty
scope=""disables scope validation, which weakens the normal check. - The client
oauth_issuermust exactly match the HBA issuer and the discovery document. Treat the issuer and anypg_oidc_validator.discovery_url_overrideendpoint as trusted security boundaries, and require verified TLS for database and provider connections. - Token validation does not replace PostgreSQL grants, role membership, or row-level security.
- Pigsty RPM packages are limited to EL10; DEB packages cover the supported Debian and Ubuntu targets. PostgreSQL 18 is required.