# RBAC (role-based access control)

RBAC, role-based access control, is a way of granting access where people get roles and each role carries the permissions a job needs, so access is managed by role instead of person by person. In Meadowstack 2.1 every module keeps its roles and their actions in one table, `domain/permissions.ts`, and every screen asks that table instead of comparing roles.

Checked 2 December 2026. By Bohuslav Poláček. https://meadowstack.com/glossary/rbac/

*The starter's purchase requests: which actions each of the three roles may ever take.*

From `templates/starter/src/modules/requests/domain/permissions.ts` in the Meadowstack repository:

```ts
const own: Action[] = [
  "request.read",
  "request.create",
  "request.edit",
  "request.submit",
  "request.withdraw",
  "request.delete",
  "request.comment",
];
const decide: Action[] = ["request.approve", "request.reject", "request.reopen"];

const roleActions: Record<Role, Action[]> = {
  member: own,
  approver: [...own, ...decide],
  admin: [...own, ...decide],
```

## Why it matters in a business app

A business app has a handful of jobs: the person who asks for a purchase, the person who approves it, the person who runs the system. RBAC matches that. When someone moves from the warehouse to purchasing, you change one role, not forty switches, and an auditor can read who may approve by reading one list.

The model stops at the record. "An approver may approve" is a role rule; "but not their own request" depends on whose record it is. That half is [ABAC](https://meadowstack.com/glossary/abac/), and most real apps need both.

## How Meadowstack handles it

- **One table per module.** `roleActions` (above) maps each role to the actions it may ever take, named `<thing>.<verb>`. The app's own actions (settings, the team) live in `templates/starter/src/workspace/permissions.ts`.
- **Components ask, never decide.** Screens call `<Can>`, `useCan` or `usePermission`; `if (role === "approver")` in a component breaks the rule in AGENTS.md.
- **Actions people cannot take are hidden**, and a page they cannot open shows `NoAccess` under its header.
- **The backend is yours in 2.1.** The simulated api asks the same function before every change, the way your api must, and `docs/recipes/examples/supabase/0001_requests.sql` mirrors the rules in the database. Meadowstack 3.0, coming as an update to every licence, moves the rules into one policy file per app that also generates the database policies.

The whole recipe is `docs/recipes/permissions.md`; the screen side is in [the permissions pattern](https://meadowstack.com/patterns/permissions/).

## Common mistakes

- **A role per person.** Twenty roles for twenty people is a permissions list with extra steps. Keep a few roles that match jobs.
- **Roles compared in components.** The rule then lives in two places and the backend cannot share it.
- **A hidden button as the only check.** Anyone can call the api without your interface; the server and the database ask too.
- **Letting people change their own role.** The starter refuses it, so the app always keeps an admin who can put a mistake right.

## Roles as people see them

*Team and roles in the demo's roastery: each person with one role, changed by an admin.*

A live screen, rendered from the kit's components on the page: https://meadowstack.com/glossary/rbac/

## Questions

### What is the difference between RBAC and ABAC?

RBAC decides by the person's role. ABAC decides by attributes of the person, the record, the action and sometimes the context, such as whose record it is or which status it is in. Most business apps use roles for the broad lines and record attributes for the exceptions.

### How many roles should a business app have?

As few as the jobs require. The starter has three, member, approver and admin, and adds conditions on the record instead of inventing a role for every exception.

### Is hiding a button enough for RBAC?

No. Hiding is for the person; the protection is the same check in the api and in the database, because a request can be sent without the interface.

## Sources

- [NIST, Role Based Access Control project](https://csrc.nist.gov/projects/role-based-access-control), checked 2 December 2026

## Related

- [Team and roles, with the rules in code](https://meadowstack.com/screens/roles-and-permissions/) (Screens)
- [Permissions](https://meadowstack.com/patterns/permissions/) (Patterns)
- [The approval flow](https://meadowstack.com/patterns/approval-flow/) (Patterns)
- [The settings screen](https://meadowstack.com/patterns/settings/) (Patterns)
- [Google Workspace: only your company's domain](https://meadowstack.com/integrations/google-workspace/) (Integrations)
- [Microsoft Entra ID: the person from the token](https://meadowstack.com/integrations/microsoft-entra-id/) (Integrations)
