Hashicorp Vault 读取凭证 - 无法找到名称为 db_name 的连接条目

the*_*uke 3 hashicorp-vault

我不知道我是否做错了什么。

但这是我的配置。

// payload.json
{
  "plugin_name": "postgresql-database-plugin",
  "allowed_roles": "*",
  "connection_url": "postgresql://{{username}}:{{password}}@for-testing-vault.rds.amazonaws.com:5432/test-app",
  "username": "test",
  "password": "testtest"
}
Run Code Online (Sandbox Code Playgroud)

然后运行这个命令:

curl --header "X-Vault-Token: ..." --request POST --data @payload.json http://ip_add.us-west-1.compute.amazonaws.com:8200/v1/database/config/postgresql
Run Code Online (Sandbox Code Playgroud)

角色配置:

// readonlypayload.json
{
  "db_name": "test-app",
  "creation_statements": ["CREATE ROLE \"{{name}}\" WITH LOGIN PASSWORD '{{password}}' VALID UNTIL '{{expiration}}';
   GRANT SELECT ON ALL TABLES IN SCHEMA public TO \"{{name}}\";"],
  "default_ttl": "1h",
  "max_ttl": "24h"
}
Run Code Online (Sandbox Code Playgroud)

然后运行这个命令:

curl --header "X-Vault-Token: ..." --request POST --data @readonlypayload.json http://ip_add.us-west-1.compute.amazonaws.com:8200/v1/database/roles/readonly
Run Code Online (Sandbox Code Playgroud)

然后创建了一个策略:

path "database/creds/readonly" {
  capabilities = [ "read" ]
}

path "/sys/leases/renew" {
  capabilities = [ "update" ]
}
Run Code Online (Sandbox Code Playgroud)

并运行它以获取令牌:

curl --header "X-Vault-Token: ..." --request POST --data '{"policies": ["db_creds"]}' http://ip_add.us-west-1.compute.amazonaws.com:8200/v1/auth/token/create | jq
Run Code Online (Sandbox Code Playgroud)

执行此命令以获取值:

VAULT_TOKEN=... consul-template.exe -template="config.yml.tpl:config.yml" -vault-addr "http://ip_add.us-west-1.compute.amazonaws.com:8200" -log-level debug
Run Code Online (Sandbox Code Playgroud)

然后我收到此错误:

URL: GET http://ip_add.us-west-1.compute.amazonaws.com:8200/v1/database/creds/readonly
Code: 500. Errors:

* 1 error occurred:
        * failed to find entry for connection with name: "test-app"
Run Code Online (Sandbox Code Playgroud)

任何建议将不胜感激,谢谢!

编辑:也在服务器上尝试过这个命令 vault read database/creds/readonly

还在回来

* 1 error occurred:
        * failed to find entry for connection with name: "test-app"
Run Code Online (Sandbox Code Playgroud)

Exc*_*bur 10

对于通过谷歌搜索此错误消息来到此页面的人,这可能会有所帮助:

不幸的是,Vault 数据库/角色的参数db_name有点误导。该值需要匹配一个database/config/条目,而不是一个实际的数据库名称本身。GRANT 语句本身是数据库名称相关的地方,db_name它只是对配置名称的引用,它可能与数据库名称匹配,也可能不匹配。(在我的情况下,配置有其他数据,例如环境前缀数据库名称。)