grants_manager
pg_grants_manager · Declarative PL/pgSQL toolkit for snapshotting, reporting, and aligning database object grants.
Overview
| ID | Extension | Package | Version | Category | License | Language |
|---|---|---|---|---|---|---|
| 100182 | grants_manager | pg_grants_manager | 0.0.1 | SEC | Unknown | SQL |
| Relationships | |
|---|---|
| Requires | plpgsql |
Usage
Sources:
grants_manager is a small PL/pgSQL toolkit for snapshotting table and sequence privileges into an editable matrix, reporting drift, and optionally applying the declared grants. Use it only under controlled administration: applying the matrix executes REVOKE ALL and new GRANT statements.
Core Workflow
gm_generate_current() rebuilds public.grants_manager from current table and sequence ACLs, renaming the previous matrix to grants_manager_old. Each role becomes an array column. Edit those arrays, run gm_align_permissions(false) for notices only, review the proposed changes, and use gm_align_permissions(true) only when ready to change privileges.
Main Objects
gm_generate_current()creates the editable privilege snapshot.gm_get_status()reports current grants asschema_name,object_name,grantee, andgrants.gm_align_permissions(boolean)reports or applies differences.gm_translate(text)maps PostgreSQL privilege names to ACL letters and back.
The ACL letters used by the implementation include r for SELECT, w for UPDATE, a for INSERT, d for DELETE, D for TRUNCATE, x for REFERENCES, t for TRIGGER, and U for USAGE.
Caveats
Version 0.0.1 handles ordinary tables and sequences and does not claim complete coverage of every grantable object. The upstream README lists group-role alignment as unfinished. Snapshot generation replaces the working matrix, while execution revokes all privileges before re-granting the declared set. Test with representative ownership, quoted identifiers, schemas, role inheritance, and concurrent changes before using it in production.