【发布时间】:2020-12-07 01:40:06
【问题描述】:
我正在尝试使用 Firestore 模拟器测试我的安全规则。我做了一个firestore.rules 禁止所有读写的安全规则:
service cloud.firestore {
match /databases/{database}/documents {
allow read, write: if false;
}
}
我从终端启动了 Firestore 模拟器:
firebase emulators:start --only firestore
然后我初始化了我的 Firestore 客户端:
import firebase_admin
from firebase_admin import firestore
firebase_app = firebase_admin.initialize_app()
self.client = firestore.client(app=firebase_app)
我在 Firestore 模拟器的数据库中添加了一个示例文档:
self.client.collection("Users").document("user_1").set(...)
这一切都成功了,这是出乎意料的。我禁止了所有写入,但我只执行了一次,Firestore 模拟器成功确认规则生效:
[info] ✔ firestore: Rules updated.
我终于遇到了Get started with Cloud Firestore Security Rules,它说:
服务器客户端库绕过所有 Cloud Firestore 安全规则,而是通过 Google 应用程序默认凭据进行身份验证。
真的没有办法修改self.client 或firebase_app 使得上面的写入失败吗?我无法想象这种类型的身份验证仅受客户端支持(如在 iOS/Android 设备上)。页面继续:
如果您使用服务器客户端库或 REST 或 RPC API,请确保为 Cloud Firestore 设置身份和访问管理 (IAM)。
但根据我的实际安全规则,我试图限制对某些集合/文档的访问,而 IAM 似乎只涵盖全局权限,例如 createDocument。
【问题讨论】:
标签: python firebase google-cloud-firestore firebase-authentication firebase-security