RBAC Access Control System Implementation with FusionAuth
-
Hello,
We am trying to implement an RBAC (Role-Based Access Control) system using FusionAuth. I have described our requirements and concerns below, and I would greatly appreciate your help on how to best address these needs.
Our current setup involves
Users
who can have access to multipleCompanies
through the use ofCompanyUsers
. Additionally,Companies
can have multipleWorkspaces
, andUsers
may have access to multipleWorkspaces
within the sameCompany
or across multipleCompanies
.Based on my understanding, it seems that we cannot utilize the
Tenant
model for our RBAC implementation. Could you kindly confirm whether this is the case? And if my understanding is incorrect, could you please advise on how to achieve the expected data modelling usingTenants
?Given this context, it looks like our only viable option is to use
Entities
. We plan to have multipleEntityTypes
, such asCompany
,Workspace
andServiceAccount
. TheseEntityTypes
will have associatedPermissions
, represented as strings (e.g., "users.index," "users.create," etc.). We intend to provide entityPermissions
toUsers
through entityGrants
.However, there are a few issues we have identified with this approach. Firstly, FusionAuth does not currently offer entity
Roles
, making it challenging to efficiently assignPermissions
in bulk. It seems we would need to maintain separateRole
andPermission
models on our end for this purpose. The same issue applies to deletingPermissions
. Furthermore, if aUser
has multipleRoles
within aCompany
, such as "CompanyAdmin" and "CompanyManager," both of which have the "users.create"Permission
, removing the "CompanyAdmin"Role
would result in theUser
losing the "users.create" privilege, even if they still retain the "CompanyManager"Role
.Considering these challenges, we would greatly appreciate your guidance on how best to model FusionAuth to meet our needs. We would be particularly interested in any recommendations or best practices you can provide regarding
Entity
management,Permissions
, andRole
assignments.Additionally, we anticipate that a
User
may have access to a potentially large number ofCompanies
within our application, potentially reaching hundreds of thousands. We are concerned about the practicality of including all thesePermissions
in the JWT (JSON Web Token). Could you please advise us on an effective approach for managing and including thesePermissions
in the JWT? What would be the alternatives or what are the best practices on this topic?Thank you very much for your time and we're looking forward to your suggestions.
Kind regards,
Andrei -
@apetrescu Sounds like a fun problem!
You are correct that entities are the best approach for this while staying entirely within FusionAuth. We don't have a lot of guidance on best practices around entities that I can share, unfortunately.
Considering these challenges, we would greatly appreciate your guidance on how best to model FusionAuth to meet our needs. We would be particularly interested in any recommendations or best practices you can provide regarding Entity management, Permissions, and Role assignments.
You might think about making an intermediate entity such as CompanyAbcAdminRole or CompanyAbcManagerRole, which would have permissions for admin or manager actions on CompanyAbc. Then you could atomically grant or remove CompanyAbcAdminRole to a user while leaving CompanyAbcManagerRole assigned.
Additionally, we anticipate that a User may have access to a potentially large number of Companies within our application, potentially reaching hundreds of thousands. We are concerned about the practicality of including all these Permissions in the JWT (JSON Web Token). Could you please advise us on an effective approach for managing and including these Permissions in the JWT? What would be the alternatives or what are the best practices on this topic?
Why would you need to do so? Is your user going to be accessing all the Companies at one time? In this case, I might offer the user the ability to choose a Company to 'enter' and create a JWT based on that action. You'd create an Company 'chooser' based on their grants to allow them to pick between the companies they know about.
If you'd like to discuss this more, consider talking to our sales engineers.
Another option is to, as you said, not use FusionAuth entities. You could instead use FusionAuth for authentication, then feed the resulting JWT into a solution like permit.io, cerbos or oso (or something home grown). You'd use that other system as the authorization solution.
Hope this helps.