mirror of
https://github.com/hashicorp/vault.git
synced 2025-11-24 04:01:37 +01:00
* clarify subkey read in GUI * add screenshots * add to index * update kv nav steps * update alt text for screenshot * update steps * edits * fix build error and simplify path structure * fix paths * missed one * missed another one >_< * Update website/content/docs/secrets/kv/kv-v2/cookbook/write-data.mdx --------- Co-authored-by: Sarah Chavis <62406755+schavis@users.noreply.github.com>
159 lines
3.5 KiB
Plaintext
159 lines
3.5 KiB
Plaintext
---
|
|
layout: docs
|
|
page_title: Write new data
|
|
description: >-
|
|
Write new versioned data to the kv v2 plugin
|
|
---
|
|
|
|
# Write new key/value data
|
|
|
|
Write new versions of data to a new or existing data path in the `kv` v2 plugin.
|
|
|
|
<Tip title="Assumptions">
|
|
|
|
- You have [set up a `kv` v2 plugin](/vault/docs/secrets/kv/kv-v2/setup).
|
|
- Your authentication token has `create` and `update` permissions for the `kv`
|
|
v2 plugin.
|
|
|
|
</Tip>
|
|
|
|
<Tabs>
|
|
|
|
<Tab heading="CLI" group="cli">
|
|
|
|
<Note>
|
|
|
|
The Vault CLI forcibly converts `kv` keys and values data to strings before
|
|
writing data. To preserve non-string data, write your key/value pairs to Vault
|
|
from a JSON file or use the plugin API.
|
|
|
|
</Note>
|
|
|
|
Use [`vault kv put`](/vault/docs/command/kv/put) to save a new version of
|
|
key/value data to an new or existing secret path:
|
|
|
|
```shell-session
|
|
$ vault kv put \
|
|
-mount <mount_path> \
|
|
<secret_path> \
|
|
<list_of_kv_values>
|
|
```
|
|
|
|
For example:
|
|
|
|
<CodeBlockConfig hideClipboard="true">
|
|
|
|
```shell-session
|
|
$ vault kv put \
|
|
-mount shared \
|
|
dev/square-api \
|
|
sandbox=1234 prod=5679 smoke=abcd
|
|
|
|
======= Secret Path =======
|
|
shared/data/dev/square-api
|
|
|
|
======= Metadata =======
|
|
Key Value
|
|
--- -----
|
|
created_time 2024-11-15T01:52:23.434633061Z
|
|
custom_metadata <nil>
|
|
deletion_time n/a
|
|
destroyed false
|
|
version 5
|
|
```
|
|
|
|
</CodeBlockConfig>
|
|
|
|
</Tab>
|
|
|
|
<Tab heading="GUI" group="gui">
|
|
|
|
The Vault GUI forcibly converts non-string keys to strings before writing data.
|
|
To preserve non-string values, use the JSON toggle to write your key/value data
|
|
as JSON.
|
|
|
|
@include 'gui-instructions/plugins/kv/open-overview.mdx'
|
|
|
|
- Click **Create new +** from one of the following tabs:
|
|
- **Overview** tab: in the "Current version" card.
|
|
- **Secret** tab: in the toolbar.
|
|
- Set a new key name and value.
|
|
- Use the **Add** button to set additional key/value pairs.
|
|
- Click **Save** to write the new version data.
|
|
|
|

|
|
|
|
</Tab>
|
|
|
|
<Tab heading="API" group="api">
|
|
|
|
1. Create a JSON file with the key/value data you want to write to Vault. Use
|
|
the `options` field to set optional flags and `data` to define the key/value
|
|
pairs.
|
|
|
|
1. Make a `POST` call to
|
|
[`/{plugin_mount_path}/data/{secret_path}`](/vault/api-docs/secret/kv/kv-v2#create-update-secret)
|
|
with the JSON data:
|
|
```shell-session
|
|
$ curl \
|
|
--request POST \
|
|
--header "X-Vault-Token: ${VAULT_TOKEN}" \
|
|
--data @data.json \
|
|
${VAULT_ADDR}/v1/<plugin_mount_path>/data/<secret_path>
|
|
```
|
|
|
|
|
|
For example:
|
|
|
|
|
|
<CodeBlockConfig hideClipboard="true">
|
|
|
|
```json
|
|
{
|
|
"options": {
|
|
"cas": 4
|
|
},
|
|
"data": {
|
|
"sandbox": "1234",
|
|
"prod": "5679",
|
|
"smoke": "abcd"
|
|
}
|
|
}
|
|
```
|
|
|
|
</CodeBlockConfig>
|
|
|
|
<CodeBlockConfig hideClipboard="true">
|
|
|
|
```shell-session
|
|
$ curl \
|
|
--request POST \
|
|
--header "X-Vault-Token: ${VAULT_TOKEN}" \
|
|
--data @data.json \
|
|
${VAULT_ADDR}/v1/shared/data/dev/square-api | jq
|
|
|
|
{
|
|
"request_id": "0c872d86-0def-4261-34d9-b796039ec02f",
|
|
"lease_id": "",
|
|
"renewable": false,
|
|
"lease_duration": 0,
|
|
"data": {
|
|
"created_time": "2024-11-15T02:41:02.556301319Z",
|
|
"custom_metadata": null,
|
|
"deletion_time": "",
|
|
"destroyed": false,
|
|
"version": 5
|
|
},
|
|
"wrap_info": null,
|
|
"warnings": null,
|
|
"auth": null,
|
|
"mount_type": "kv"
|
|
}
|
|
```
|
|
|
|
</CodeBlockConfig>
|
|
|
|
</Tab>
|
|
|
|
</Tabs>
|