Skip to content

jwt_context

Experimental JWT-signed session context for SQL and row security

jwt_context · Experimental JWT-signed session context for SQL and row security

Overview

IDExtensionPackageVersionCategoryLicenseLanguage
102282jwt_contextjwt_context1.0.0SECBSD-2-ClauseC

PostgreSQL · 14, 15, 16, 17

Usage

Sources:

jwt_context 1.0.0 is an experimental signed session context for SQL and row-security policies. It verifies HS256 or ES256 signatures before accepting a JSON context. The reviewed CI matrix covers PostgreSQL 14–17. Install as a superuser; the extension is relocatable.

Read a Verified Context

CREATE EXTENSION jwt_context;
SELECT jwt();
SELECT jwt('TENANT_ID');
RESET jwt.context;

A trusted administrator sets jwt.secret for HS256 or jwt.pubkey for ES256; both are superuser-only settings and hold base64url-encoded key material. The application sets jwt.context to a valid token from its trusted signer. jwt() returns the JSONB claims and jwt(key) reads one claim as text. The helpers jwt_sign, jwt_verify, jwt_generate_keys and jwt_generate_secret are provided for experimentation; protect signing secrets and do not expose signing privileges to application users.

Security and Connection Pools

Applications must connect as unprivileged roles: a superuser or a user allowed to replace the verification key can forge a context. Signature validity does not establish application authorization. The prototype does not enforce token expiration or revocation; design those checks outside it before relying on a token. A leaked signed token can be replayed.

The context is session state. Reset it before a pooled connection is handed to another user; use RESET or RESET ALL as appropriate, and test the pool’s actual reset behavior. Review the upstream threat model before using this experimental module for row security.

Table reader