"Could not load default credentials" google cloud secrets manager - use CLI authorized user

4.3k views Asked by At

I would like to have my nodeJS application authenticate itself locally with my IAM credentials, however when I run the basic secrets manager function below:

// 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

I receive the error:

Could not load the default credentials. Browse to https://cloud.google.com/docs/authentication/getting-started for more information. at GoogleAuth.getApplicationDefaultAsync

I can't seem to find any documentation on how to use my CLI login credentials locally, any ideas?

(I don't want to use a JSON service account config)

1

There are 1 answers

0
Kevin Danikowski On BEST ANSWER

Even if you're authenticated with the gcloud CLI you need to set the default application login. This is solved by running gcloud auth application-default login

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