I am able to write values to Vault from a json file :
# cat secrets.json
{ "value": "bGktzwatc" }
{ "value": "AGktzwatB" }
While trying to create a new value by reading from json file, Vault is reading only the first value from the file :
# ./vault write secret/passwd1 @secrets.json
Success! Data written to: secret/passwd1
# ./vault read secret/passwd1
Key Value
--- -----
refresh_interval 768h0m0s
value bGktzwatc
Is it possible to read multiple values from a file and write to different keys through vault?
My Requirement is adding values to the multiple keys by reading from a file:
Key Value
--- -----
refresh_interval 768h0m0s
value bGktzwatc
Key Value
--- -----
refresh_interval 768h0m0s
value AGktzwatB
AFAIK, you cannot so this, as vault write
command expects key
to be specified as part of the command.
When trying > vault write @data.json
it looks like it doesn't matter what the file contains at all, as instead of wrong file format
kind of error there is the general output about available parameters for command.
Maybe it will be helpful: you can specify more than one value for specific key:
# cat secrets.json
{ "value1": "bGktzwatc", "value2": "AGktzwatB" }
then key will contains
Key Value
--- -----
refresh_interval 768h0m0s
value1 bGktzwatc
value2 AGktzwatB
If you are copying data from one key to another key via a file, this approach works for me:
vault read -format=json secret/mykey1 > file.json
cat file.json | jq '.data' | vault write secret/mykey2 -
Note the use of jq
to bring the "data"
sub-element to the top level first.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With