Modeling Google Drive Permissions with ReBAC
This tutorial explains how to build a simplified Google Drive-like permission system using Permit.io.
Before you begin
Setup your client
You can install the latest version of the SDKs to use ReBAC functions, or call the APIs directly using cURL or any other HTTP client.
- Python
- Node.js
- Java
- cURL
To install the latest python SDK:
pip install permit
All other instructions from the Python quickstart remain the same.
To install the latest Node.js SDK:
npm install permitio
All other instructions from the Node.js quickstart remain the same.
To install the latest Java SDK you'll need version 2.0.0
.
For Maven projects, use:
<dependency>
<groupId>io.permit</groupId>
<artifactId>permit-sdk-java</artifactId>
<version>2.0.0</version>
</dependency>
For Gradle projects, configure permit-sdk-java
as a dependency in your build.gradle
file:
dependencies {
// ...
implementation 'io.permit:permit-sdk-java:2.0.0'
}
All other instructions from the Java quickstart remain the same.
For calling the API directly using cURL or Postman, you'll need to setup a few environment variables.
export permit_project="<your-project-key>" # for example: the `default` project
export permit_env="<your-environment-key>" # for example: the `dev` environment
export permit_sdk_api_key="<your-api-key>" # for example: `permit_key_...`
The API key you should use for your API calls must be an environment-level API key.
What you will be building
Google drive is a system you can use to store, share, and collaborate on files and folders.
The G-Drive permission model is documented here. For simplicity we will implement a subset of it with Permit.
Requirements
- Object Hierarchy: A google drive account can contain many folders and files. Folders can contain other files and folders.
- Direct file access: A user can be a viewer of file, a commenter (meaning they can view and comment on the contents) or an editor (can view, comment and edit).
- Folder-level access: A user can be granted access to a folder. A user access level on a certain folder will grant that same access level on all the files within the folder.
- Account admin access: A user can be granted admin access to the entire account, which will grant the highest permission level on all folders and files within the account.
- General access to "Everyone in account": Files can be shared with all the users who are associated with the account that contains the file (share with all account members).
Test objects
To verify our system work, we will define a few objects (resource instances) and a few users.
The instances we will define:
- a `2023_report` file
- a `finance` folder
- an `acme` account
The hierarchy we will define is:
- the `2023_report` file is located within the `finance` folder
- both `file:2023_report` and `folder:finance` belong to the `acme` account.
The users we will define are
- John who has `viewer` access to file:2023_report // direct file access
- Jane who has `editor` access to folder:finance // folder level access
Modeling the Resource Graph
Define resources and roles
Resources
Resources in Permit are types of objects that you can enforce permissions on. Each resource has a predefined set of actions that a user can perform on it.
Permit ReBAC allows you to model your resources as a graph. Each resource (a type) is a node in the graph, and can connect to other resources via edges called relations.
The resources we will define for this example are:
- Account
- Folder
- File
Resource Roles
Each resource type can define its own roles. A resource role represents an access level (or a set of permissions) that can be granted on instances of a specific resource type.
Resource roles are typically denoted as Folder#editor
, which means "a resource role with key editor
that is defined on the resource type with key Folder
".
The resource roles we will define are:
- Account#admin
- Account#member
- Folder#editor
- Folder#commenter
- Folder#viewer
- File#editor
- File#commenter
- File#viewer