我正在尝试根据用户数据保护我的Firebase(Google云存储)文件的安全。在firestore中,我使用了一条基于获取数据库内容的规则(在users表中查找uid并匹配一个字段),并且工作正常。我正在尝试在Firebase存储中使用相同的规则,但是在模拟器中,我得到了Error: simulator.rules line [12], column [17]. Function not found error: Name: [get].; Error: Invalid argument provided to call. Function: [get], Argument: ["||invalid_argument||"]
。我的规则如下:
match /b/{bucket}/o {
function isAuth() {
return request.auth != null && request.auth.uid != null
}
function isAdmin() {
return isAuth() &&
"admin" in get(/databases/$(database)/documents/users/$(request.auth.uid)).data.roles;
}
function clientMatch(client) { // expects user's "client" field to be ID of client
return isAuth() &&
client == get(/databases/$(database)/documents/users/$(request.auth.uid)).data.client;
}
match /P/Clients/{client}/{allPaths=**} {
allow read, write: if isAdmin() || clientMatch(client);
}
}
}
第12行是client == get
中以clientMatch()
开头的那一行。
我无法确定这些功能是否仅受Firestore(db)规则支持,或者它们是否也应用于存储。
如果这不起作用,我有什么选择?人们如何查找用户数据以确保Firebase存储安全?
答案 0 :(得分:1)
您目前无法在“存储”规则中引用Firestore文档。如果您希望将其作为存储规则的功能,请file a feature request。
考虑在文件上传后使用Cloud Functions存储触发器执行一些其他检查,如果发现文件无效,则将其删除。