【问题标题】:Why my Cloud Run Instance is using the Default Service account instead of my Dedicated Service Account?为什么我的 Cloud Run 实例使用默认服务帐户而不是我的专用服务帐户?
【发布时间】:2022-10-02 00:28:18
【问题描述】:

我有一个带有专用服务帐户的 Cloud Run 实例(我在 UI(GCP Concole)-> 修订/安全选项卡中看到它)。我认为这意味着,它被设置为主要(默认)标识符。

在 Cloud Run 中,我运行一个 python 应用程序,我想生成一个签名的 url

credentials, project_id = google.auth.default()
blob = bucket.get_blob(blob_name)
expires = datetime.now() + timedelta(seconds=86400)
url = blob.generate_signed_url(expiration=expires, credentials=credentials)

但我收到以下错误消息(引用默认计算引擎服务帐户):

AttributeError: you need a private key to sign credentials.the credentials you are currently using <class \'google.auth.compute_engine.credentials.Credentials\'> just contains a token.

我的问题:

  • 为什么默认服务帐户仍然是计算引擎一而不是专用服务帐户?
  • 如何将我的专用服务帐户设置为 Cloud Run 实例的“默认/主”服务帐户?

    标签: python google-cloud-platform google-cloud-run service-accounts


    【解决方案1】:

    文档很差而且不清楚,但我认为(!?)正在发生的事情是应用程序默认凭据不包含私钥,并且需要私钥来生成签名 URL。

    如果正确,问题不是无论您使用的是默认的 Compute Engine 服务帐户还是用户定义的服务帐户,但 google.auth.default() 生成的凭据不包含私钥,generate_signed_url 需要私钥!?

    如果 (!) 正确,解决方案是直接从 JSON 密钥 (link) 创建一个新的凭证对象。

    generated_signed_url 的文档中有一个 Note,但写得不好。我认为它指的是Signed BLOB creation with (Application) Default Credentials does not work,它也没有完全解释问题或解决方案。

    【讨论】:

      猜你喜欢
      • 2021-04-21
      • 1970-01-01
      • 2016-06-01
      • 2021-08-31
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多