-
Hi Everyone, I have a multi-tenant app where we first create the account and then add users to it. We also create the groups and roles under the account. The same user can be present in multiple accounts, but groups and roles are owned by a specific account and can not be shared across accounts. Currently we are having authorization mechanism where users can create their custom roles by selecting the fine-grained permissions. Here role is a collection or container of the related permissions. If I take the example of a resource fund, then fund.create, fund.read, fund.update, fund.delete are the permissions, and users can create custom roles by selecting those permissions. The user can only assign those roles to the group and not to the users. When user logs in and try to create the fund, we check if the user is present in the group which has the role that contains fund.create permission, and if so, then only allow to create the fund. If user creates a custom role called Fund Manager and select all the above permissions and assign that role to say Group Fund Manager within that account then all the users present in that group for that account would be able to create the funds, update all the funds present in the account, read all the funds and delete all the funds present in the account. But along with this we also have a scenario where lets say we have a resource called questionnaires, and questionnaires are having a sections. Now, here we want to make sure only Group-1 can have section.read and section.write permission on section-1 and group-2 has access of section-2. Right now, we store section_id, group_id and role_id mapping to the database for this and then checking the access resource specific checks. We also have a concept of modules where we assign the modules to the accounts and when we add users to the account we select which module access the user should have and when the user tries to access the module first we check if the user really have access of that module and if so then we perform other regular authorization checks. Now, we want to use OpenFGA to remove the manual checks we are doing, and I designed the model as below. I have 2 questions
Your help will be greatly appreciated. Many Thanks |
Beta Was this translation helpful? Give feedback.
Replies: 7 comments 16 replies
-
Hi @prsanjay The model looks good! Regarding |
Beta Was this translation helpful? Give feedback.
-
Would something like this work?
|
Beta Was this translation helpful? Give feedback.
-
In general, you would try to model all permission in the model and avoid doing two checks. Sometimes is not possible, but in this case it is. Evaluating the permission will be more expensive, but still pretty fast. About the model in relations like the one below,
You can just write it as:
The same everywhere you have |
Beta Was this translation helpful? Give feedback.
-
re:
|
Beta Was this translation helpful? Give feedback.
-
Hi @aaguiarz, Thank you so much for your help so far. A quick question, according to the model, I need to create all the granular resources in the OpenFGA to check if they belong to the correct account and have correct module access in a single API call. If I do this, then the number of tuples will increase significantly in a very short time. For example, I need to create all the sections, funds, and many other tuples in the OpenFGA store by setting up the relation between
Do you think this approach could lead to a bottleneck quickly? I want to ensure the authorization check API call completes within a few milliseconds. |
Beta Was this translation helpful? Give feedback.
-
Hi @prsanjay Yes, that is the way that OpenFGA and Relationship Based Access Control works. You can have billions of tuples on an FGA database. If you don't want to synchronize the data, you can use OpenFGA's Contextual Tuples https://openfga.dev/docs/modeling/token-claims-contextual-tuples and send some of those tuples in each request to FGA. |
Beta Was this translation helpful? Give feedback.
-
This answers all my questions. Thanks a lot. |
Beta Was this translation helpful? Give feedback.
Hi @prsanjay
Yes, that is the way that OpenFGA and Relationship Based Access Control works. You can have billions of tuples on an FGA database.
You need to provide the data first so the authorization checks are very fast.
If you don't want to synchronize the data, you can use OpenFGA's Contextual Tuples https://openfga.dev/docs/modeling/token-claims-contextual-tuples and send some of those tuples in each request to FGA.