Skip to content

Commit 716e206

Browse files
authored
Merge pull request #2016 from sofixa/add_vault_kv_subkeys
support Vault KV subkeys to avoid consul-template adding /data/ to the path
2 parents 134b935 + a513d0c commit 716e206

File tree

2 files changed

+18
-3
lines changed

2 files changed

+18
-3
lines changed

dependency/vault_read.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -212,9 +212,9 @@ func shimKVv2Path(rawPath, mountPath, clientNamespace string) string {
212212
// Trim (mount path - client namespace) from the raw path
213213
p := strings.TrimPrefix(rawPath, rawPathNsAndMountPath)
214214

215-
// Only add /data/ prefix to the path if neither /data/ or /metadata/ are
215+
// Only add /data/ prefix to the path if neither /data/, or /metadata/ or /subkeys/ are
216216
// present.
217-
if strings.HasPrefix(p, "data/") || strings.HasPrefix(p, "metadata/") {
217+
if strings.HasPrefix(p, "data/") || strings.HasPrefix(p, "metadata/") || strings.HasPrefix(p, "subkeys/") {
218218
return rawPath
219219
}
220220

dependency/vault_read_test.go

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -706,7 +706,22 @@ func TestShimKVv2Path(t *testing.T) {
706706
"secret/",
707707
"secret/data/foometadata/foo/bar",
708708
"",
709-
}, {
709+
},
710+
{
711+
"prefix not added to subkeys",
712+
"secret/subkeys/foo",
713+
"secret/",
714+
"secret/subkeys/foo",
715+
"",
716+
},
717+
{
718+
"prefix added with subkeys* in subpath",
719+
"secret/subkeysfoo/foo/bar",
720+
"secret/",
721+
"secret/data/subkeysfoo/foo/bar",
722+
"",
723+
},
724+
{
710725
"prefix added to mount path",
711726
"secret/",
712727
"secret/",

0 commit comments

Comments
 (0)