Configure your first RBAC Policy
Role-Based Access Control (RBAC) grants access to resources through roles: you give permissions to a role, and assign roles to users. Each user gets only the access their role needs. For more on RBAC, read the blog post or the Permit RBAC page.
For example, in a web application, an "Admin" role might have full access to manage resources, while a "Viewer" role can only view them.
In this guide, you configure your first RBAC policy step by step: create a role, define a resource and its actions, grant permissions, and assign the role to a user.
Creating your first role
Start by defining roles. A role is a set of permissions to perform actions on resources, and it determines what a user can or cannot do in your system.
In this example, you create a role called Admin, which usually represents the highest level of access.
Make sure the name is clear and meaningful, reflecting the purpose of the role. You can also pass a
keyto uniquely identify a role and adescriptionto offer a more meaningful explanation of the role.
To create the Admin role:
- Navigate to the Policy Screen
- Click
Create a Role - Enter "Admin" as the name of the role.
Creating a resource and its actions
- Navigate to the
PolicyScreen. - Click
Create a Resource. - Enter
Documentas the name of the resource. Use a name that clearly represents the object in your system that needs controlled access, such as a file, database entry, or, in this case, a document. - Add the actions associated with this resource. Start with Permit's predefined actions:
create,read,update, anddelete(CRUD). They cover the basic operations most systems need. - Optionally, add custom actions to reflect specific operations relevant to your use case. For example, add a custom action called
publish, representing an operation specific to document management.
Combine predefined and custom actions to model the operations your application actually has.
Configuring RBAC permissions in the Policy editor
With the role and resource in place, define the permissions for the Admin role. In the Policy Editor, you choose which actions each role can perform on each resource.
- Navigate to the
Policy EditorScreen. - Find the
Adminrole, and theDocumentresource underneath the role. - Tick the actions the Admin role can perform on the Document resource:
createreadpublish(the custom action defined earlier).
Each ticked box maps an action on a resource to a role. Change the boxes and the policy changes, without touching your code.
Add a user and assign a role
Finally, add a user and grant them access through the role.
Users represent the people or services that interact with your application, and roles determine what they can do.
- Navigate to the
Directorypage. - Click
Add User. - Enter
sam@permit.ioas the user's email address. Use the email of the person who should receive access. - Assign the
Adminrole to this user by selecting it from the list of available roles. The user can now perform every action you granted to that role.
Your RBAC setup is ready: the Admin role has the permissions you granted on the Document resource, and sam@permit.io has the Admin role.
What did you learn?
You configured your first RBAC policy: you created a role, defined a resource with actions, set permissions, and assigned the role to a user. Every other policy model in Permit builds on these same pieces.
What's next? 🎉
- Fetching your API key
- Initializing the Permit Instance
- Performing your first API call
Congratulations! A great start!