Skip to content
Book a call

Role-based access meets a real org chart

· 4-minute read · Engineering · by Direct Softworks

The permissions model is usually correct and the screens still leak. Gating the action is not the same as gating the view, and only one of them is tested.

Every permission system starts with four roles and a table. Admin, manager, user, viewer. It is clean for about a month.

Then somebody needs to see costs but not salaries. A contractor needs one project and nothing else. The accountant needs every invoice and no client contact details. A sales lead needs their own team's numbers. None of these is unreasonable and none of them fit four roles.

The two failure modes

Too few roles, and people get access they should not have, because the alternative was blocking them from doing their job. This is the common one, and it is almost never a decision. It is a series of small accommodations.

Too many roles, and nobody can say what any of them mean. We have seen a system with nineteen roles, of which four were in use, and the other fifteen existed because it was easier to add one than to work out which existing role fit.

The way out of both is to stop modelling jobs and start modelling capabilities.

Capabilities, composed into roles

A capability is one thing a person can do, named precisely: invoice.create, invoice.void, client.view_contact, project.view_cost, report.export.

A role is a named set of capabilities. Job titles map to roles; permissions checks only ever ask about capabilities.

The payoff comes the first time somebody needs a variation. The accountant who should not see contact details is not a new role, it is the existing role minus one capability. Nobody has to reason about what nineteen roles mean, only about whether this person should be able to do this specific thing.

Keep the mapping in one table, in code, reviewable in a diff. Not scattered across the components that happen to need it. When somebody asks "who can void an invoice", that must be a question you answer by reading one file, not by grepping.

The gap almost everybody has

Here is the failure worth the whole article, because it survives a correct permissions model and a passing test suite.

The action is gated. The screen is not.

The void-invoice endpoint checks invoice.void and refuses correctly. The invoice page renders a Void button for everyone, and the button fails when pressed. Annoying, not dangerous.

But the same page also renders the total revenue for the client, the margin on the project and the contractor's hourly rate, because the page was written once for the role that should see all of it. The lawyer, whose entire reason for existing as a role is that they do not see the ledger, opens a client record and reads the ledger.

Nothing refused. No permission was violated, because no action was attempted. The data was handed over by the render.

A test that asks "does the action check permissions" cannot see this. It passes. We have audited systems where every single action was correctly gated and half the screens leaked, and the leak had been there since the day the second role was added.

What to do about it

Make the view take a scope, not a user. A rendering function that receives "who is looking" will eventually forget to ask. One that requires an explicit scope object cannot render without somebody having decided what this viewer sees.

Test the render, not just the endpoint. For each sensitive field, one test: role X loads page Y, assert the field is absent from the response. Tedious and it is the only thing that catches this class.

Hide what cannot be used. A button that fails on press is a small cruelty and a large hint. It tells a curious person exactly which capabilities exist, which is the first step of any interesting attack, and it wastes the time of every honest user.

Audit by reading pages, not by reading the policy. The policy is nearly always right. Go through the screens as each role and write down what you can see.

Two things that always come up

Ownership is a dimension, not a role. "Can edit their own projects" is not a role, it is a rule about the relationship between the actor and the record. Model it separately, or you get manager and manager_own and the combinatorics eat you.

Record who can grant what. The ability to change permissions is itself a capability, and it is the one worth logging most carefully. A system where an admin can quietly promote themselves and nothing records it has an audit gap exactly where it matters, which is what a decent audit log is for.

The thing to accept

There will be exceptions. One person who needs something the model does not express, usually a director, usually urgently.

Handle it as an explicit capability grant to a named individual, with a reason and a date, visible in the same table as everything else. What you must not do is add a role for them, or add a check for their user id in the code. Both work on the day and both are invisible in a year, and the second one has a way of outliving the person it was written for.

More notes