node-vault icon indicating copy to clipboard operation
node-vault copied to clipboard

Reading a versioned K/V secrets

Open ChamNouki opened this issue 5 years ago • 2 comments

Here is what i try to do :

const vaultOptions: VaultOptions = {
  requestOptions: {
    headers: {
      'X-Vault-Namespace': process.env.VAULT_NAMESPACE
    }
  }
};

const vault = Vault(vaultOptions);

vault.read('secret/my/secret');

(Endpoint, token and namespace are set from environment variables.)

When the vault client try to request the key I get the following error :

ApiResponseError: Status 404
    at handleVaultResponse ([...]/node_modules/node-vault/src/index.js:49:21)
    at processTicksAndRejections (internal/process/task_queues.js:97:5) {
  response: {
    statusCode: 404,
    body: {
      request_id: 'd81f2ed4-222b-10de-abd2-b2f8c782d599',
      lease_id: '',
      renewable: false,
      lease_duration: 0,
      data: null,
      wrap_info: null,
      warnings: [Array],
      auth: null
    }
  }
}

Here is the full error object stringified :

{ 
  "response":{ 
    "statusCode":404,
    "body":{ 
      "request_id":"d81f2ed4-222b-10de-abd2-b2f8c782d599",
      "lease_id":"",
      "renewable":false,
      "lease_duration":0,
      "data":null,
      "wrap_info":null,
      "warnings":[ 
        "Invalid path for a versioned K/V secrets engine. See the API docs for the appropriate API endpoints to use. If using the Vault CLI, use 'vault kv get' for this operation."
      ],
      "auth":null
    }
  }
}

Any idea of what I can do to solve this ?

ChamNouki avatar Feb 12 '20 19:02 ChamNouki

seems to be a duplicate of #82

ChamNouki avatar Feb 12 '20 19:02 ChamNouki

Looks like you're running in to the same issue as #148.

Per my comment...

I had to solve the same problem for my VisualStudio Code extension (which uses this library). My solution was to simply adapt the node-vault client as necessary based on the metadata associated with engine mount points.

Example Implementation

owenfarrell avatar Jun 19 '20 01:06 owenfarrell

Dupe of #82; Closing :_)

aviadhahami avatar Nov 10 '22 16:11 aviadhahami