Roles and Permissions #22
reindert-vetter
started this conversation in
Docs
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Why Should You Care?
Roles and permissions aren’t just for security nerds. If you want to know who can do what, and why your website sometimes says "nope," you’re in the right place. They’re your best friends when you want the user to:
The basics (RBAC)
You assign permissions to roles, and then hand out those roles to your users.
Required Permissions vs. Granted Permissions
Suppose you want only certain users to be able to edit blog posts. You can check for a required permission like
blogs. If the user has this permission, they can edit all blogs. If not, access is denied. This makes it easy to control who can do what, just by checking for the right permission string.You can check permissions in your Blade views like this:
Path
You can use paths to control access to specific fields or sub-resources. For example,
blog/titlerefers to the title field of a blog. This allows you to grant fine-grained permissions for different fields and resources.If a user is granted
blog, they can access all fields of a blog. If a user is grantedblog/title, they can only access or edit the title field.Example:
blogcan create and edit the entire blog, including all fields.blog/titlecan only edit the title of the blog.Actions: To Read or Not to Read
Permissions can be extended to specify what actions a user can perform on a resource. The path determines which part of the system the user can manage, and the action on a permission lets you control what actions are allowed.
blogs— allows both reading and writingblogs.read— allows only readingblogs.write— allows only writingThis applies to both requested and granted permissions. For example, you can request
blogs.writeand only get access if your granted permissions includeblogsorblogs.write.This way, both
blogs.writeandblogsGranted Permission allow editing the blog.You can also define other activities besides 'write', such as 'blog.delete', to control custom actions on your resources.
For example:
blog.delete— allows deleting a blogQuery (ABAC)
With a query, you can make your permissions even more fine-grained by specifying parameters for a resource. This allows you to control access to specific subsets of data.
For example:
blogs?author_id=123— only allows access to blogs by author 123blogs?album=photos_2025— only allows access to blogs in the album 'photos_2025'You can check for a specific query in Blade like this:
Or for a specific album:
Roles
Here’s an example of how you can assign permissions to roles in a
roles.json5file:You can add as many roles and permissions as you need for your project. You can also assign multiple roles to a single user.
Relative permission
In Confetti, you have one account for all your websites. That’s why permissions are always stored as a full path, starting with a
/(slash) followed by the repository name (e.g.,/ninja-agency/silent-site/blogs). This makes it possible to manage access across multiple projects and organizations with a single user account.An owner of an agency can have a permission like
/ninja-agency(instead of/ninja-agency/silent-site/). In that case, the owner is allowed to do everything within all repositories of the agency. Packages can still have their own restrictions (these are prefixed with their own repository, like/the-pkg-maker/image-uploader). See the package section for more information.Advanced
Parsing
In some situations, you may want to parse a user's permission. For example, you can use this to show a list of all blogs the user has access to. You can parse a permission just like you would parse a URL. For example, in PHP:
If you are building your own package in Go, you can use the standard library:
Iterate over permissions
Sometimes you want to loop through all the permissions a user has access to. For example, to show a list of all blogs the user can edit:
Beta Was this translation helpful? Give feedback.
All reactions