Defining a Schema
The ReBAC schema is comprised of three main components: namespaces, relation definitions, and relations. Namespaces are top-level entities in your application, like documents, folders, and organizations. Relation definitions defines the relationship between namespaces, like a user being a member of an organization. Relations are the actual relationships between entities, like a specific user being a member of a particular organization.
The general flow of defining a schema involves creating namespaces and relation definitions.
An example schema
Download an example schema here.
Breaking down the schema
Getting into the details of how a schema is constructed, we'll start from a top down approach. The first data type we have is the schema.
Schema
The FGASchema
holds the full schema/dsl (Domain-Specific Language) for a project.
Types
Within the FGASchema
, we have the dsl
field, which starts out with a name and top-level types.
Relations & Permissions
Within each Type
, you define Relations
and Permissions
. These are abstract representations that establish how entities within your model relate to each other and dictate access control logic.
Relations
: Define direct relationships between entities or references to relationships of other entities. They act as building blocks for more complex permission definitions.Permissions
: Use relations and other permissions to create logical rules for access control, combining simple relationships into sophisticated permission structures.
Full Example
Model AuthZ 1.0
The AuthZ 1.0 model demonstrates a structured and flexible approach to defining access control for a system that includes user
, group
, folder
, and doc
entities.
By leveraging a combination of relations and permissions, this model establishes a clear and maintainable structure for enforcing authorization policies.
Entity Definitions
-
Type
user
:- Represents an individual user within the system. This entity forms the foundation for other relations and permissions.
-
Type
group
:- Represents a collection of users, supporting roles and hierarchies within the group:
- Relation
member
: Links users to the group as general members. - Relation
super_admin
: Identifies privileged users within the group who have elevated permissions.
- Relation
- Represents a collection of users, supporting roles and hierarchies within the group:
-
Type
folder
:- A hierarchical structure that supports ownership and access control:
- Relation
parent
: Establishes a recursive relationship where folders can nest within other folders. - Relations for access control:
owner
: Individuals or group members who have ownership of the folder.editor
: Individuals or group members with edit permissions.viewer
: Individuals or group members with view permissions.
- Permissions:
can_create
: Granted toowner
, inherited fromparent.owner
, or derived fromparent.can_create
.can_edit
: Combines the roles ofeditor
or inherited fromparent.editor
and includescan_create
.can_view
: Extends fromviewer
orparent.viewer
and includescan_edit
.
- Relation
- A hierarchical structure that supports ownership and access control:
-
Type
doc
:- Represents a document, inheriting its structure and access control rules from
folder
:- Relation
parent
: Links the document to a parent folder. - Relations for access control:
owner
: Individuals or group members who have ownership of the document.editor
: Individuals or group members with edit permissions.viewer
: Individuals or group members with view permissions.
- Permissions:
can_create
: Granted toowner
or inherited fromparent.owner
.can_edit
: Combines the roles ofeditor
or inherits fromparent.editor
and requirescan_create
.can_view
: Includesviewer
orparent.viewer
, but excludes those withcan_edit
.
- Relation
- Represents a document, inheriting its structure and access control rules from
Next
We'll move on to implementing a schema.