Two people can have the same job title and need very different access. A delivery manager may need engagement details without seeing every commercial negotiation. Someone in finance may need payment records but should never be able to change scope. Once you try to cover that with roles named after job titles, you end up with a growing pile of exceptions that nobody can explain six months later.
This piece is adapted from a Centravon™ resource on CRM permissions. The examples and code below are illustrative, with made-up resources and field names, so adapt them to your own stack.
Split "access" into actions
A single "access" checkbox hides several different capabilities. Viewing, editing, deleting, approving, exporting and administering are separate operations with separate consequences, and they deserve separate rules.
Start with a matrix. Each row says who can do what, to which resource, inside what scope, and under which conditions.
| Role | Resource | Action | Scope | Condition |
|---|---|---|---|---|
| Relationship owner | Account | view, edit | Assigned accounts | None |
| Relationship owner | Credit | request | Assigned accounts | Approval required |
| Finance | Payment | view | Organization | None |
| Finance | Credit | approve | Organization | Not the requester |
| Operations lead | Schedule | edit | Own business unit | Contracted rate is read-only |
| Admin | User role | assign | Organization | Change is logged |
Walk through each row with the people who are accountable when something goes wrong. A relationship owner who can update an account but can't approve a credit is a decision the business has to own. It shouldn't fall out of whatever the default role happened to allow.
Decide where access stops
Scope is the part teams skip. Access can be bounded by record, account, team, business unit, region or the whole organization. Write down how shared accounts work and what happens during temporary assignments.
Be careful with hierarchy. A manager role doesn't automatically need unrestricted access to everything below it in the org chart. If that's the intent, make it an explicit rule rather than a side effect of how the tree is modeled.
The model also has to cover people joining, changing roles and leaving. Temporary privileges need an expiry or a review date. Without one, exceptional access piles up until the system no longer matches the boundary you meant to draw. A simple way to make expiry the default is to store it on the grant itself:
CREATE TABLE access_grant ( id BIGSERIAL PRIMARY KEY, user_id BIGINT NOT NULL, role TEXT NOT NULL, scope_type TEXT NOT NULL, -- 'account', 'team', 'business_unit', 'org' scope_id BIGINT, granted_by BIGINT NOT NULL, reason TEXT NOT NULL, expires_at TIMESTAMPTZ, -- NULL only for standing role grants created_at TIMESTAMPTZ NOT NULL DEFAULT now() ) Then a scheduled query turns old exceptions into a review list instead of letting them sit:
SELECT user_id, role, scope_type, scope_id, granted_by, reason, created_at FROM access_grant WHERE expires_at IS NULL AND role NOT IN ('relationship_owner', 'finance', 'operations_lead') AND created_at < now() - INTERVAL '90 days' ORDER BY created_at The 90 days is a placeholder. Pick a review cycle that fits your own policy.
Enforce the rule where the action happens
Hiding a button makes the interface cleaner. It doesn't secure the request behind it. Anyone with a browser dev tools panel or a copy of the API call can still send it. Authorization has to be checked by the system that processes the operation, on every request.
The OWASP Authorization Cheat Sheet boils it down to a few habits worth building in from day one: least privilege, deny by default, and validate permissions on every request. Here's what that looks like as a small Python check that every handler calls before it does any work:
from dataclasses import dataclass @dataclass(frozen=True) class Rule: role: str resource: str action: str scope: str # "assigned", "business_unit", "org" RULES = { Rule("relationship_owner", "account", "view", "assigned"), Rule("relationship_owner", "account", "edit", "assigned"), Rule("relationship_owner", "credit", "request", "assigned"), Rule("finance", "payment", "view", "org"), Rule("finance", "credit", "approve", "org"), } def in_scope(user, record, scope): if scope == "org": return record.org_id == user.org_id if scope == "business_unit": return record.business_unit_id in user.business_unit_ids if scope == "assigned": return record.owner_id == user.id or record.id in user.assigned_ids return False def is_allowed(user, action, resource, record): for role in user.active_roles(): # active_roles() drops expired grants for rule in RULES: if (rule.role, rule.resource, rule.action) == (role, resource, action): if in_scope(user, record, rule.scope): return True return False # deny by default A few details matter more than the code style. The check runs on the server. It loads the record before deciding, so scope is evaluated against real data and not whatever the client sent. Anything not listed is denied. And conditions like "an approver can't approve their own request" belong in the same place, so they can't be skipped by calling a different endpoint.
Test the denied paths
Most acceptance testing checks that people can do their jobs. Fewer test plans check that people can't do things outside them. Both matter.
Test direct requests as well as clicking through the UI. If a user can't see a record in a list, they also shouldn't be able to fetch it by changing the ID in the URL. That's the classic insecure direct object reference, and it shows up whenever filtering happens in the list view but not in the detail endpoint.
Give export and bulk operations their own scenarios. One export can expose far more data than any single screen, and bulk update endpoints often skip the per-record checks that the single-record path enforces.
Writing the role scenarios as regression tests keeps a later change from quietly widening access:
import pytest DENIED = [ ("finance", "PATCH", "/api/engagements/{other}/scope"), ("relationship_owner", "GET", "/api/accounts/{unassigned}"), ("relationship_owner", "POST", "/api/credits/{own_request}/approve"), ("operations_lead", "PATCH", "/api/contracts/{in_unit}/rate"), ("relationship_owner", "GET", "/api/accounts/export?all=true"), ] @pytest.mark.parametrize("role,method,path", DENIED) def test_denied_paths(client_as, fixtures, role, method, path): client = client_as(role) response = client.request(method, path.format(**fixtures)) assert response.status_code in (403, 404) Returning 404 instead of 403 for records outside someone's scope is a reasonable choice when you don't want to confirm that a record exists. Pick one behavior and test for it consistently.
Log the decisions that matter
Decide which changes need a record of who acted, when and on what. Approvals, permission changes and sensitive exports usually make that list. They may need different levels of detail.
Logging everything just because you can is its own risk. Logs can end up holding the same sensitive data you were trying to protect. Choose meaningful events, restrict who can read the logs, set a retention period on purpose, and keep secrets and full record payloads out of them. The OWASP Logging Cheat Sheet is a good reference for what to capture and what to leave out.
A useful test is to hand an authorized reviewer the logs and ask them to reconstruct one decision. Who approved the credit, under which role, and when was that role granted? If they can't answer from the records, the logging design needs work.
Keep the matrix alive
The permission matrix is a maintained artifact. Review it whenever a new workflow, team or integration shows up. Integrations deserve attention because service accounts tend to get broad access during setup and keep it forever.
Store the matrix next to the code that enforces it, review changes to it like code, and run the denied-path tests in CI. When someone asks whether a system is "enterprise secure," the honest answer is the boundary, the operation and the test behind it.
Checklist
- [ ] List view, edit, approve, export and admin actions separately
- [ ] Define record and organizational boundaries for each role
- [ ] Put an expiry or review date on temporary grants
- [ ] Enforce authorization on the server for every request
- [ ] Test denied access through direct requests, exports and bulk operations
- [ ] Agree on audit events, who can read them and how long they're kept
- [ ] Re-review the matrix when workflows, teams or integrations change
Further reading
Originally published at centravon.app.

