【问题标题】:Why are Cloud Functions not stopped from writing when using Security rules in Firestore?为什么在 Firestore 中使用安全规则时 Cloud Functions 不会停止写入?
【发布时间】:2019-09-27 05:48:49
【问题描述】:

我使用 Cloud Firestore 作为后端。我正在使用规则,因此只有经过身份验证的用户才能读取一些数据(私人数据),而他们都不能写入。我还创建了一个在将一些新内容添加到数据库时触发的函数。但是,当触发该功能时,即使规则设置为false,我也可以写入数据。

如何阻止这种情况发生?

【问题讨论】:

    标签: firebase google-cloud-firestore google-cloud-functions


    【解决方案1】:

    实际上,当您通过 Cloud Function(使用 Firebase Admin SDK)访问 Firestore 时,没有任何安全规则适用。

    以下文档https://firebase.google.com/docs/admin/setup 明确指出对于 Relatime Database:

    Admin SDK 可让您从特权用户与 Firebase 交互 执行读取和写入实时数据库等操作的环境 具有完全管理员权限的数据。

    但与 Firestore 相同。

    此 Firestore“入门”文档中还有一个注释https://firebase.google.com/docs/firestore/security/get-started

    注意:服务器客户端库绕过所有 Cloud Firestore 安全 规则...

    如上所述,这不仅适用于 Admin SDK,也适用于其他服务器 SDK,因为您在 Firebase 所谓的“特权环境”中使用这些服务器 SDK,例如您自己的服务器(在您的控制之下)或Cloud Functions(也在您的控制之下,因为您是唯一能够部署 Cloud Functions 代码的人)。另见What is a "trusted server environment" in Firebase?


    如果您想限制 Cloud Function 的写入权限,则需要在 Cloud Function 中开发特定的业务逻辑来模仿您的安全规则。

    【讨论】:

      猜你喜欢
      • 2021-12-11
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-11-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多