gpt4 book ai didi

python - Firestore 中具有服务帐户的细化权限

转载 作者:行者123 更新时间:2023-12-01 01:20:01 26 4
gpt4 key购买 nike

我正在编写一个从诊断包收集信息的工具。该工具的结果会写入 Firestore 中进行分析。该工具用 Python 编写并作为包分发,包括服务帐户的 .json。该服务帐户用于验证数据库的读取和写入。以下是每个包中使用的数据库组件的片段:

    import firebase_admin
from firebase_admin import credentials
from firebase_admin import firestore

cred=credentials.Certificate(os.path.join(os.path.dirname(os.path.abspath(__file__), 'name_of_file.json'))
firebase_admin.initialize_app(cred)

db = firestore.client()

我希望缩小 Firestore 的权限范围,因为目前,拥有这些凭据的所有用户都可以完全访问 Firestore。查看文档,这似乎不可能:

Code that uses the Firebase Admin SDK with a service account to access Firestore currently can not be scoped to a particular user ID for the purpose of enforcing security rules. All access with the Admin SDK will bypass security rules and have full control of the database.

有人知道这种用例的解决方法吗?作为替代方案,是否可以“硬编码”Firebase 用户帐户?如果是这样,最直接的实现是什么?

如果有什么需要澄清的地方,请告诉我,我对 Firebase 还很陌生,所以我可能会走完全错误的方向!

谢谢!

最佳答案

Firestore 目前无法将使用服务帐户的连接范围限制为某些有限权限。使用 Admin SDK 时,您始终拥有对整个数据库的完全读写访问权限。这是一个普遍要求的功能,您应该 file a feature request如果这对您也有用。

关于python - Firestore 中具有服务帐户的细化权限,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53918625/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com