跳转到主要内容

pg_oidc_validator

OAuth and OIDC token validator for PostgreSQL 18

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
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.

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
Package Version OS ORG SIZE File URL
pg_oidc_validator_18 1.1.0 el10.x86_64 pigsty 142.6 KiB pg_oidc_validator_18-1.1.0-1PGSTY.el10.x86_64.rpm
pg_oidc_validator_18 1.0.0 el10.x86_64 pgdg 173.5 KiB pg_oidc_validator_18-1.0.0-1PGDG.rhel10.2.x86_64.rpm
pg_oidc_validator_18 0.2 el10.x86_64 pgdg 173.1 KiB pg_oidc_validator_18-0.2-1PGDG.rhel10.2.x86_64.rpm
pg_oidc_validator_18 1.1.0 el10.aarch64 pigsty 129.5 KiB pg_oidc_validator_18-1.1.0-1PGSTY.el10.aarch64.rpm
pg_oidc_validator_18 1.0.0 el10.aarch64 pgdg 155.4 KiB pg_oidc_validator_18-1.0.0-1PGDG.rhel10.2.aarch64.rpm
pg_oidc_validator_18 0.2 el10.aarch64 pgdg 154.9 KiB pg_oidc_validator_18-0.2-1PGDG.rhel10.2.aarch64.rpm
postgresql-18-pg-oidc-validator 1.1.0 d12.x86_64 pigsty 108.8 KiB postgresql-18-pg-oidc-validator_1.1.0-1PGSTY~bookworm_amd64.deb
postgresql-18-pg-oidc-validator 1.1.0 d12.aarch64 pigsty 94.5 KiB postgresql-18-pg-oidc-validator_1.1.0-1PGSTY~bookworm_arm64.deb
postgresql-18-pg-oidc-validator 1.1.0 d13.x86_64 pigsty 116.6 KiB postgresql-18-pg-oidc-validator_1.1.0-1PGSTY~trixie_amd64.deb
postgresql-18-pg-oidc-validator 1.1.0 d13.aarch64 pigsty 101.3 KiB postgresql-18-pg-oidc-validator_1.1.0-1PGSTY~trixie_arm64.deb
postgresql-18-pg-oidc-validator 1.1.0 u22.x86_64 pigsty 106.3 KiB postgresql-18-pg-oidc-validator_1.1.0-1PGSTY~jammy_amd64.deb
postgresql-18-pg-oidc-validator 1.1.0 u22.aarch64 pigsty 98.0 KiB postgresql-18-pg-oidc-validator_1.1.0-1PGSTY~jammy_arm64.deb
postgresql-18-pg-oidc-validator 1.1.0 u24.x86_64 pigsty 107.8 KiB postgresql-18-pg-oidc-validator_1.1.0-1PGSTY~noble_amd64.deb
postgresql-18-pg-oidc-validator 1.1.0 u24.aarch64 pigsty 99.6 KiB postgresql-18-pg-oidc-validator_1.1.0-1PGSTY~noble_arm64.deb
postgresql-18-pg-oidc-validator 1.1.0 u26.x86_64 pigsty 120.9 KiB postgresql-18-pg-oidc-validator_1.1.0-1PGSTY~resolute_amd64.deb
postgresql-18-pg-oidc-validator 1.1.0 u26.aarch64 pigsty 105.2 KiB postgresql-18-pg-oidc-validator_1.1.0-1PGSTY~resolute_arm64.deb

Source

pig build pkg pg_oidc_validator;		# build rpm/deb

Install

Make sure PGDG and PIGSTY repo available:

pig repo add pgsql -u   # add both repo and update cache

Install this extension with pig:

pig install pg_oidc_validator;		# install via package name, for the active PG version

pig install pg_oidc_validator -v 18;   # install for PG 18

Config this extension to shared_preload_libraries:

shared_preload_libraries = 'pg_oidc_validator';

This extension does not need CREATE EXTENSION DDL command

Usage

Sources:

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:

oauth_validator_libraries = 'pg_oidc_validator'

Add an OAuth rule to pg_hba.conf; the issuer and required scope must match the provider. Use hostssl outside a strictly local test:

hostssl  all  all  127.0.0.1/32  oauth  issuer=https://id.example.com/realms/postgres scope="openid postgres" validator=pg_oidc_validator

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:

pg_oidc_validator.authn_field = 'email'

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:

psql 'host=127.0.0.1 dbname=app user=alice oauth_issuer=https://id.example.com/realms/postgres oauth_client_id=postgres-client'

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_issuer must exactly match the HBA issuer and the discovery document. Treat the issuer and any pg_oidc_validator.discovery_url_override endpoint 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.