小编Tho*_*søy的帖子

Firestore 规则多组织多用户访问权限列表数据

我正在尝试为我们有以下根集合的新 Firestore 项目设置规则集:

用户

组织

在用户下,我们有 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: …
Run Code Online (Sandbox Code Playgroud)

firebase firebase-security google-cloud-firestore

6
推荐指数
1
解决办法
1326
查看次数