Relationship-based access (ReBAC)
Also called: ReBAC, relationship-based access control.
Access is worked out from stored relationships, such as "Ana is a member of deal-team", "deal-team edits the folder fund-a" and "fund-a holds memo.pdf". To answer "may Ana view memo.pdf?", a permission service follows those links from the file until it reaches Ana, or answers no. Sharing or removing access means writing or deleting one relationship, with no change to the file or to the app's code.
The main button asks the permission service whether Ana can view memo.pdf; it follows the tuples from the file to Ana. Remove Ana from the team and Share the file with Ben each change one tuple and check again (press either again to undo it).
Tuples: 3 · Checks: 0 · Hops: 0
Three tuples link Ana to memo.pdf: she is in deal-team, the team edits fund-a, and fund-a holds the file.
Say it in a prompt
Add relationship-based access with OpenFGA. Model the types user, team, folder and file: a team has members; a folder has editors (users or team#member) and viewers, and every editor is also a viewer; a file has a parent folder and viewers, and the viewers of its parent may view it too. Write a tuple when someone joins a team, a folder is shared or a file is created. Before showing or downloading a file, call Check(user, viewer, file) and deny when it says no or the call fails; a route that never calls Check is open, so add a test that every file route does. To list a folder, call ListObjects(user, viewer, file) instead of one Check per file. Test that Ana is allowed through deal-team, and denied once she leaves it. Vague vs precise prompt
Vague prompt
let people share folders and files with their team Typical resultAdds a shared_with list on each file and checks it in the download route. Sharing a folder doesn't reach the files in it, leaving a team changes nothing, and each screen checks access in its own slightly different way.
Precise prompt
Use relationship-based access with OpenFGA: tuples for team members, folder editors and each file's parent folder, and a model where a folder's editors may view its files. Every file route calls Check(user, viewer, file) first. Leaving a team deletes one tuple. Typical resultJoining or leaving a team, or sharing one file, is a single tuple write, and every screen asks the same service, so access is the same everywhere. It only guards the routes that ask: a route that skips Check is still open, and folder listings need ListObjects. A test shows Ana allowed through her team, then denied once she leaves it.
Seen on
- Google Research: Zanzibar, Google's authorization system, keeps access rules as relationships in one data model and config language, and answers millions of checks a second over trillions of access control lists.
- OpenFGA docs: A relationship tuple is a user, a relation and an object, like user:anne editor document:new-roadmap. A check asks whether a user has a relation with an object and answers allowed true or false.
- OpenFGA docs: An editor of a folder can be made an editor of every document whose parent is that folder, with no tuple for each document.
- OpenFGA docs: A relation can be given to a whole team with team:writers#member, so everyone in the team has it.
- OpenFGA docs: ListObjects returns every object of one type that a user has a given relation with, for screens like all the documents a user can read.
- SpiceDB docs: A permission check asks whether a chain of relationships leads from the resource to the user, so access questions become questions of reaching one point in a graph from another.
You might describe it as
- share one file with one person without opening the whole folder
- access that follows teams, folders and files
- ask one service "may this user do this?" before every action
Not to be confused with
- Row-level security (RLS)
Row-level security filters the rows of a table inside one database, by a rule on each row; ReBAC answers "may this user do this to this object?" from stored relationships, for any service and any kind of object.
- Audit log
ReBAC decides whether an action is allowed before it happens; an audit log records who did what after it happened.