Skip to main content

Case Study

Six Keys, One Resolver — the Role Authority Model

8 September 2026

About This Project

A shipping SaaS has to answer, on every request, one question: is this person allowed to do this thing? An admin can approve a KYC. A super-admin can approve a rate publish. An accountant can read the ledger. A merchant can ship an order. A sub-user can do exactly what their tenant allows, no more. Get the authority model wrong and either the platform is unusable (every action is refused for want of a specific permission), or the platform is unsafe (a plain admin has quiet access to the reserved decisions that should sit with the super-admin).

Celestial Infosoft built the Role Authority model behind ShipShop 2.0. Every endpoint on the platform gates on a specific key from a single permission catalogue. A reserved set of super-admin-only keys — the money and the meta-authority ones — cannot be granted to a plain admin through the ordinary permissions matrix; the only sanctioned path is a time-bounded elevation issued by a super-admin. A ₹25,000 payout limit means an ordinary admin can move most money but not the largest movements. The whole model is enforced at CI with source-level tests that fail if the boundary shifts.

The Challenge

Most SaaS authority systems are built around roles — a user has a role, a role has a fixed permission set, a role check gates every endpoint. That model breaks the moment a role needs to be tuned for a specific person, or a specific capability needs to be added to a specific role for a limited period, or a specific action within a role's normal scope needs a higher approval level. You end up either creating too many roles (a specific role for every specific tuning), or adding role-checks everywhere (a dozen if role == 'admin' lines that drift).

The brief was: every action on the platform gates on a specific permission key. A permission catalogue lists every key. A role has a baseline set of keys. A specific user under that role can have specific extra keys granted, or specific baseline keys revoked. A reserved set of keys — rate publishing, margin management, payout authorisation, admin-account management, identity settings, and the profit report — cannot be granted through the ordinary matrix; only a super-admin holds them, and only a super-admin can grant them temporarily to a specific admin for a specific window.

1. A single permission catalogue

Every capability on the platform — every menu item, every endpoint, every action — is a key in PERMISSION_CATALOG. The catalogue is grouped by module (Merchants, Orders, Couriers, Accounting, Admin) and shipped to the frontend so the roles-management screen renders itself from the same source of truth the backend gates on. A new endpoint adds a new key; a new key appears on the roles screen automatically. Two copies of "what keys exist" is exactly how the frontend and backend drift into disagreeing about which admin can do what.

2. Role baselines, per role

Every role has a baseline permission set. role_matrix() returns the mapping — super_admin gets everything (all catalogue keys + all reserved keys). Admin gets everything except the reserved keys. Accountant gets read-only access to the accounting surfaces and nothing else. Sub_user's baseline is empty; grants come from their tenant's SubUserAccess table. Merchant, franchise, agency, affiliate get the tenant-owner keys they need to run their own tenant. The baseline is what a fresh user under that role starts with; user-specific grants and revocations layer on top.

3. effective_keys — the resolver

Every endpoint gate calls effective_keys(user, db). The resolver reads the user's role, looks up the baseline, unions the user's granted keys from user_permissions, subtracts the user's revoked keys, unions the user's currently-active elevations (see below), strips reserved keys if the role is not super_admin, and returns the final key set. Every check on every endpoint asks the same question of the same resolver — no per-endpoint role branching, no if user.role == 'admin' lines scattered through the codebase. A future change to how permissions layer lands in one function, once.

4. Reserved keys, held by super-admin alone

Six keys are reserved: rates:publish (approve a rate matrix), margin:manage (set a courier's margin), reports:profit (see the profit report, which shows real buy rates), identity:manage (edit GST and legal identity), payouts:authorize (approve a payout above the platform limit), and admins:manage (create, disable or reduce another admin). A super-admin's baseline includes them. Every other role's baseline does not. The ordinary permission-write endpoint filters reserved keys out of any grant — a super-admin cannot slip a reserved key into an admin's user_permissions row by mistake, because the API refuses. The only sanctioned path is elevation.

5. Time-bounded elevation

A super-admin can grant a specific admin a specific capability (including a reserved key, with one exception below) until a specific timestamp. The elevation lives in permission_elevations, expires at the timestamp with no cron job needed (effective_keys filters expired rows at read time), and is auditable to the super-admin who issued it, the reason they gave, and the admin who received it. An elevation writes an audit row on issue, on revoke, and on natural expiry. The one exception: admins:manage is not itself elevatable, because a self-perpetuating elevation ring — an admin issues themselves the key that lets them issue more elevations — is closed at both the write path (the API refuses) and the read path (a tampered row naming admins:manage still confers nothing at resolve time).

6. The ₹25,000 payout limit

Every payout endpoint — a credit-facility approval, a COD remittance, a complaint compensation, a merchant credit request — calls assert_payout_authority(user, amount). If amount > settings.payout_super_limit_inr (default ₹25,000, env-configurable), the request requires payouts:authorize. A plain admin can approve most everyday money movements. A large one goes to the super-admin, or to an admin they have elevated for the window in which the payout is being processed. Every money-out surface calls the same guard — no per-endpoint threshold copy, no ordering trap where the check ran after the debit committed.

7. Instant revocation

Disabling an admin account revokes their access on the very next request. The access token dies because get_current_user re-loads the user's status on every call — a JWT that has not expired but names a disabled user is refused. The refresh token is revoked in the same atomic commit with reason "disabled", so the reuse-grace window cannot mint a fresh session on a stale token. Instant, not "eventually consistent". A super-admin disabling an admin at 12:03:04 UTC has revoked them at 12:03:04 UTC.

8. Reduce-rights, not just increase

A specific admin can be granted a specific extra key over their role's baseline (increase), or a specific baseline key can be revoked from them (reduce). user_permissions.revoked is a JSONB list, defaulting to empty; the resolver subtracts it from (baseline ∪ granted) so a revoke works on both the granular and the coarse permission surfaces. Reserved keys cannot be revoked (there is nothing to revoke — no non-super holds them), and a user cannot re-permission their own account, so a rogue admin cannot lift their own restrictions.

9. The last-super-admin floor

Disabling or demoting the last active super-admin is refused. A TOCTOU-safe check inside the disable/demote handler uses pg_advisory_xact_lock so two concurrent super-admin disables of two different super-admins cannot both reach zero. The platform cannot lock itself out of super-admin authority through a race. This guard exists because the alternative is a support incident that only becomes visible when a super-admin task next surfaces — a rate approval that nobody can approve, a payout limit that nobody can authorise.

The Outcome

ShipShop 2.0's authority model gates every endpoint on a specific permission key, resolves that key through a single shared resolver, holds a reserved set of the highest-impact capabilities in the hands of the super-admin alone, offers time-bounded elevation as the one sanctioned path to lend a reserved key to an admin, and audits every issue, use and expiry. The class of defect where a plain admin accumulates authority they should not have — through UI oversight, through role drift, through a stale permission row that outlives the role — is structurally closed. Every endpoint asks the same question of the same resolver. Every grant, revoke, elevation and disable is logged. The last super-admin cannot lock themselves out.

Delivered by Celestial Infosoft.

Have a similar project in mind?

Tell us what you're building and we'll get back to you within one business day.

Get in touch