【问题标题】:Authenticate gcloud service account in automated fashion以自动方式验证 gcloud 服务帐户
【发布时间】:2019-06-09 22:29:59
【问题描述】:

总体目标:

我们希望能够使用 Circle CI 作业中的 Docker 容器将工件上传到 Google Cloud 中的存储桶。理想情况下,我们可以使用gsutil cp <artifact> <bucket>

问题:

我最难以自动方式验证gcloud 服务帐户,而且我在任何地方都找不到这方面的文档。几乎我读过的每一篇文章都让你遵循以下两种变体之一:

  1. 使用gsutil配置

    $ gsutil config -a
    

    但是,这会提示一系列需要与 shell 交互的问题:

    Backing up existing config file "/Users/<user>/.boto" to "/Users/<user>/.boto.bak"...
    This command will create a boto config file at
    /Users/<user>/.boto containing your credentials, based on your
    responses to the following questions.
    What is your google access key ID?
    
  2. 使用gcloud登录:

    $ gcloud auth login
    Your browser has been opened to visit:
    
        https://accounts.google.com/o/oauth2/auth?....
    

由于这里的最终结果是 Docker 容器将验证服务帐户以执行gsutil cp,因此交互式登录不是很有利...

我在 this example 中设置了凭据 JSON,但设置环境变量 GOOGLE_APPLICATION_CREDENTIALS 仍然 提示无法自动绕过的 Are you sure? [Y/n] 消息。有什么想法吗?

【问题讨论】:

    标签: google-cloud-platform gcloud gsutil


    【解决方案1】:

    从服务帐号 Json 文件配置 Google Cloud SDK CLI 的命令:

    gcloud auth activate-service-account test@development-123456.iam.gserviceaccount.com --key-file=service_account.json

    将电子邮件地址 test@... 替换为您的服务帐户电子邮件地址。 将 Json 文件名 service_account.json 替换为您用于服务帐户凭据的文件名。

    服务帐户电子邮件地址在服务帐户 json 文件中,为 client_email

    如果您想了解更多信息,我写了一些关于 Google 凭据和 OAuth 的文章:

    Google Cloud – Setting up Gcloud with Service Account Credentials

    【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2020-08-29
    • 1970-01-01
    • 2021-03-14
    • 2014-07-04
    • 1970-01-01
    • 2021-10-24
    • 1970-01-01
    • 2020-12-03
    相关资源
    最近更新 更多