【问题标题】:"Could not load default credentials" google cloud secrets manager - use CLI authorized user“无法加载默认凭据”谷歌云机密管理器 - 使用 CLI 授权用户
【发布时间】:2021-05-16 18:07:03
【问题描述】:

我想让我的nodeJS 应用程序使用我的IAM 凭据在本地进行身份验证,但是当我运行下面的基本secrets manager 函数时:

// config/secret_manager.js
const { SecretManagerServiceClient } = require('@google-cloud/secret-manager')

const client = new SecretManagerServiceClient()

async function getSecret(name) {
  const [version] = await client.accessSecretVersion({ name })
  const secretValue = JSON.parse(version.payload.data.toString())

  return secretValue
}

module.exports = getSecret

我收到错误:

无法加载默认凭据。浏览至https://cloud.google.com/docs/authentication/getting-started 了解更多信息。 在 GoogleAuth.getApplicationDefaultAsync

我似乎找不到任何关于如何在本地使用我的 CLI 登录凭据的文档,有什么想法

(我不想使用 JSON 服务帐户配置)

【问题讨论】:

  • 由于您标记了Node.js,您可能应该使用服务帐户而不是用户凭据。对于调试,可以使用用户凭据,但不建议用于生产场景。在 Google 计算服务上运行代码时,应使用元数据中的凭据。使用有关环境的更多详细信息更新您的问题。
  • @JohnHanley in CloudRun 会不会同样的功能不能获取任何可用的服务帐户?
  • 您问题中的代码将从元数据中获取凭据。您的答案在 Cloud Run 中不起作用。一个关键点是不要在应该使用服务帐户的地方使用用户凭据,这对于其中一项计算服务几乎总是如此。 SDK 将打印警告,您将受到配额限制等。

标签: node.js google-cloud-platform service-accounts google-secret-manager gcloud-cli


【解决方案1】:

即使您通过gcloud CLI 进行身份验证您也需要设置默认应用程序登录。这可以通过运行gcloud auth application-default login

来解决

来源:Could not load the default credentials? (Node.js Google Compute Engine tutorial)

【讨论】:

    猜你喜欢
    • 2020-10-15
    • 2021-01-02
    • 1970-01-01
    • 1970-01-01
    • 2017-06-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-11-13
    相关资源
    最近更新 更多