【问题标题】:Granting access to a Google Cloud Storage bucket to a third-party向第三方授予对 Google Cloud Storage 存储分区的访问权限
【发布时间】:2019-04-05 23:30:27
【问题描述】:

我需要第三方将一些文件上传到 Google Cloud Storage 存储分区。授予他们访问权限的最佳(或最简单)方法是什么?

【问题讨论】:

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


    【解决方案1】:

    前两种方法要求用户拥有有效的Google Account。我在这个答案中忽略了Google Identity Platform。如果用户有一个Gmail Account,那么这意味着他们也有一个Google Account。第三种方法使用 Google 服务帐户。

    方法一:使用谷歌云存储控制台:

    • 转到Storage -> Browser

    • 检查所需的存储桶。在permissions 下的右侧面板中,单击Add 按钮。

    • 添加用户的 Google 帐户电子邮件地址。选择Storage Object Creator

    授予的角色是roles/storage.objectCreator。该角色授予用户在存储桶中创建对象的权限,但用户不能删除或覆盖对象。

    Link to Cloud Storage Roles

    方法2:使用gsutl CLI:

    gsutil iam ch user:username@example.com:ObjectCreator gs://examplebucket
    

    Link to gcloud IAM

    读取当前存储桶 IAM 策略的命令:

    gsutil iam get gs://examplebucket
    

    方法 3:使用 Google 服务帐号

    在 Google Cloud Console 中创建 Google 服务帐号

    1. 转到IAM & admin -> Service accounts
    2. 点击CREATE SERVICE ACCOUNT
    3. 输入Service account nameService account description
    4. 点击CREATE
    5. 在下一个屏幕Service account permissions 中,选择一个角色。
    6. 选择Storage -> Storage Object Creator
    7. 点击CONTINUE
    8. 点击Create key
    9. 检查JSON 单选按钮以获取Key type
    10. 将 json 文件保存到本地计算机。

    您现在拥有Google Service Account 凭据,可以使用gsutilgcloud 和软件程序进行设置。

    Setting up gcloud with Service Account Credentials

    【讨论】:

      【解决方案2】:

      您授予第三方客户将文件上传到 Google Cloud Storage 存储分区的访问权限的方式因一种编程语言而异。在 PHP 中,您可以编写如下内容:

      $options = ['gs_bucket_name' => $my_bucket]; $upload_url = CloudStorageTools::createUploadUrl('/upload/handler', $options);

      并因此获得一个上传 URL。您可以在“允许用户上传文件”在线document 中找到有关此解决方案的更多详细信息。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2016-11-07
        • 1970-01-01
        • 2021-05-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2019-07-12
        • 1970-01-01
        相关资源
        最近更新 更多