Multi-OrBAC for PostgreSQL

Permissions that live
inside your database

pgmorbac answers one question, can this user do this here? and enforces the answer on every row, for every client that connects. Organizations, roles and contextual rules, in plain SQL.

PostgreSQL 14+ · plain SQL, no service to run · Apache-2.0

psql
CREATE EXTENSION pgmorbac;

-- may this nurse read patients
-- at the north clinic?
SELECT morbac.is_allowed(
    '11111111-…',       -- user
    'clinique-nord',    -- org
    'read',
    'patients'
);
-- t

One rule covers a whole branch

Here is the example the documentation runs on. A nurse must read patient records at one hospital and in every department under it, but nowhere else.

That is a single pgmorbac rule. New departments are covered the day they open, and the other hospital stays invisible on its own.

Groupe Hospitalier Valmontfictional examplenurse · read patients · subtree
Groupe Valmonthead officeClinique NordgrantedClinique SudisolatedPharmaciecoveredCardiologiecoverednurse
The rule you write
INSERT INTO morbac.rules (role, activity, view, org, scope, modality)
VALUES (
    'nurse',                  -- who
    'read',                   -- may do what
    'patients',               -- on which resources
    'Clinique Valmont Nord',  -- where
    'subtree',                -- ...and everything under it
    'permission'
);

Simplified: real rules reference ids and a context. See the org hierarchies recipe.

Grows with the tree

The subtree scope follows the organization tree, so departments opened next year are covered with no new rule.

Isolation by default

The southern clinic stays invisible because nothing grants it: absence of a rule is the isolation.

Enforced per row

Attach morbac.rls_check to the table and the database filters rows itself, in every query, for every client.