问题描述
是否可以根据 Firebase 实时数据库中存储的数据评估条件来分配 Firebase 存储安全规则?
Is it possible to assign Firebase Storage security rules based on evaluating a condition from data stored in Firebase Realtime Database?
例如:
(1) Firebase 存储模型:
(1) Firebase Storage Model:
{ userPhotos/:
"JohnUID" : {
"JohnURL": john.jpeg,
},
"JaneUID" : {
"JaneURL": jane.jpeg,
},
"AbbyUID" : {
"AbbyURL": abby.jpeg,
},
}
(2) Firebase 实时数据库模型:
(2) Firebase Realtime Database Model:
{ userReadPermissions:
"JohnUID": {
"JohnUID": true,
"JaneUID": true,
"AbbyUID": false,
},
"JaneUID": {
"JohnUID": true,
"JaneUID": true,
"AbbyUID": false,
},
"AbbyUID": {
"JohnUID": false,
"JaneUID": false,
"AbbyUID": true,
},
}
目标是根据 Firebase RTD (2) 中每个 UID 设置的条件,仅允许对照片 URL 存储节点 (1) 的读取权限.
The goal is to only allow read permissions to the photo URL storage node (1) according to the conditions set by each UID in Firebase RTD (2).
例如,只有 John & 才能看到 John 的照片.Jane,但不是 Abby,根据 (2) 中每个用户定义的权限.
For example, John's photo would only be visible to John & Jane, but not Abby, as the per the permissions defined by each user in (2).
同样,只有 John & 才能看到 Jane 的照片.Jane,而不是 Abby,而 Abby 的照片只有 Abby 可见,John 和 Jane 都不可见.
Similarly, Jane's photo would only be visible to John & Jane, but not Abby, while Abby's photo would be visible to Abby only, and to neither John or Jane.
有没有办法交叉引用跨这些 Firebase 服务定义的条件来相应地定义安全规则?
Is there a way to cross-reference conditions defined across these Firebase services to define security rules accordingly?
推荐答案
无法从 Firebase 存储安全规则访问 Firebase 实时数据库.
There is no way to access the Firebase Realtime Database from Firebase Storage security rules.
您要么必须将读取权限直接编码到存储安全规则中(如图所示 此处),或将成员资格"编码为一小组 自定义声明.
You will either have to encode the read permissions directly into the Storage security rules (as shown here), or encode the "membership" into a small set of custom claims.
另见:
这篇关于根据 Firebase 数据库条件创建 Firebase 存储安全规则的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!