【发布时间】:2019-02-27 19:05:49
【问题描述】:
我正在尝试为具有以下根集合的新 Firestore 项目设置规则集:
用户
组织
在 users 下,我们有 users/userid/ar/organisationid(ar 表示访问权限)
本文档应定义用户对给定组织的访问权限。关键是许多用户可以访问此 saas 应用程序中的一个或多个组织。
我希望再次检查该组织下的所有文档和所有子集合的访问权限。
这非常适合获取和写入,但数据列表会导致访问错误,我发现限制列表数据的唯一方法是在列出用户 ID 的文档上添加一个数组,并在此客户端上进行过滤边。这不是一个可用于生产的解决方案,因为会有很多包含许多文档的子集合。
有什么建议吗?我可以通过其他方式使列表适用于 Firestore 吗?有没有更好的方法来构建数据,或者我遗漏了什么?
我能看到的唯一其他方法是使用 firestore 函数来检查服务器端的列表,但随后我们在 @angular/fire 中丢失了很棒的东西。
过滤客户端的安全性不够。
谢谢。
目前的规则:
service cloud.firestore {
match /databases/{database}/documents {
match /users/{userId} {
allow read, write: if request.auth.uid == userId;
match /ar/{organisationDoc} {
allow read: if request.auth.uid == userId;
allow write: if false;
}
}
// read
match /organisations/{oId} {
allow get: if exists(/databases/$(database)/documents/users/$(request.auth.uid)/ar/$(oId));
allow list: if request.auth.uid in resource.data.users;
match /{all=**} {
allow get: if exists(/databases/$(database)/documents/users/$(request.auth.uid)/ar/$(oId));
allow list: if request.auth.uid in resource.data.users;
}
}
// write
match /organisations/{oId} {
allow create: if get(/databases/$(database)/documents/users/$(request.auth.uid)/ar/$(oId)).data.create == true;
allow update: if get(/databases/$(database)/documents/users/$(request.auth.uid)/ar/$(oId)).data.update == true;
allow delete: if get(/databases/$(database)/documents/users/$(request.auth.uid)/ar/$(oId)).data.delete == true;
match /{all=**} {
allow create: if get(/databases/$(database)/documents/users/$(request.auth.uid)/ar/$(oId)).data.create == true;
allow update: if get(/databases/$(database)/documents/users/$(request.auth.uid)/ar/$(oId)).data.update == true;
allow delete: if get(/databases/$(database)/documents/users/$(request.auth.uid)/ar/$(oId)).data.delete == true;
}
}
}
}
【问题讨论】:
标签: firebase google-cloud-firestore firebase-security