Cloud Firestore安全规则仅允许从Firebase功能写入

编程入门 行业动态 更新时间:2024-10-28 00:15:53
本文介绍了Cloud Firestore安全规则仅允许从Firebase功能写入的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我真的很希望能够通过只允许将Firebase函数写入特定集合来保护我的Firestore数据库...我将如何去做呢?看那里的文档,我找不到任何可以说明您如何执行此操作的文件.例如,我正在寻找类似的东西:

I'd really like to be able to secure my firestore db by allowing only firebase functions to write to the specific collection... how would I go about doing that? Looking at there documentation I do not find anything that might state how you could do that. For instance, I am looking for something like:

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代码的Cloud Functions通常使用Firebase Admin SDK访问其他Firebase产品.无论如何设置权限,Admin SDK都将具有对Firestore的完全读取和写入访问权限.您既不能明确允许也不拒绝对Admin SDK的访问,这意味着您也不能明确允许也不拒绝对Cloud Functions的访问.

Cloud Functions for Firebase code generally accesses other Firebase products using the Firebase Admin SDK. The Admin SDK will have full read and write access to Firestore, no matter how the permissions are set. You can neither explicitly allow nor deny access to the Admin SDK, which means you also can't explicitly allow nor deny access to Cloud Functions.

如果您只希望后端读取和写入数据库的某些部分,但不读取任何移动客户端应用程序,则只需完全拒绝对所有客户端的访问,然后让Admin SDK进行工作即可.

If you just want your backend to read and write some part of your database but none of your mobile client apps, simply reject access to all clients entirely, and let the Admin SDK do its work.

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; } } }

更多推荐

Cloud Firestore安全规则仅允许从Firebase功能写入

本文发布于:2023-11-22 05:14:47,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1616107.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:规则   功能   Cloud   Firestore   Firebase

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!