Skip to content

eidos_oauth

OAuth 2.0 JWT validator for PostgreSQL 18 using the OAuth validator API.

pg_extensions · OAuth 2.0 JWT validator for PostgreSQL 18 using the OAuth validator API.

Overview

IDExtensionPackageVersionCategoryLicenseLanguage
100979eidos_oauthpg_extensions0.4.0SECMatroid-SAL-1.0Rust

PostgreSQL · 18

Usage

Sources:

eidos_oauth version 0.3.0 validates OAuth bearer JWTs for PostgreSQL 18 connection authentication. It verifies signatures through a remote JWKS endpoint, checks configured issuer and audience claims, returns an authentication identity, and exposes claims as session GUCs for authorization policies.

Core Workflow

Configure the library at server start, then create the SQL extension and inspect the validator state:

shared_preload_libraries = 'eidos_oauth'
oauth_validator_libraries = 'eidos_oauth'

eidos_oauth.jwks_url = 'https://auth.example.com/.well-known/jwks.json'
eidos_oauth.issuer = 'https://auth.example.com'
eidos_oauth.audience = 'my-app'
eidos_oauth.role_claim = 'sub'
eidos_oauth.role_prefix = 'oauth_'
eidos_oauth.jwks_cache_seconds = 300
eidos_oauth.jwks_timeout_ms = 5000
CREATE EXTENSION eidos_oauth;

SELECT eidos_oauth.oauth_jwks_status();
SELECT eidos_oauth.oauth_refresh_jwks();
SELECT eidos_oauth.oauth_validate_token('signed.jwt.value');
SELECT current_setting('app.user_sub', true);

The SQL helpers are oauth_validate_token, oauth_get_claim, oauth_inject_claims, oauth_jwks_status, and oauth_refresh_jwks. Connection-time validation uses the configured claim, defaulting to sub, as the authenticated identity; PostgreSQL role mapping remains responsible for mapping that identity to a database role.

Operational Notes

The connection validator API requires PostgreSQL 18. The source describes oauth_inject_claims as a testing or pre-18 helper, not as a replacement for PostgreSQL 18 OAuth authentication. The control file is non-relocatable and superuser-only. Configuration changes use SIGHUP-context GUCs, but adding the libraries requires a restart. Protect the JWKS endpoint, test key rotation and outage behavior, restrict refresh and token-testing functions, and write RLS policies that treat injected claims as authentication context rather than trusted application input.

Version 0.3.0 Boundary

This is an unsupported proof of concept under Matroid Source Available License 1.0. APIs may change. Version 0.3.0 is the new upgrade baseline: earlier 0.2.0 installations require a rehearsed data migration/recreation, not ordinary ALTER EXTENSION UPDATE. Back up data and dependencies before following that destructive upstream path.

Table reader