-
Notifications
You must be signed in to change notification settings - Fork 781
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Unable to read Vault KVv2 secrets metadata #1396
Comments
I have a suspicion the error occurs in consul-template/dependency/vault_read.go Lines 147 to 149 in 3250aa0
consul-template/dependency/vault_common.go Lines 362 to 375 in 3250aa0
imo, the code should check specifically for existing |
I found a workaround. (and probably another bug?) This Consul template fetches metadata from Vault KV v2.
The metadata endpoint is useful for fetching available secrets versions. It allows logic like iterating through a list of versions:
The exact template doesn't work though ( |
Hey @terorie, thanks for the report. I agree with your assessment that the addPrefixToVKVPath not handling metadata is the issue. Looks like this stopped working with changes to fix issues where it mistakenly saw random 'foodata' entries as matching 'data' and not fixing their path. This broke 'metadata' as it was a good case of that bug, but there was no test asserting that. The fix needs to include both a way to recognize 'metadata' as a valid path and to be sure to add a test for it. |
Great find @terorie, this was an overlook on my part and not considering the vault usage of |
After digging into this a bit more, I noticed reading metadata was also not working in |
Thank you all so much for looking into this! @findkim I'm going to test the changes included in #1399 and report my findings. I'll also test out iterating versioned secrets with this using the aforementioned template. I might have another small bug there, but this is probably just wrong configuration on my end. |
I could confirm that #1399 fixes iterating over KVv2 secrets versions. Vault data: vault kv put secret/test_secret abc=def
vault kv get -version 1 secret/test_secret
vault kv put secret/test_secret abc=def
vault kv get -version 2 secret/test_secret Consul Template config: vault {
address = "http://localhost:8200"
token = "token"
}
template {
destination = "./version-1-test.txt"
contents = <<EOF
{{- with secret "secret/data/test_secret?version=1" -}}
{{ .Data }}
{{- end }}
EOF
}
template {
destination = "./version-iteration-test.txt"
contents = <<EOF
{{- with secret "secret/metadata/test_secret" -}}
{{- range $key, $value := .Data.versions -}}
{{- with secret (printf "secret/data/test_secret?version=%s" $key) }}
{{ .Data }}
{{- end }}
{{- end }}
{{- end }}
EOF
} Output: version-iteration-test.txt
Output: version-1-test.txt
|
Consul Template version
Vault Agent 1.4.2
Configuration
vault-k8s
annotationsGenerated Vault Agent config
Consul Template
Sanity Check Template that works
Logs
Output of sanity check template
Command
Vault Agent logs
Expected behavior
The
secret
call should be able to read Vault KV v2 metadata directly from thesecret/metadata/<path>
value.Actual behavior
It was reported that
no secret exists
when asking for metadata.This is probably due to
vault.read()
injecting path segment/data
:secret/data/metadata/<path>
.A sanity check listing the secrets in
secret/metadata
shows that the secret that we read exists (see Configuration section).Steps to reproduce
secret/metadata
endpoint referring to secret via template.The text was updated successfully, but these errors were encountered: