云安全的FireStore规则允许从火力地堡功能只写

问题描述 投票:11回答:2

我真的希望能够通过只允许火力功能写入特定集合,以确保我公司的FireStore分贝......我怎么会去这样做?看着有相关文件证明我没有发现任何可能说明你如何能做到这一点。举例来说,我在寻找的东西,如:

service cloud.firestore {
  match /databases/{database}/documents {

    // Match any document in the 'cities' collection
    match /cities/{city} {
      allow read;
      allow write: if <from firebase function>;
    }
  }
}
firebase google-cloud-firestore google-cloud-functions firebase-security-rules
2个回答
36
投票

对于火力地堡码云功能一般访问使用火力地堡联系SDK等火力地堡产品。管理SDK将有完全的读写访问公司的FireStore,不管权限如何设置。您可以既没有明确允许,也没有拒绝访问管理SDK,这意味着你也不能明确允许,也没有拒绝访问的云功能。

如果你只是想你的后端读取和写入数据库的某些部分,但没有你的手机客户端应用程序,简单地拒绝访问完全所有客户端,并且让管理员SDK做其工作。

service cloud.firestore {
  match /databases/{database}/documents {

    // Match any document in the 'cities' collection
    match /cities/{city} {
      allow read: if false;
      allow write: if false;
    }
  }
}

1
投票

所以,我用这个规则:

service cloud.firestore {
  match /databases/{database}/documents {
    match /{document=**} {
      allow read: if false;
      allow write: if false;
    }
  }
}

它基于上面的回答。它只是不允许任何客户端应用程序访问,除非管理员SDK。

© www.soinside.com 2019 - 2024. All rights reserved.