Search code examples
node.jsbad-requesthashicorp-vault

Bad response when writing secret using node-vault


I have started a Hashicorp Vault dev server in my local machine:

$ vault server -dev

It shows an Unseal Key and a Root Key. Then, I have executed:

$ vault auth enable app-id

And I have this code:

const rootKey = //whatever;
const unsealKey = //whatever;

var options = {
    apiVersion: 'v1',
    endpoint: 'http://127.0.0.1:8200',
    token: rootKey
};

var vault = require("node-vault")(options);
vault.unseal({ key: unsealKey })
    .then(() => {
        vault.write('secret/hello', { value: 'world' })
          .then((res) => console.log(res))
          .catch((err) => console.error(err));
    });

But I get this error response:

{ 
  statusCode: 404,
  body:
  { 
    request_id: '433b2301-1f65-63d7-f281-cf7f70f20055',
    lease_id: '',
    renewable: false,
    lease_duration: 0,
    data: null,
    wrap_info: null,
    warnings: [Array],
    auth: null 
  }
}

What am I missing?


Solution

  • With secrets/hello you are trying to access the k/v secrets backend, that might not have been enabled.

    Use one of the following commands to enable it (choose the version that you need): vault secrets enable -version=1 kv or vault secrets enable -version=2 kv