Commit 58aeb56
authored
vault_client: add support to 'vault kv get' for the vault_client (#642)
This commit adds support to 'vault kv get' for the 'vault_client' extension to
make the consumption of secrets from Vault K/V version 2 convenient.
There is a difference in the JSON structure of K/V version 1 (a.k.a 'generic')
and K/V version 2 responses returned when reading secrets.
Version 1
```
{
"auth": null,
"data": {
"foo": "bar",
"ttl": "1h"
},
"lease_duration": 3600,
"lease_id": "",
"renewable": false
}
```
Version 2
```
{
"data": {
"data": {
"foo": "bar"
},
"metadata": {
"created_time": "2018-03-22T02:24:06.945319214Z",
"custom_metadata": {
"owner": "jdoe",
"mission_critical": "false"
},
"deletion_time": "",
"destroyed": false,
"version": 2
}
}
}
```
Note the nested 'data.data' in version 2's response.
This difference makes the usability of 'vault read' impractical for version 2
secrets when compared to 'vault kv get'.
As 'vault kv get' knows how to unwrap the nested 'data' blocks, we can access
the values of secrets directly.
```
vault kv get -mount=<MY-MOUNT> -field=<MY-FIELD> <MY-PATH>
<MY-SECRET-VALUE>
```
However, when reading the same secret with 'vault read', we get the following
structure.
```
❯ vault read <MY-MOUNT>/data/<MY-PATH>
Key Value
--- -----
data map[<MY-FIELD>:<MY-SECRET-VALUE>]
metadata map[created_time:2025-08-06T13:23:08.155132764Z custom_metadata:<nil> deletion_time: destroyed:false version:2]
❯ vault read -field=data <MY-MOUNT>/data/<MY-PATH>
map[<MY-FIELD>:<MY-SECRET-VALUE>]
```
To be able to the the actual value of '<MY-SECRET-VALUE>' we need to parse the
output from 'vault read' and that's far from being convenient.
References:
* https://developer.hashicorp.com/vault/api-docs/secret/kv/kv-v2#sample-response-1
* https://developer.hashicorp.com/vault/api-docs/secret/kv/kv-v1#sample-response
Signed-off-by: Diogo Kiss <[email protected]>1 parent c9b1032 commit 58aeb56
3 files changed
+30
-12
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
59 | 59 | | |
60 | 60 | | |
61 | 61 | | |
62 | | - | |
| 62 | + | |
63 | 63 | | |
64 | 64 | | |
65 | 65 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2 | 2 | | |
3 | 3 | | |
4 | 4 | | |
5 | | - | |
| 5 | + | |
6 | 6 | | |
7 | | - | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
8 | 12 | | |
9 | 13 | | |
10 | 14 | | |
11 | | - | |
| 15 | + | |
12 | 16 | | |
13 | 17 | | |
14 | 18 | | |
15 | 19 | | |
16 | 20 | | |
17 | | - | |
| 21 | + | |
18 | 22 | | |
19 | 23 | | |
20 | 24 | | |
21 | | - | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
22 | 32 | | |
23 | | - | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
24 | 39 | | |
25 | 40 | | |
26 | 41 | | |
27 | | - | |
28 | | - | |
| 42 | + | |
| 43 | + | |
29 | 44 | | |
30 | | - | |
31 | | - | |
| 45 | + | |
| 46 | + | |
32 | 47 | | |
33 | | - | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
3 | 3 | | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
4 | 8 | | |
5 | 9 | | |
6 | 10 | | |
0 commit comments