Uploading multiple key/value pairs using a file

3,713 views
Skip to first unread message

Synaesthete

unread,
Sep 28, 2016, 4:09:59 PM9/28/16
to Vault
Is there a means of uploading several key/value pairs from a file? I can upload a single value like this:

vault write secret/passwords/my_password value=@file.json

Where the contents of the file are something like:

{ "value":"ABCD123"}

How can I write several key/values using a file like this:

{ { "my_password": { "value": "ABCD123" }, "your_password": { "value": "EFGH456" } }

If I use the following:

vault write secret/passwords @file.json

It sets the value of secret/passwords to a list of several maps, but these aren't the same datatype as most key/value pairs stored normally by Vault when setting a single key/value.

Vishal Nayak

unread,
Sep 28, 2016, 4:16:16 PM9/28/16
to vault...@googlegroups.com
Hi Synaesthete,

Any valid JSON can be stored. The sample you mentioned, has an extra
open curly bracket at the beginning.

Regards,
Vishal
> --
> This mailing list is governed under the HashiCorp Community Guidelines -
> https://www.hashicorp.com/community-guidelines.html. Behavior in violation
> of those guidelines may result in your removal from this mailing list.
>
> GitHub Issues: https://github.com/hashicorp/vault/issues
> IRC: #vault-tool on Freenode
> ---
> You received this message because you are subscribed to the Google Groups
> "Vault" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to vault-tool+...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/vault-tool/b3c8141f-5601-410a-a7e9-f3295fa48a31%40googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.



--
vn

Synaesthete

unread,
Sep 28, 2016, 4:22:16 PM9/28/16
to Vault
Whoops, typed that too hastily, this is a more indicative JSON file:

{ "my_password": { "value": "ABCD123" }, "your_password": { "value": "EFGH456" } }

But writing this file as I mentioned above is not quite the same as doing it like this:

$ vault write secret/passwords/my_password value=ABCD123
$ vault write secret/passwords/your_password value=EFGH456

Where in the former case, the value of "secret/passwords" is a set of maps and in the latter "secret/passwords" is just the path to several individual key/value pairs.

Vishal Nayak

unread,
Sep 28, 2016, 4:38:16 PM9/28/16
to vault...@googlegroups.com
Hi Synaesthete,

Vault doesn't populate different paths based on the input received by one path.

Regarding the datatype, it is the JSON decoder doing its job. It tries
to return the values in the same datatype which was used to write the
data.

In order to store a series of key value pairs at once, the following
can be used:

file.json:
{
"my_password": "ABCD123",
"your_password": "value"
}
vault write secret/file @file.json
vault read secret/file

Use `vault read -format=json secret/file` to see the JSON response.

Hope this helps!

Regards,
Vishal
> https://groups.google.com/d/msgid/vault-tool/8d6acee3-c63c-444b-8112-47faad318674%40googlegroups.com.
Message has been deleted

Synaesthete

unread,
Sep 28, 2016, 4:45:39 PM9/28/16
to Vault
So if I do that but then try something like:

vault read secret/file/my_password

I get

No value found at secret/file/my_password

Basically I just want to batch in a bunch of key/value pairs. Is there a means of doing this in Vault natively or will I need to write a routine that traverses the JSON and runs several `vault write` commands?

Vishal Nayak

unread,
Sep 28, 2016, 4:49:42 PM9/28/16
to vault...@googlegroups.com
Hi Synaesthete,

Input provided to one path belongs to just that. There is currently no
way to supply a bunch of key value pairs and expect paths to be
populated for each key present in the input.

Regards,
Vishal
> https://groups.google.com/d/msgid/vault-tool/d2440aa6-6f9c-4d4d-83ae-bbf1b7550cba%40googlegroups.com.

prachi.d...@lafargeholcim.com

unread,
Jun 13, 2018, 4:00:04 AM6/13/18
to Vault


How to insert multiple values corresponding to single key in drive properties(app script).
Reply all
Reply to author
Forward
0 new messages