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)
Even if you're authenticated with the
gcloudCLIyou need to set the default application login. This is solved by runninggcloud auth application-default loginSource: Could not load the default credentials? (Node.js Google Compute Engine tutorial)