HASHICORP VAULT: How to read multiple items from a file and write them to Vault

Here_2_learn picture Here_2_learn · Apr 12, 2017 · Viewed 9.8k times · Source

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

Answer

Set picture Set · Apr 13, 2017

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