【问题标题】:How to change the scope of a Google Compute Engine service account to write data to a Google Cloud Storage bucket?如何更改 Google Compute Engine 服务帐户的范围以将数据写入 Google Cloud Storage 存储桶?
【发布时间】:2015-10-29 13:25:58
【问题描述】:

在 GCE 上运行了一个实例,并且在同一个项目中有一个 GCS 存储桶。但我无法向其写入数据。如何将数据从 VM 实例写入存储桶?

【问题讨论】:

    标签: google-cloud-storage google-compute-engine service-accounts


    【解决方案1】:

    更新:截至 2016 年 12 月 15 日setServiceAccount 功能现在处于测试版

    如果您想以不同的身份运行,或者您确定该实例需要一组不同的范围来调用所需的 API,您可以更改现有实例的服务帐号和/或访问范围。例如,您可以更改访问范围以授予对新 API 的访问权限,或更改实例以使其作为您创建的服务帐户而不是 Compute Engine 默认服务帐户运行。

    要更改实例的服务帐号和访问范围,必须暂时停止该实例。要停止您的实例,请阅读Stopping an instance 的文档。更改服务帐号或访问范围后,记得restart the instance

    documentation 提供了有关如何使用 Google Cloud Consolegcloud CLI 工具以及 API 来使用此功能的说明。这是使用gcloud 的示例;请参阅docs 了解更多信息。

    gcloud beta compute instances set-scopes [INSTANCE_NAME] \
         --service-account [SERVICE_ACCOUNT_EMAIL] \
         [--no-scopes | --scopes [SCOPES,...]]
    

    上一个答案(2016 年 12 月 15 日之前有效):

    您无法更改正在运行的虚拟机实例的范围。您可以:

    • create a new instance(可能重用当前实例的磁盘)在创建时指定正确的范围,例如:

      gcloud compute instances create [...] --scopes storage-rw
      
    • 如果您想在虚拟机内部手动使用gsutil,您可以在虚拟机内部运行gsutil config,并按照提示进行身份验证

    • 如果您计划通过 Google API 使用自动化工具,请使用service account

    【讨论】:

      【解决方案2】:

      有待改进:

      Google Cloud Platform Ability to change API access scopes

      但尚未说明到期日。敬请期待。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2020-05-05
        • 1970-01-01
        • 2022-07-25
        • 2014-07-10
        • 1970-01-01
        • 2018-11-17
        • 2015-10-16
        相关资源
        最近更新 更多