Configure your first RBAC Policy
Build your first role-based access control (RBAC) policy in the Permit.io dashboard, without code. This walkthrough is for new Permit users. You create an Admin role and a Document resource, give the Admin role permissions on documents, and assign the role to a user.
In RBAC, you give permissions to roles, and you assign roles to users. A user can perform an action on a resource when one of the user's roles has that permission. For example, an Admin role can create and delete documents, while a Viewer role can only read them. For more background, see What is RBAC.
Prerequisites
- A Permit.io account with a project and environment. Sign up at app.permit.io.
1. Create a role
A role is a named set of permissions. It defines what a user with that role can do in your application.
- In the Permit dashboard, open Policy and select the Roles tab.
- Click Create a Role (or Add Role when roles already exist).
- In Name, enter
Admin. Permit fills in the Key from the name. Your code uses the key to refer to the role. - Optionally, enter a Description that explains what the role is for.
- Click Save.
The Admin role appears in the Roles list.
2. Create a resource and its actions
A resource is a type of object in your application that needs access control, such as a file, a database record, or, here, a document. Actions are the operations users perform on a resource.
- In Policy, select the Resources tab.
- Click Create a Resource (or Add Resource when resources already exist).
- In Name, enter
Document. Permit fills in the Key. - In Actions, keep the default actions:
create,read,update, anddelete. - Add a custom action for an operation specific to your application: type
publishand press Enter. - Click Save.
The Document resource appears in the Resources list.
3. Grant the Admin role permissions in the Policy Editor
The Policy Editor is a grid of roles, resources, and actions. Each checked box allows one role to perform one action on one resource.
- In Policy, select the Policy Editor tab.
- Find the Admin role, and the Document resource under the role.
- Check the actions the Admin role can perform on documents. The video checks
create,delete, andpublish. - Click Save Changes.
When you change the checked boxes and save, the policy changes. Your application code doesn't change.
4. Add a user and assign the role
Users are the people or services that use your application. A user gets permissions through the roles you assign.
- Open Directory.
- Click Add user.
- In Key, enter a unique ID for the user, for example
unique_id_12345. Your code passes this key topermit.check(). - In Email, enter
sam@permit.io. Optionally, enter a first and last name. - In Assigned Roles (labeled Top Level Access in some dashboard versions), select Admin.
- Click Save.
Verify the policy
- Open Directory. The user
sam@permit.ioappears with the Admin role. - Open Policy > Policy Editor. Under Admin > Document, the actions you checked are still checked after you reload the page.
The user sam@permit.io can perform the checked actions on documents. To confirm this with a permission check from code, continue to Run your first policy check.
What you built
You configured an RBAC policy from its four parts: a role, a resource with actions, permissions that connect them, and a user with a role. The attribute-based and relationship-based policy models in Permit build on the same roles, resources, and actions.
Next: connect your application with an API key and the SDK.