用于实现RBAC的适当firebase安全规则
我正在使用firebase构建一个多租户应用程序。在构建应用程序时,我正在构建一个RBAC模型,该模型允许用户脱离多个组织,并在每个组织中分配多个角色。每个角色都分配了用户可以访问的资源 给定如下firebase结构,如何创建适当的firebase安全规则来确定用户是否有权访问给定组织中的资源?用于实现RBAC的适当firebase安全规则,firebase,firebase-security,firebase-authentication,firebase-hosting,Firebase,Firebase Security,Firebase Authentication,Firebase Hosting,我正在使用firebase构建一个多租户应用程序。在构建应用程序时,我正在构建一个RBAC模型,该模型允许用户脱离多个组织,并在每个组织中分配多个角色。每个角色都分配了用户可以访问的资源 给定如下firebase结构,如何创建适当的firebase安全规则来确定用户是否有权访问给定组织中的资源? organizations org1UUID about staff uid1 roles ViewerRoleUUID
organizations
org1UUID
about
staff
uid1
roles
ViewerRoleUUID
about
type: "view"
resources
DashboardUUID: "true"
SomeSettingsUUID: "true"
MoreResourcesUUID: "true"
SysAdminUUID
about..
type: "full"
resources:
AdminAreaUUID: "true"
DashboardUUID: "true"
SomeSettingsUUID: "true"
type: "admin"
org2UUID...<repeat of above>
users
uid1
authinfo
organizations
org1UUID
roles
ViewRoleUUID: "true"
SysAdminUUID: "true"
org2UUID
roles
AnotherRoleUUID: "true"
上面的示例仅在为用户分配了一个角色时有效。但是,如果根据用户需要访问的资源,用户需要分开两个或多个角色,则此操作将不起作用
最初,我考虑将角色信息(包括其类型和资源列表)复制到每个用户。问题是,即使数据结构被移动或复制到用户,搜索查看用户是否有权访问资源仍然可以解决在尝试搜索给定公司的所有用户角色以确定用户是否有权访问时的问题 在安全规则文档中,它解释了hasChildren,但似乎只适用于您知道的root.child('groupID')这样的子节点。在安全规则文档中,它解释了hasChildren,但似乎只适用于您知道的root.children('groupID')。hasChildren('one')这样的子节点
".read": "(root.child('users/' + auth.uid + '/organizations/' + $organization).child('role').val() === "viewer"),
".write": "(root.child('users/' + auth.uid + '/organizations/' + $organization).child('role').val() === "admin")"