2018-04-04 06:22:41 +00:00
|
|
|
---
|
2020-01-18 00:18:09 +00:00
|
|
|
layout: docs
|
|
|
|
page_title: KV - Secrets Engines
|
|
|
|
description: The KV secrets engine can store arbitrary secrets.
|
2018-04-04 06:22:41 +00:00
|
|
|
---
|
|
|
|
|
2018-04-09 16:39:32 +00:00
|
|
|
# KV Secrets Engine - Version 1
|
2018-04-04 06:22:41 +00:00
|
|
|
|
|
|
|
The `kv` secrets engine is used to store arbitrary secrets within the
|
|
|
|
configured physical storage for Vault.
|
|
|
|
|
|
|
|
Writing to a key in the `kv` backend will replace the old value; sub-fields are
|
|
|
|
not merged together.
|
|
|
|
|
|
|
|
Key names must always be strings. If you write non-string values directly via
|
|
|
|
the CLI, they will be converted into strings. However, you can preserve
|
|
|
|
non-string values by writing the key/value pairs to Vault from a JSON file or
|
2018-08-15 17:57:36 +00:00
|
|
|
using the HTTP API.
|
2018-04-04 06:22:41 +00:00
|
|
|
|
|
|
|
This secrets engine honors the distinction between the `create` and `update`
|
|
|
|
capabilities inside ACL policies.
|
|
|
|
|
|
|
|
~> **Note**: Path and key names are _not_ obfuscated or encrypted; only the
|
|
|
|
values set on keys are. You should not store sensitive information as part of a
|
|
|
|
secret's path.
|
|
|
|
|
|
|
|
## Setup
|
|
|
|
|
2018-04-09 16:39:32 +00:00
|
|
|
To enable a version 1 kv store:
|
2018-04-04 06:22:41 +00:00
|
|
|
|
|
|
|
```
|
2018-04-09 16:39:32 +00:00
|
|
|
vault secrets enable -version=1 kv
|
2018-04-04 06:22:41 +00:00
|
|
|
```
|
|
|
|
|
|
|
|
## Usage
|
|
|
|
|
|
|
|
After the secrets engine is configured and a user/machine has a Vault token with
|
|
|
|
the proper permission, it can generate credentials. The `kv` secrets engine
|
|
|
|
allows for writing keys with arbitrary values.
|
|
|
|
|
|
|
|
1. Write arbitrary data:
|
|
|
|
|
2020-01-18 00:18:09 +00:00
|
|
|
```text
|
|
|
|
$ vault kv put kv/my-secret my-value=s3cr3t
|
|
|
|
Success! Data written to: kv/my-secret
|
|
|
|
```
|
2018-04-04 06:22:41 +00:00
|
|
|
|
|
|
|
1. Read arbitrary data:
|
|
|
|
|
2020-01-18 00:18:09 +00:00
|
|
|
```text
|
|
|
|
$ vault kv get kv/my-secret
|
|
|
|
Key Value
|
|
|
|
--- -----
|
|
|
|
my-value s3cr3t
|
|
|
|
```
|
2018-04-04 06:22:41 +00:00
|
|
|
|
|
|
|
1. List the keys:
|
|
|
|
|
2020-01-18 00:18:09 +00:00
|
|
|
```text
|
|
|
|
$ vault kv list kv/
|
|
|
|
Keys
|
|
|
|
----
|
|
|
|
my-secret
|
|
|
|
```
|
2018-04-04 06:22:41 +00:00
|
|
|
|
|
|
|
1. Delete a key:
|
|
|
|
|
2020-01-18 00:18:09 +00:00
|
|
|
```
|
|
|
|
$ vault kv delete kv/my-secret
|
|
|
|
Success! Data deleted (if it existed) at: kv/my-secret
|
|
|
|
```
|
2018-04-04 06:22:41 +00:00
|
|
|
|
|
|
|
## TTLs
|
|
|
|
|
|
|
|
Unlike other secrets engines, the KV secrets engine does not enforce TTLs
|
|
|
|
for expiration. Instead, the `lease_duration` is a hint for how often consumers
|
2019-02-07 02:51:08 +00:00
|
|
|
should check back for a new value.
|
2018-04-04 06:22:41 +00:00
|
|
|
|
|
|
|
If provided a key of `ttl`, the KV secrets engine will utilize this value
|
|
|
|
as the lease duration:
|
|
|
|
|
2020-05-21 17:18:17 +00:00
|
|
|
```shell-session
|
2018-04-04 06:22:41 +00:00
|
|
|
$ vault kv put kv/my-secret ttl=30m my-value=s3cr3t
|
|
|
|
Success! Data written to: kv/my-secret
|
|
|
|
```
|
|
|
|
|
2018-08-15 17:57:36 +00:00
|
|
|
Even with a `ttl` set, the secrets engine _never_ removes data on its own. The
|
2018-04-04 06:22:41 +00:00
|
|
|
`ttl` key is merely advisory.
|
|
|
|
|
|
|
|
When reading a value with a `ttl`, both the `ttl` key _and_ the refresh interval
|
|
|
|
will reflect the value:
|
|
|
|
|
2020-05-21 17:18:17 +00:00
|
|
|
```shell-session
|
2018-04-04 06:22:41 +00:00
|
|
|
$ vault kv get kv/my-secret
|
|
|
|
Key Value
|
|
|
|
--- -----
|
|
|
|
my-value s3cr3t
|
|
|
|
ttl 30m
|
|
|
|
```
|
|
|
|
|
2022-04-04 17:05:16 +00:00
|
|
|
## Tutorial
|
2019-10-14 17:31:03 +00:00
|
|
|
|
|
|
|
Refer to the [Static Secrets: Key/Value Secrets
|
|
|
|
Engine](https://learn.hashicorp.com/vault/secrets-management/sm-static-secrets)
|
2022-04-04 17:05:16 +00:00
|
|
|
tutorial to learn how to set up a uniform workflow to securely store sensitive information.
|
2019-10-14 17:31:03 +00:00
|
|
|
|
2018-04-04 06:22:41 +00:00
|
|
|
## API
|
|
|
|
|
|
|
|
The KV secrets engine has a full HTTP API. Please see the
|
2022-03-18 01:14:48 +00:00
|
|
|
[KV secrets engine API](/api-docs/secret/kv/kv-v1) for more
|
2018-04-04 06:22:41 +00:00
|
|
|
details.
|