Does anyone know if there is a good NodeJS library to connect to hashicorp vault from an AWS Lambda using IAM Authentication.
Something similar to HVAC for Python would be good.
I have tried using node-vault-client but there aren't any good examples of IAM Authentication and it doesn't seem to have had an update since 2019 so I am not sure if its actively being maintained.
I managed to get it working using node-vault-client but I had to make changes to the library because it doesnt allow you to pass a namespace header. I have raised a PR that adds a new field to resolve the issue.
Here is a sample of my code:
const VaultClient = require('node-vault-client');
const vaultClient = VaultClient.boot('main', {
api: { url: 'https://my-vault-url.com' },
auth: {
type: 'iam',
config: {
role: 'my-role',
iam_server_id_header_value: 'my-vault-url.com',
namespace: 'my-namespace', // new option added in my pull request
credentials: new AWS.Credentials({
accessKeyId: process.env.AWS_ACCESS_KEY_ID,
secretAccessKey: process.env.AWS_SECRET_ACCESS_KEY,
sessionToken: process.env.AWS_SESSION_TOKEN,
}),
},
},
});
vaultClient
.read('secrets/data/path/to/secret')
.then((secrets: any) => {
console.log(`MY SECRET IS ${secrets.__data.data['MY_SECRET_KEY']}`);
})
.catch((e: Error) => {
console.error('Error connecting to vault .....');
console.error(e);
});