pgmorbacMulti-OrBAC for PostgreSQL
    DocumentationDownloadSource
    Use cases
    • How do I...?
    Getting Started
    • Introduction
    • Quick start
    • How pgmorbac compares
    • Upgrade
    Concepts
    • Organizations
    • Roles
    • Activities
    • Views
    • Contexts
    • Rules & Modalities
    • Global Rules
    • System Principals
    • Constraints
    • Row-Level Security
    • Decision Cache
    Resolution
    • is_allowed
    Recipes
    • Org Hierarchies
    • Multi-Tenant Isolation
    • Wildcard Admin
    • Delegation
    • Service Accounts
    • Deny Rules
    • Separation of Duty
    • Derived Roles
    • Cross-Org Access
    • Obligations & Recommendations
    • Temporal Access
    Integration
    • Fastify
    • PostgREST & RLS Context
    • SQL Only
    Reference
    • Function Reference
    Reference

    Function Reference

    Every morbac helper function alongside is_allowed: org traversal, roles, cache, audit, config.

    morbac.is_allowed is the front door, but it is built on a family of helper functions you can call directly, whether to compose your own checks, to debug a decision, or to drive an admin UI. Every function lives in the morbac schema.

    Decision

    FunctionReturnsPurpose
    is_allowed(user, org, activity, view)booleanThe cached decision. The one you call in normal use.
    is_allowed_nocache(user, org, activity, view)booleanThe same decision computed from scratch, for debugging.
    rls_check(activity, view, row_org, row_user)booleanThe row-level-security entry point; reads session context. See row-level security.

    Organizations

    FunctionReturnsPurpose
    get_org_ancestors(org)rows of (org_id, depth)The org and every ancestor.
    get_org_descendants(org)rows of (org_id, depth)The org and every descendant.
    get_org_scope(org, scope, max_depth)rows of (org_id, depth)A named slice of the tree: self, children, descendants, subtree, parent, ancestors, lineage, root.
    org_in_scope(asked, rule_org, scope)booleanWhether a rule at rule_org with scope covers asked.

    Roles

    FunctionReturnsPurpose
    get_comprehensive_roles(user, org)rows of (role_id, source, depth)Every effective role: direct, delegated, derived, inherited.
    get_effective_roles(user, org)rows of (role_id, depth)Direct plus inherited roles.
    get_inherited_roles(role)role idsRoles a given role inherits through the hierarchy.
    user_roles_in_org(user, org)role idsThe user's directly assigned roles in an org.
    user_has_role(user, org, role_name)booleanA quick membership check.
    assign_role(user, role, org)voidAssign a role, enforcing separation of duty and cardinality.
    revoke_role(user, role, org)voidRemove a role assignment.

    Activities and views

    FunctionReturnsPurpose
    get_effective_activities(activity)activity namesThe activity plus every senior activity that implies it.
    get_effective_views(view)view namesThe view plus its hierarchy expansion.

    Contexts, obligations, recommendations

    FunctionReturnsPurpose
    eval_context(context_id)booleanEvaluate a context's predicate now.
    pending_obligations(user, org)rowsDuties the user currently owes (obligations recipe).
    pending_recommendations(user, org)rowsAdvisory actions not voided by a prohibition or obligation.

    Session context (RLS)

    FunctionReturnsPurpose
    current_user_id()uuidThe acting user from the session.
    current_org_id()uuidThe single org in scope, if set.
    current_org_ids()uuid[]The org list in scope, if set.
    current_target_user_id()uuidThe per-user row filter, if set.
    get_user_orgs(user)org idsEvery org the user holds a role in.

    Cache and audit

    FunctionReturnsPurpose
    invalidate_cache(user, org)voidFlush cached decisions for a user/org (both optional).
    invalidate_all_cache()voidFlush the whole decision cache.
    cleanup_auth_cache()voidDelete expired cache rows (housekeeping).
    enable_audit(table) / disable_audit(table)voidAttach or detach the audit trigger on a table.

    Constraints and configuration

    FunctionReturnsPurpose
    check_sod_violation(user, role, org)booleanWhether assigning a role would break separation of duty.
    check_cardinality_violation(role, adding)booleanWhether a role's user cap would be exceeded.
    get_config(key) / set_config(key, value)text / voidRead or change runtime settings such as cache_ttl_seconds and schema_version.

    All of these are plain SQL functions: call them from any language, or from psql, exactly like is_allowed.

    PreviousSQL Only
    pgmorbac - Multi-OrBAC permission engine for PostgreSQL
    DocumentationDownloadGitea