在 Firebase 存储中,我可以使用 db“get”规则吗?

Gar*_*ryO 4 google-cloud-storage firebase firebase-security

我正在尝试根据用户数据保护我的 Firebase(谷歌云存储)文件。在 firestore 中,我使用基于获取数据库内容的规则(在用户表中查找 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);
    }
  }
}
Run Code Online (Sandbox Code Playgroud)

第 12 行是一个开始client == get,在clientMatch(). 我无法判断这些函数是否仅支持 Firestore (db) 规则,或者它们是否也适用于存储。

如果这不起作用,我有什么选择?人们如何查找 Firebase 存储安全的用户数据?

Dou*_*son 7

您目前无法在存储规则中引用 Firestore 文档。如果您希望将其视为存储规则的一项功能,请提交功能请求

考虑改为使用 Cloud Functions 存储触发器在文件上传后执行一些额外检查,如果您发现文件无效,则将其删除。

  • 这主要不是关于写入,而是关于限制读取。我不想让客户看到彼此的文件! (2认同)