【问题标题】:How can I give my Google Cloud App Engine access to my Firebase Storage bucket如何让我的 Google Cloud App Engine 访问我的 Firebase Storage 存储分区
【发布时间】:2018-03-17 16:05:07
【问题描述】:

我收到一个错误:API error 7 (images: ACCESS_DENIED)

通常我会将 Firebase 应用与我的 Google App Engine 服务相关联,但由于 Firestore 与 App Engine 不兼容,我必须创建单独的服务实例。但是,现在我需要我的应用引擎图像服务能够引用 firebase 云存储文件夹中的文件。如何设置访问权限,是否需要创建某种在两种服务之间共享的 IAM?

我的应用引擎 go 函数引用 firebase 存储桶 the-other-firebase-app 的示例

func photoHandler(w http.ResponseWriter, r *http.Request) {

    c := appengine.NewContext(r)
    v := r.URL.Query()
    fileName := v.Get("file")
    if (fileName == "") {
        fmt.Fprint(w, "file name is required")
    } else {
        filename := "/gs/the-other-firebase-app.appspot.com/photos/" + fileName;
        blobKey,err := blobstore.BlobKeyForFile(c, filename)
        if (err == nil) {
            url, urlErr := image.ServingURL(c, blobKey, nil)
            if (urlErr == nil) {
                fmt.Fprint(w, url)
            } else {
                fmt.Fprint(w, urlErr)
            }
        } else {
            fmt.Fprint(w, "image does not exist")
        }
    }  
}

【问题讨论】:

    标签: google-app-engine google-cloud-storage firebase-storage


    【解决方案1】:

    如果您的应用是标准 env 应用,它应该已经有一个服务帐户,请参阅 Using service accounts

    App Engine 应用程序使用 App Engine 的身份运行 默认服务帐户。您可以在 IAM 页面上看到此帐户 云平台控制台。

    如果您的应用是 flex 引擎,请参阅 Service Account for the App Engine Flexible Environment:

    当您启用 Google App Engine 柔性环境 API 时, 会自动创建特定的服务帐户。您可以查看您的 IAM section of the Cloud Platform Console 中的项目服务帐户。 App Engine 柔性环境服务的电子邮件 帐户是 service-[PROJECT-NUMBER]@gae-api-prod.google.com.iam.gserviceaccount.com, 其中[PROJECT-NUMBER]IAM settings 中列出的项目编号。

    在 Firebase 应用项目中,您需要将 GAE 应用的服务帐号添加为团队成员,并为其授予必要的权限。

    如评论中所述:

    Firebase Dasbhoard -> 项目设置 Cog -> 用户和权限 – 小猴子

    可能感兴趣的也可能是Integrate with Google Cloud Platform

    【讨论】:

    • 添加项目成员的链接适用于谷歌云仪表板,而不是 Firebase 仪表板 - 如何操作 Firebase 项目的权限 - 我在 Firebase 仪表板中看不到任何添加项目的内容成员。
    • 哦,我现在明白了,我可以继续 Firebase Dasbhoard -> 项目设置 Cog -> 用户和权限
    【解决方案2】:

    我有一个非常相似的问题,但抛出的确切错误消息是:

    _"your-project-name@appspot.gserviceaccount.com 没有 storage.objects.get 访问 storage_file_path_here>"_

    感谢 eltonnobrega 在 Github 上的建议,我修复了它:https://github.com/firebase/functions-samples/issues/299

    总结如下:

    1. 进入 Google Cloud Console 并选择您的存储桶所在的项目 - 您要从您的服务帐户访问的存储桶。
    2. 转到“存储”选项卡
    3. 在浏览器选项卡上,您应该会看到此项目中的存储桶。每个选项都会在右侧结束的行处显示一个选项图标(三个垂直点)
    4. 从这些选项中选择编辑存储桶权限
    5. 您可以从那里添加成员。添加您的服务帐户 (your-project-name@appspot.gserviceaccount.com) 并为其赋予 Storage Object Admin 角色

    【讨论】:

      猜你喜欢
      • 2017-07-07
      • 2021-11-14
      • 1970-01-01
      • 2020-08-01
      • 1970-01-01
      • 1970-01-01
      • 2017-05-28
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多