0

I was trying to integrate vault in my Nodejs application using "node-vault ". I am getting below error enter image description here

Please see the code snippet

  var options = {
  apiVersion: 'v1', // default
  endpoint: 'https://XXXXXXXXXX', 
  token: 'XXXXXX' 
};

// get new instance of the client
var vault = require("node-vault")(options);

// init vault server
vault.init({ secret_shares: 1, secret_threshold: 1 })
.then( (result) => {
  var keys = result.keys;
  // set token for all following requests
  vault.token = result.root_token;
  // unseal vault server
  return vault.unseal({ secret_shares: 1, key: keys[0] })
})
.catch(console.error);
Anoop M Nair
  • 1,057
  • 1
  • 13
  • 31
  • May be related to you working locally? see this & attempt the solution https://stackoverflow.com/questions/9626990/receiving-error-error-ssl-error-self-signed-cert-in-chain-while-using-npm/10796030#10796030 – Aviad Nov 26 '20 at 14:13
  • tried that but same issue repeating – Anoop M Nair Nov 26 '20 at 14:25
  • Can you elaborate on which env this is happening? (obviously, censor any sensitive info) As in - is it targeted locally? which authority provided the certs etc – Aviad Nov 26 '20 at 14:31
  • Its happening in my local, trying connect vault instance hosted in GCP – Anoop M Nair Nov 26 '20 at 15:07
  • Since you're connecting from your localhost, try passing the `NODE_TLS_REJECT_UNAUTHORIZED=0` env variable and test again – Aviad Nov 26 '20 at 15:20
  • I have set export NODE_TLS_REJECT_UNAUTHORIZED="0" this one again getting the same issue – Anoop M Nair Nov 26 '20 at 15:35

1 Answers1

3

I ran into same issue. Here is something that worked for me.

import NodeVault from "node-vault";
const vault = NodeVault({
    endpoint: "https://xxxxxx.com",
    requestOptions: {
      strictSSL: false
    }
})

// this should now work without errror
const result = await vault.approleLogin({
  role_id: VAULT_ROLE_ID,
  secret_id: VAULT_SECRET_ID,
});
Shubham Prasad
  • 136
  • 1
  • 5