signed_vault
rls-examples · Historical RLS application-identity example using signed session settings
Overview
| ID | Extension | Package | Version | Category | License | Language |
|---|---|---|---|---|---|---|
| 101997 | signed_vault | rls-examples | 1.0 | SEC | SQL |
Usage
Sources:
signed_vault is a historical SQL demonstration of application identity context for row-level security. Version 1.0 comes from the 2016 rls-examples source snapshot; it is an example to review and adapt, not a production authentication framework.
Core Workflow
Install the files, enable pgcrypto, then create signed_vault as an administrator. PL/pgSQL is required. Objects live in the fixed signed_vault schema; there is no shared library or preload step. In this psql example, supply the vault_passphrase variable securely before running it, and initialize the key table only once.
The setter checks the shared passphrase and stores a signed session value in signed_vault.username. It returns the context token. The getter returns the application username only while the context passes validation and is less than one day old; missing or expired context raises an error.
Objects and Operational Boundaries
set_username(text,text)andget_username()are publicly executable security-definer functions; possession of the shared passphrase authorizes setting an application username.key_vaultholds the protected credential material. The SQL revokes public access and grants schema usage for the API. Restrict administrative table access and protect the credential when sending SQL.- The functions do not set a fixed
search_pathand call unqualified helper functions. Review owner privileges and schema trust before allowing untrusted SQL callers. - Session context persists across transactions. A connection pool must establish the correct context for every checkout and must not leak a previous caller’s token.
- No current PostgreSQL compatibility matrix or explicit license is supplied. Keep this historical demonstration separate from claims of modern security or support.