首页 > 解决方案 > “无法加载默认凭据”谷歌云机密管理器 - 使用 CLI 授权用户

问题描述

我想让我的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.jsgoogle-cloud-platformservice-accountsgoogle-secret-managergcloud-cli

解决方案


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

来源:无法加载默认凭据?(Node.js 谷歌计算引擎教程)


推荐阅读