pg_oidc_validator
Overview
| Package | Version | Category | License | Language |
|---|---|---|---|---|
pg_oidc_validator | 1.1.0 | SEC | Apache-2.0 | C++ |
| ID | Extension | Bin | Lib | Load | Create | Trust | Reloc | Schema |
|---|---|---|---|---|---|---|---|---|
| 7170 | pg_oidc_validator | No | Yes | Yes | No | No | No | - |
Configure oauth_validator_libraries=pg_oidc_validator; 1.1.0 adds discovery_url_override; RPM is available on EL10 only while DEB covers all supported Debian and Ubuntu targets.
Version
| Type | Repo | Version | PG Ver | Package | Deps |
|---|---|---|---|---|---|
| EXT | PIGSTY | 1.1.0 | 1817161514 | pg_oidc_validator | - |
| RPM | PIGSTY | 1.1.0 | 1817161514 | pg_oidc_validator_$v | - |
| DEB | PIGSTY | 1.1.0 | 1817161514 | postgresql-$v-pg-oidc-validator | - |
Build
You can build the RPM / DEB packages for pg_oidc_validator using pig build:
Install
You can install pg_oidc_validator directly. First, make sure the PGDG and PIGSTY repositories are added and enabled:
Install the extension using pig or apt/yum/dnf:
Preload:
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.
Was this page helpful?
Thanks—your feedback helps us improve this page.
What got in the way? (optional)