首页 > 解决方案 > 什么规则将使我的 Firebase 存储桶只能由同一项目中的 Firebase 函数访问?

问题描述

我的文件上传到 Cloud Storage 存储分区只能从 Firebase 控制台进行。什么 Cloud Storage 规则只允许我在同一个项目中的 Firebase 函数读取/写入存储桶?

service firebase.storage {
  match /b/{bucket}/o {
    match /{allPaths=**} {
       ???
    }
  }
}

标签: firebasegoogle-cloud-platformgoogle-cloud-functionsgoogle-cloud-storage

解决方案


Cloud Functions 以对其所属项目的管理访问权限运行。这意味着您可以简单地不授予普通用户访问存储桶的权限,因为 Cloud Functions 无论如何都会绕过您的规则。

文档中:

// Access to files through Firebase Storage is completely disallowed.
// Files may still be accessible through Google App Engine or GCS APIs.
service firebase.storage {
  match /b/{bucket}/o {
    match /{allPaths=**} {
      allow read, write: if false;
    }
  }
}

您对 Cloud Functions 的访问属于上述评论中的“GCS API”。


推荐阅读