How to model multi-tenancy where the same user (logged in user that is) can have multiple tenant-users, each with a different set of permissions? #446
-
Hi folks, I'm working with a multi-tenant app, where there are these entities:
Where:
What I want to achieve:
The best I could come up with is to used conditions and contextual tupples:
Example of tuple stored in DB:
The check:
I've super curious would you approach this? |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 3 replies
-
I don't think I fully understand the scenario, but it seems you should be able to model it without conditions, using contextual tuples, in a way similar to this https://openfga.dev/docs/modeling/organization-context-authorization You can send a contextual tuple restricting access of that tenant-user to a single tenant tenant, for example. Let me know if that works. |
Beta Was this translation helpful? Give feedback.
-
Thanks for the response @aaguiarz. I know the scenario is a bit convoluted 😓. Let me try to explain it in a DB relations form, may be this will make it easier to understand. This is is how the tenant-user table looks like:
The principal ID is basically the The highlight here is that 2 of these users belong to the same tenant ( Because of that, I guess I cannot model my authZ in terms of the relation between the I hope it makes more sense. |
Beta Was this translation helpful? Give feedback.
-
When you are making an API call, are you authorizing that the "tenant user id" (tenant1-user2) can perform a specific action on a tenant? e.g. check(user: user:tenant1-user2, relation: can_write, object: tenant-1)? |
Beta Was this translation helpful? Give feedback.
It seems that the permissions are defined at the user level, not principal level, right?
Do you want to confirm that the principal and the tenant-user that are in the JWT are actually linked somehow in OpenFGA?
Would this work?