{"canonical_url":"https://engineer.company/glossary/rbac/","content_markdown":"# RBAC\n\n## What it is\n\nRBAC decides what someone may do by looking at the roles they hold rather than\nat who they are. The letters stand for role-based access control, and NIST,\nwhere the model was formalised, also calls it “role based security”. A role is a\nnamed collection of permissions, such as “accounts clerk” or “read-only on\nproduction”. Users are assigned roles, and every permission a user exercises\narrives through one of them.\n\nDavid Ferraiolo and Rick Kuhn of NIST proposed the general model in 1992, as an\nalternative to the mandatory and discretionary access control of the day. In\n1996 Sandhu, Coyne, Feinstein and Youman split it into layers: RBAC0 with users,\nroles and permissions, RBAC1 adding role hierarchies, RBAC2 adding constraints,\nand RBAC3 with both. The two lines were unified and became the standard\nANSI/INCITS 359-2004, revised in 2012. Its reference model has four components.\nCore RBAC, the only one every system must have, holds the assignments of users\nto roles and permissions to roles, plus the session, in which a user activates a\nsubset of the roles assigned. Hierarchical RBAC lets a senior role inherit a\njunior one. Static separation of duty constrains which roles one user may be\nassigned together, and dynamic separation of duty constrains which roles may be\nactive at once in a session, so someone can hold both the role that raises a\npayment and the role that approves it without using both in one sitting.\n\nThe difference from an ordinary group is narrower than it looks. The NIST FAQ\nputs it this way: a group is usually a collection of users, and most group\nmechanisms also let a permission be attached straight to a user, which the FAQ\ncalls a “loophole” that makes the user-permission relation hard to control. RBAC\ncloses it by attaching permissions only to roles. The reason is in another line\nof the same FAQ: roles in an organisation stay fairly stable, whereas users and\npermissions are numerous and change quickly, so routing all access through roles\nmakes it simpler to manage and to review.\n\nDatabases often implement the model directly. PostgreSQL has had one kind of\nentity since version 8.1, the role, which can act as a user, a group or both. A\nrole meant as a group usually has no LOGIN, and membership in it is granted like\nany other privilege. Two membership options control how a member uses the group's\nprivileges: INHERIT gives the member the group's privileges automatically, and\nSET lets the member switch into the role with SET ROLE, which comes close to\nthe RBAC idea of activating a role only in the session that needs it.\n\n```sql\n-- the role carries the permissions; nobody logs in as it\nCREATE ROLE reporting NOLOGIN;\nGRANT USAGE ON SCHEMA sales TO reporting;\nGRANT SELECT ON ALL TABLES IN SCHEMA sales TO reporting;\n\n-- a person receives the role, never the table\nCREATE ROLE alex LOGIN;\nGRANT reporting TO alex;\n\n-- a powerful role that has to be switched on deliberately\nCREATE ROLE schema_admin NOLOGIN;\nGRANT schema_admin TO alex WITH INHERIT FALSE;\n-- later, in the one session that needs it: SET ROLE schema_admin;\n```\n\n## Why it matters\n\nAccess control has to answer two questions that pull in different directions: is\nthis request allowed right now, and who can do what across the whole system.\nMost schemes answer the first well. RBAC is built for the second, because its\nanswer is a short list of roles and the people in each, which an auditor or a\nmanager can actually read. NIST's one-line verdict on the alternative,\nattribute-based access control, where each decision evaluates rules over\nattributes of the user, the resource and the context, is that it “can be easy to\nset up but complex to manage”.\n\nThe practical decision is where roles stop being enough. The 1992 model grants\naccess “only if” the role requirements are met, a wording chosen to leave room\nfor further checks at access time. A doctor role lets someone read medical\ncharts, but not every patient's chart: the relationship between this doctor and\nthat patient is a fact about the data, not a job title. That is where a second\nmechanism belongs, such as row-level security in the database or an attribute\nrule in the application, layered on top of the roles rather than replacing them.\n\nOur recommendation is to model access as roles first, named after jobs people\nactually do, with permissions attached only to roles and never directly to a\nlogin. Keep the role list short enough that one person can read all of it. Add\nrow-level or attribute rules only where a role demonstrably cannot draw the\nboundary, and let the database enforce whatever it can, because a check made by\nthe database applies to every client, including the code path someone forgot.\n\n## What it looks like in practice\n\nIn a database engineering job from 2022 to 2024, access to every developer\nenvironment, application instance, PostgreSQL and MS SQL database and Linux\nserver came under\n[1,000 RBAC rules](/portfolio/wrote-1000-rbac-rules-to-secure-linux-servers/).\nThe model was the simple part; the volume was the challenge.\nPermissions were broken into reusable categories such as “read-only access to\nproduction databases” and mapped to roles such as developers, application\ninstances and database administrators. Developers reached only their designated\nservers, and application instances had limited permissions to prevent lateral\nmovement. Ansible applied the rules consistently across environments, and the\nrules were documented so teams could audit or change them. The delivered\nresult was the role-based rule set and a repeatable way to apply and review it.\n\nRoles rarely work alone. When a\n[map application moved from MSSQL to PostgreSQL with PostGIS](/portfolio/improved-gis-map-performance-10x-on-postgresql/),\nrole-based access controls went in together with row-level security to enforce\ndata-protection policies across several user groups. That pairing is the usual\ndivision of labour: roles decide which tables a group may touch, and row\npolicies decide which rows inside them.\n\nThe strictest version takes the tables out of reach entirely. In a\n[function-first PostgreSQL data layer](/portfolio/designed-a-function-first-postgresql-data-layer/)\nfrom 2025, every operation the application performs is one of 1,275 functions\nacross 34 schemas. The role the API logs in as, mariner, holds EXECUTE on the\napplication functions and USAGE on the schemas and nothing else, which comes to\nroughly 4,000 explicit grants instead of one blanket grant. The functions run as\nSECURITY DEFINER, owned by a separate non-login role with a pinned search_path,\nand the superuser account is kept for migrations and cron. A compromised API\nwould still be limited to what the functions allow. The price is written down as\nwell: a new field means a migration and a function change.\n\n## Where it goes wrong\n\n- **Roles multiply until nobody can read them.** Every exception becomes a new\n  role, such as “developer except billing” or “developer plus one report”, and\n  soon there are more roles than people. Role explosion defeats the reason for\n  RBAC, which was a list short enough to review. Give a person two or three\n  roles rather than minting one per exception, and merge roles whose permission\n  sets have become identical.\n- **A permission lands on a login directly.** One urgent ticket, one GRANT\n  straight to a user, and that user now has access that no role review will\n  show. It is the loophole NIST describes in group systems, rebuilt by hand.\n  Grant to roles only, and have the review query look for privileges held by\n  roles that can log in.\n- **Defaults hand out access before any role does.** In PostgreSQL the name\n  PUBLIC means every role, and by default it receives EXECUTE on new functions\n  and CONNECT and TEMPORARY on databases. Where a database was upgraded from\n  PostgreSQL 14 or an older release, it can also create objects in the schema\n  called public. Revoke those defaults deliberately, ideally inside the\n  transaction that creates the object.\n- **Roles only ever grow.** People change jobs and keep the old role beside the\n  new one, and temporary access becomes permanent because removing it is\n  nobody's task. Each assignment needs a reason and a review date, and leaving a\n  job should take away the roles that came with it.\n- **Some accounts skip the rules.** Superusers and roles with BYPASSRLS ignore\n  row-level security, and a table's owner normally does too unless the table is\n  set to FORCE ROW LEVEL SECURITY. An application that connects as the owner or\n  as a superuser turns every row policy into decoration, so connect it as a role\n  that owns nothing.\n\n## Further reading\n\n- [NIST Role Based Access Control project](https://csrc.nist.gov/projects/role-based-access-control)\n  — the archived project home: the model's history, the 2004 standard and its\n  2012 revision.\n- [NIST RBAC FAQ](https://csrc.nist.gov/projects/role-based-access-control/faqs)\n  — roles versus groups, RBAC0 to RBAC3, separation of duty and the four\n  components of the standard.\n- [PostgreSQL: Role Membership](https://www.postgresql.org/docs/current/role-membership.html)\n  — group roles, granting and revoking membership, and the INHERIT and SET\n  options.\n- [PostgreSQL: Row Security Policies](https://www.postgresql.org/docs/current/ddl-rowsecurity.html)\n  — default deny, which roles bypass row policies, and FORCE ROW LEVEL SECURITY.\n- [PostgreSQL: Privileges](https://www.postgresql.org/docs/current/ddl-priv.html)\n  — what PUBLIC receives by default and how to revoke it.\n- [SQL Server: Database-level roles](https://learn.microsoft.com/en-us/sql/relational-databases/security/authentication-access/database-level-roles)\n  — fixed and user-defined roles inside a SQL Server database.\n\n\u003chttps://engineer.company/glossary/rbac/\u003e\n","date_modified":"2026-11-09T21:50:25Z","description":"How role-based access control works, from the NIST model and its standard to PostgreSQL group roles, and how a tidy role scheme decays over time.","formats":{"gemtext":"https://engineer.company/glossary/rbac/index.gmi","gopher":"https://engineer.company/glossary/rbac/gophermap","html":"https://engineer.company/glossary/rbac/","json":"https://engineer.company/glossary/rbac/index.json","markdown":"https://engineer.company/glossary/rbac/index.md","pdf":"https://engineer.company/glossary/rbac/index.pdf"},"kind":"page","language":"en","title":"What is RBAC?","url":"https://engineer.company/glossary/rbac/","version":1}