使用 consul-template 从 vault 读取机密

Reading secrets with consul-template from vault

我在 pod 中有保险库 运行。 我可以使用 vault read 读取机密。

$ vault read test
Key                 Value
---                 -----
refresh_interval    768h
value               world

$ vault kv get test
==== Data ====
Key      Value
---      -----
value    world

我可以使用两个版本的 Api 来查看保险库中的秘密

当我列出金库秘密引擎时,我清楚地看到它们:

$ vault secrets list
Path                   Type         Description
----                   ----         -----------
secret/                kv           key/value secret storage
test/                  kv           n/a

在我的 Consul-template 模板中,我有以下

[default]
{{ with secret "test"}}
{{ if .Data.value }}
consul_template_value = {{ .Data.value }}
{{ end }}
{{ end }}

我的 consul-template 是一个 sidecar pod,它读取上面的文件并返回当前错误:

watcher reported error: vault.read(test): no secret exists at test
[ERR] (cli) vault.read(test): no secret exists at test

我在 consul-template sidecar 上打开了跟踪

[TRACE] (view) vault.read(test) starting fetch
[TRACE] vault.read(test2): GET /v1/test?stale=true&wait=1m0s
[WARN] (view) vault.read(test): no secret exists at test (retry attempt 1 after "250ms")

我用 curl

检查了 Vault API
curl -k -H "X-Vault-Token: TOKEN" -X GET https://X.X.X.X/v1/test?stale=true

我收到回复

{
"request_id":"aa947343-723a-45fc-cdee-7394c3074a4c",
"lease_id":"",
"renewable":false,
"lease_duration":2764800,
"data":{
    "value":"word"
    },
"wrap_info":null,
"warnings":null,
"auth":null
}

我在 github https://github.com/hashicorp/consul-template/issues/341

上发现了类似的问题

任何想法都会有帮助

已解决,我遗漏了 CT 的一些配置方面