pgauthz
pgauthz · Provide Zanzibar-style relationship-based authorization inside PostgreSQL
Overview
| ID | Extension | Package | Version | Category | License | Language |
|---|---|---|---|---|---|---|
| 100850 | pgauthz | pgauthz | 0.3.0 | SEC | Apache-2.0 | Rust |
PostgreSQL · 16, 17, 18
Usage
Sources:
pgauthz implements Zanzibar-style relationship-based authorization inside PostgreSQL. Policies define object and subject types, relations, computed permissions, conditions, and wildcards; relationship tuples then drive checks. It targets PostgreSQL 16 through 18 and keeps policy, tuple, revision, changelog, and assertion data in the authz schema.
Core Workflow
Define a policy, write a relationship, and check it on the same database transaction boundary as application data:
Use pgauthz_check_with_context when a declared condition requires runtime JSON context, and enforce the boolean result in the same statement or security-definer boundary that protects the resource.
Important Objects
pgauthz_define_policyparses and versions the active authorization model.pgauthz_add_relationandpgauthz_write_relationshipscreate or change relationship tuples.pgauthz_checkandpgauthz_check_with_contextevaluate a relation or computed permission.pgauthz_list_objectsandpgauthz_list_subjectsenumerate reachable resources or principals.pgauthz_expandreturns a permission tree for debugging.pgauthz_read_relationships,pgauthz_read_latest_policy, andpgauthz_read_changesexpose stored state and changes.authz.*GUCs control check strategy, cache TTL and capacity, revision quantization, tracing, and OpenTelemetry export.
Security and Consistency Notes
An authorization function does not enforce access unless every data path actually calls it or a correct RLS/policy wrapper. Revoke direct access to protected tables and to the underlying authz relations from application roles. Caches are disabled by default; enabling TTLs or revision quantization trades freshness for speed, so test revocation latency explicitly. Treat policy changes and relationship writes as security-sensitive audited operations, validate condition context types, and protect OpenTelemetry endpoints from leaking authorization metadata.