Use case
When roles are no longer enough: modelling access scope from the org chart
Two users, the same role, different data: lessons from an access control model built on the company's actual organisation chart.
7 min readMouhcine EL HASNAOUI
- Gestion des accès
- IAM
- Plateforme sur mesure
- Supply chain

In a business application, managing access seems simple at first: a user has a role, and that role grants certain permissions. This model works as long as rights remain global.
But what happens when two users with the same role must not access the same data? Or when one manager can act on an entire division, while another user is limited to a specific team?
That is when the role is no longer enough. The system needs to understand what the user can do, but also where they can do it.
This is precisely the problem we faced when evolving a recent business application. So we redesigned the access control model around a simple principle: use the company’s actual organisation as the basis for access scope.
1. From role to scope: the limit of classic RBAC
RBAC (Role-Based Access Control) associates permissions with roles and answers the question “what can they do?”. Yet UPDATE_DOSSIER does not say which files can be modified. Two managers share this permission: one reports to the Import Division, the other to the Finance Division. Giving them global access would ignore their operational responsibility.
Creating “Import Manager” and “Finance Manager” roles, then variants for each department, is tempting. This approach couples rights to the org chart: every reorganisation leads to new assignments and a risk of inconsistency. The rules become hard to explain and to test.
The chosen model separates three elements: the role, which groups responsibilities; the permission, which names the action; and the scope, which defines the resources concerned. The decision becomes contextual: an operation is only allowed if the user has the permission AND the resource belongs to the applicable scope. The principle of least privilege is thus expressed in the business model, without confusing authentication and authorisation.
2. The org chart as the source of access scope
The organisation is represented by nodes: company, division, department or team. Each node has an identifier and, except for the root, a parent. This tree accepts variable depths without changing the schema or multiplying roles.
Attaching a user to a node defines their starting point. The scope considered includes this node and its descendants. So an Import manager can have rights over the files of their departments; a Finance manager does not get this scope just by sharing the same permission.

Figure 1 — The same right can apply to separate organisational subtrees.
The formula is deliberately simple: permissions answer “what can they do?”; the org chart answers “where can they do it?”. This separation also makes administration easier: moving a team changes its position in the hierarchy rather than the definition of permissions. In return, it requires each protected resource to be reliably linked to its organisational node.
3. Turning the hierarchy into access decisions
3.1. Parent-child, recursive CTEs and Closure Table
OrgNode(id, nom, parent_id) is enough to store the hierarchy. To check that a file from Team A1 belongs to the Import Division, a recursive CTE walks up the parents or explores the descendants. This option remains suitable for infrequent traversals or structures that change a lot.
In a supply chain management application, we chose a Closure Table to make ancestor-descendant relationships explicit. Each row links an ancestor, a descendant and a depth; the relationship of a node with itself, at depth zero, can also be stored. Checking membership becomes a lookup of a relationship rather than rebuilding a path on every check. At the current scale (35 nodes and 5 levels), a recursive CTE would also have worked: the choice is mainly about keeping repeated checks and filtered file lists simple, without claiming any measured latency gain.
| Ancestor | Descendant | Depth |
|---|---|---|
| Import Division | Department A | 1 |
| Import Division | Team A1 | 2 |
| Department A | Team A1 | 1 |
| Team A1 | Team A1 | 0 |
Table 1 — Simplified example of relationships stored in the Closure Table.
The two tables complement each other: parent_id expresses the business structure; the Closure Table materialises its paths for repeated hierarchical queries. Indexes on (ancestor, descendant) pairs are essential, as are regression tests on creating, attaching and deleting nodes.
3.2. An optimisation that also has a cost
The Closure Table has a cost. The number of rows grows with the nodes and the depth; a deep tree can become large. Each insertion adds links, while moving a subtree requires recalculating the relationships concerned. To avoid divergence between parent_id and the paths table, updates must be atomic and controlled. A scope cache also requires invalidation when reorganisations or rights changes occur. This structure is justified when repeated hierarchical queries make up for these more expensive writes.
3.3. Checking when the resource is accessed
On the application side, the check must not stop at whether a button is displayed or a role is present in a token. The backend must identify the requested action, check the effective permission, find the resource’s node and test whether it belongs to the authorised scope. If either condition fails, or if a required piece of information is missing, access must be denied by default. The same rule must protect both reading filtered lists and accessing a file directly by its identifier.

Figure 2 — Authorisation decision: effective permission and organisational membership.
4. Why a built-in engine rather than a dedicated service?
Before choosing an in-house engine, the alternatives need comparing. OpenFGA and SpiceDB model relationships between subjects and resources (ReBAC); Cedar and OPA express policies; Keycloak and Okta offer authorisation capabilities. All of them require reliable business data to determine a resource’s scope.
| Approach | Main strength | Trade-off for a supply chain application |
|---|---|---|
| Built-in engine | Nodes and files close to the business | A simple model; tests, security and evolution to maintain. |
| OpenFGA (ReBAC) | Fine-grained access relationships and a dedicated API | Managing and synchronising a relationship store. |
| SpiceDB (ReBAC) | Permission graph and dedicated checks | An additional model and additional operations for a tree-shaped need. |
| Cedar / OPA | Expressive policies, separable from the code | Providing the business attributes and relationships for each decision. |
| Keycloak | Centralised permissions, resources and policies | Adapting its authorisation services to the business scope. |
| Okta | Identities, scopes and API access policies | Keeping control of business files in the application. |
Table 2 — Six options examined through the specific need of a business hierarchy.
For this supply chain application, a built-in engine kept nodes, files and scope rules close to the existing model, without a second store for logic that is essentially tree-shaped. This trade-off does not mean that specialised tools would perform worse, nor that an in-house solution would always cost less.
The decision should be reassessed if several applications share the same policies, if the relationships become a complex graph, or if audit and governance require a centralised engine. “Build” also brings a lasting responsibility: authorisation tests, traceability, security review and rule maintenance.
5. The case in figures
Two indicators describe the organisational structure currently modelled: 35 nodes and a depth of 5 levels. These are characteristics of the organisation reference data, not a benchmark of the access control check or of a complete endpoint.
| Indicator | Value |
|---|---|
| Organisational nodes | 35 nodes |
| Current depth | 5 levels |
Table 3 — Size of the modelled org chart.
The 35 nodes represent the current volume, not a capacity limit. The 5 levels describe the depth of the org chart in place; they serve to put the storage and updates of the Closure Table into context. No performance result is put forward without a verifiable measurement protocol.
The main lesson is architectural: separating the right to act from the extent over which it applies makes the rules easier to read. The Closure Table is one possible answer to the cost of repeated hierarchical checks, but it requires discipline on updates. And the choice of an in-house engine must stay proportionate to the actual complexity of the need.
Conclusion — Making security reflect the business
A sound access control system is not just a list of roles. As soon as decisions depend on a business structure, the org chart becomes an explicit part of authorisation. In this supply chain application, this principle guided a model combining fine-grained permissions and hierarchical scopes, with a Closure Table to query these relationships.
For the user experience side of the same module, read Mohamed Staili’s article: “How to offer a smooth user experience for a supposedly complex system”.
At We Are Beebay, we favour this kind of approach: start from an operational constraint, set out the trade-offs and build a maintainable solution. Looking to get control of access rights that have become hard to evolve? Let’s talk about how to align your access rights with your business organisation.


