node.js - 使用 node-vault 访问 HashiCorp Vault KV key

标签 node.js hashicorp-vault

我正在尝试使用“node-vault”访问 HashiCorp Vault KV,但不断收到“statusCode: 404”

我正在关注 Node 保险库的示例
https://github.com/kr1sp1n/node-vault

1)我在 Windows 10 上运行 vault_1.1.3_windows_amd64,在 PowerShell 上使用“vault server -dev”。

2)然后在另一个PowerShell上运行以下;

$env:VAULT_ADDR="http://127.0.0.1:8200"
vault secrets enable -version=1 kv
vault status
Key             Value
---             -----
Seal Type       shamir
Initialized     true
Sealed          false
Total Shares    1
Threshold       1
Version         1.1.3
Cluster Name    vault-cluster-28a041c6
Cluster ID      0ec85d70-8e87-dff6-347f-b1959fad8b44
HA Enabled      false

3)然后运行以下代码
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));
    });

vault.write('secret/hello', { value: 'world', lease: '1s' })
    .then( () => vault.read('secret/hello'))
    .then( () => vault.delete('secret/hello'))
    .catch(console.error);

这返回一个状态 404,还需要做什么来避免 404?
{ Error: Status 404
    at handleVaultResponse (XX\TestCodes\Node-VaultTest\node_modules\node-vault\src\index.js:49:21)
    at process._tickCallback (internal/process/next_tick.js:68:7)
  response:
   { statusCode: 404,
     body:
      { request_id: '2992e6c2-5146-6569-1f48-55f75da88993',
        lease_id: '',
        renewable: false,
        lease_duration: 0,
        data: null,
        wrap_info: null,
        warnings: [Array],
        auth: null } } }
{ Error: Status 404
    at handleVaultResponse (XX\TestCodes\Node-VaultTest\node_modules\node-vault\src\index.js:49:21)
    at process._tickCallback (internal/process/next_tick.js:68:7)
  response:
   { statusCode: 404,
     body:
      { request_id: '2f280fa4-6596-c06f-2168-091246e0a2a1',
        lease_id: '',
        renewable: false,
        lease_duration: 0,
        data: null,
        wrap_info: null,
        warnings: [Array],
        auth: null } } }

最佳答案

您将 kv 存储安装为版本 1。 node-vault 用于从版本 2 的 kv 存储读取 secret 的实际路径不同,并且与 Vault 的 v1 kv 存储不兼容。
使用 -version 2 安装您的 kv 存储.如果未指定,则默认为 v1。

关于node.js - 使用 node-vault 访问 HashiCorp Vault KV key ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57026790/

相关文章:

javascript - 在Electron JS中无法使用 Remote 关闭窗口

node.js - 用于nodejs的碳、硼、氩是什么?

node.js - Node js,%1 不是有效的 Win32 应用程序,js-bson : failed to load c++ bson extension, windows

ssl - 由于 LB 运行状况检查,Vault 节点中的连续 TLS 握手错误日志

kubernetes - 在 Kubernetes 中,将文件中的 secret 公开为环境变量

hashicorp-vault - 保险库 : how to create an secret-id

mysql - SQL 和 Node : How can I run three different query and return the result one by one

node.js - React.js 渲染完成后运行客户端 JS

go - 在 golang 上使用 Vault 客户端

kubernetes - Kubernetes 上的 CA 证书和 JWT token