小编Mic*_*ard的帖子

Google Cloud Build 中的应用程序默认凭据

在我的代码中,我尝试从 Cloud Build 中的关联服务帐户收集应用程序默认凭据:

from google.auth import default

credentials, project_id = default()
Run Code Online (Sandbox Code Playgroud)

这在我的本地空间中工作得很好,因为我已经适当地设置了环境变量GOOGLE_APPLICATION_CREDENTIALS。但是,当在 Cloud Build 中执行此行(通过构建配置中的测试步骤)时,会引发以下错误:

google.auth.exceptions.DefaultCredentialsError: Could not automatically determine credentials. 
Please set GOOGLE_APPLICATION_CREDENTIALS or explicitly create credentials and re-run the application. 
For more information, please see https://cloud.google.com/docs/authentication/getting-started
Run Code Online (Sandbox Code Playgroud)

这让我很困惑,因为根据文档:

默认情况下,Cloud Build 使用特殊服务帐户代表您执行构建。此服务帐号称为 Cloud Build 服务帐号,当您在 Google Cloud 项目中启用 Cloud Build API 时,它会自动创建。 在这里阅读

如果未设置环境变量 GOOGLE_APPLICATION_CREDENTIALS,ADC 将使用附加到正在运行代码的资源的服务帐户。 在这里阅读

那么为什么默认调用无法访问 Cloud Build 服务帐户凭据呢?

python service-accounts google-cloud-platform dockerfile google-cloud-build

9
推荐指数
1
解决办法
5782
查看次数