【发布时间】:2022-11-23 21:23:03
【问题描述】:
我正在使用 firebase 的云 firestore 数据库,我想将对该数据库的访问限制为两个通过 API 密钥和一个服务帐户进行身份验证的移动应用程序。
我查看了 firebase documentation on implementing custom rules,但我没有看到任何 API 密钥或服务帐户示例,因此我不确定如何针对此用例使用规则。
从这个 stackoverflow question and answer 看来,使用 firebase admin API 的服务帐户似乎绕过了任何 firestore 安全规则,对吗?如果是这样,完全关闭对我只希望此服务帐户更新的任何 firestore 集合的写访问是否合理?
到目前为止,我已经尝试过类似的方法来允许从服务帐户进行访问,但它没有按预期工作。我不确定云 Firestore 规则是否支持限制对某些 API 密钥的访问。
rules_version = '2';
service cloud.firestore {
match /databases/{database}/documents {
match /sales_reps/{document=**} {
allow read: if true;
allow write: if request.auth.token.email == '<first-service-account-email>';
}
match /gps_tracking/{document=**} {
allow read: if true;
allow write: if request.auth.token.email == '<second-service-account-email>';
}
match /{document=\*\*} {
allow read: if true;
allow write: if false;
}
}
}
【问题讨论】:
标签: firebase google-cloud-firestore firebase-security