You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I am building a hierarchical multi-tenant project and need to apply RLS (Row-Level Security) to my queries. I have tried doing this using a global filter and, in a more desperate attempt, even composing the generated query via an interceptor. However, I am not very confident about the best path to follow. To better illustrate, my hierarchical multi-tenant structure has the following entities:
My filter would need to apply an INNER JOIN with User and UserGrants and ensure that no user from one department or team within the same tenant can access information about a user from another department or team, for example.
Another thing I would like to know is if there is a way to avoid having User and UserGrants replicated and mapped across every bounded context of the application. Ideally, these would be mapped in a single place where I could apply the filter under the appropriate conditions.
EF Core version: 8.0.11
Database provider: Microsoft.EntityFrameworkCore.SqlServer
Target framework: .NET 8.0
Operating system:
IDE: Visual Studio 2022 17.4
The text was updated successfully, but these errors were encountered:
grcontin
changed the title
Support for Hierarchical Multi-Tenant Row-Level Security
How to Apply a Hierarchical Multi-Tenant Filter with Row-Level Security
Dec 23, 2024
I couldn't apply this filter configuration because it involves some JOINS that I need to perform. Additionally, I need to apply some AND conditions in the ON clauses of these JOINS, and, in the end, a WHERE clause that also checks the user's ID. This filter needs to be applied whenever the user is authenticated. It's a very complex filter, not a simple one.
Here is an example of the filter I need to apply:
INNER JOIN Users ON Tenants.Id = Users.TenantId
INNER JOIN UserGrants ON Users.Id = UserGrants.UserId
AND UserGrants.UnitId = Units.Id
AND UserGrants.DepartmentId = Departments.Id
AND UserGrants.TeamId = Teams.Id
WHERE Users.Id = @Id
This filter sometimes changes depending on which table I am trying to read specific information from, so it ends up being very complex. That’s why I’m a bit lost on how to proceed.
I am building a hierarchical multi-tenant project and need to apply RLS (Row-Level Security) to my queries. I have tried doing this using a global filter and, in a more desperate attempt, even composing the generated query via an interceptor. However, I am not very confident about the best path to follow. To better illustrate, my hierarchical multi-tenant structure has the following entities:
My filter would need to apply an INNER JOIN with User and UserGrants and ensure that no user from one department or team within the same tenant can access information about a user from another department or team, for example.
Another thing I would like to know is if there is a way to avoid having User and UserGrants replicated and mapped across every bounded context of the application. Ideally, these would be mapped in a single place where I could apply the filter under the appropriate conditions.
EF Core version: 8.0.11
Database provider: Microsoft.EntityFrameworkCore.SqlServer
Target framework: .NET 8.0
Operating system:
IDE: Visual Studio 2022 17.4
The text was updated successfully, but these errors were encountered: