> ## Documentation Index
> Fetch the complete documentation index at: https://notes.kodekloud.com/llms.txt
> Use this file to discover all available pages before exploring further.

# KeyValue Secrets Engine

> This guide explores the Key/Value Secrets Engine in Vault, focusing on storing static secrets and managing them effectively.

In this guide, we’ll explore the Key/Value (KV) Secrets Engine in Vault, focusing on what Operations Professionals need to know. The KV Secrets Engine is ideal for storing **static secrets**—such as service-account passwords or API keys—that are generated outside Vault. While Vault also offers powerful dynamic credentials, static secrets remain ubiquitous in many environments.

Vault supports two flavors of the KV Secrets Engine:

* **Version 1**: A simple, non-versioned store.
* **Version 2**: A fully versioned store, tracking metadata (creation time, version number, deletion status, etc.).

Secrets can be accessed via the UI, CLI, or API. Access control is enforced by Vault policies that grant specific capabilities (`create`, `read`, `update`, `delete`) on defined paths. All data at rest is encrypted using AES-256. You can mount multiple KV engines at unique paths to isolate workloads.

<Frame>
  ![The image is a slide about the Key/Value Secrets Engine, explaining how it can be enabled at different paths, stores secrets as key-value pairs, and requires specific capabilities for writing and updating secrets.](https://kodekloud.com/kk-media/image/upload/v1752878473/notes-assets/images/HashiCorp-Certified-Vault-Operations-Professional-2022-KeyValue-Secrets-Engine/key-value-secrets-engine-slide.jpg)
</Frame>

***

## How to Store Secrets as Key/Value Pairs

To write secrets, choose a mount path and supply your key/value pairs. For example, after enabling the KV engine at `secret/`:

```bash theme={null}
vault write secret/applications/web01 \
  user=dbadmin \
  password=P@ssw0rd \
  api=b93md83mdmapw
```

* **create** capability is required when writing to a new path.
* **update** capability is required for overwriting an existing secret.

<Callout icon="lightbulb" color="#1CB2FE">
  Ensure your Vault policies explicitly grant `create` and `update` permissions on the exact path (e.g., `secret/applications/web01`) or via wildcards (e.g., `secret/applications/*`).
</Callout>

***

## Organizing a KV Engine Hierarchy

Suppose you mount a KV engine at `apps/`. You can structure environments like this:

* `apps/AWS/prod` – Production credentials
* `apps/AWS/dev`  – Development certificates

Example writes:

```bash theme={null}
vault write apps/AWS/prod \
  user=dbadmin \
  password=P@ssw0rd \
  api=b93md83mdmapw

vault write apps/AWS/dev \
  cert='---BEGIN CERTI...' \
  key='---BEGIN PRIVA...'
```

You can also manage KV engines via the CLI.

***

## Enabling and Listing KV Version 1

```bash theme={null}
# Enable a KV v1 engine at the default path kv/
vault secrets enable kv

# Enable a KV v1 engine at a custom path hcvop/
vault secrets enable -path=hcvop kv

# List all secrets engines with detailed info
vault secrets list --detailed
```

| Path       | Plugin    | Accessor      | Options |
| ---------- | --------- | ------------- | ------- |
| cubbyhole/ | cubbyhole | cubbyhole\_\* | map\[]  |
| kv/        | kv        | kv\_\*        | map\[]  |
| hcvop/     | kv        | kv\_\*        | map\[]  |

<Callout icon="lightbulb" color="#1CB2FE">
  An empty `map[]` under **Options** indicates a KV v1 store.
</Callout>

***

## Enabling and Listing KV Version 2

You can enable KV v2 with either shorthand or an explicit version flag.

Method 1 (shorthand):

```bash theme={null}
vault secrets enable kv-v2
```

Method 2 (explicit):

```bash theme={null}
vault secrets enable -path=training -version=2 kv
```

Re-run the listing:

```bash theme={null}
vault secrets list --detailed
```

| Path       | Plugin    | Accessor      | Options         |
| ---------- | --------- | ------------- | --------------- |
| cubbyhole/ | cubbyhole | cubbyhole\_\* | map\[]          |
| kv-v2/     | kv        | kv\_\*        | map\[version:2] |
| training/  | kv        | kv\_\*        | map\[version:2] |

<Callout icon="lightbulb" color="#1CB2FE">
  The `map[version:2]` entry marks a KV v2 store.
</Callout>

***

## Upgrading a KV v1 Engine to v2

You can convert an existing KV v1 mount to version 2. Be aware this action is **irreversible** without restoring from backup.

<Callout icon="triangle-alert" color="#FF6B6B">
  Upgrading to KV v2 cannot be undone. Ensure you have a backup of your Vault data before proceeding.
</Callout>

```bash theme={null}
vault kv enable-versioning training/
# Success! Tuned the secrets engine at: training/
```

***

## Understanding KV v2 Metadata and Path Prefixes

KV v2 tracks detailed metadata (creation date, version, deletion status, custom fields) for every secret. To support versioning, KV v2 introduces two API path prefixes:

* **data/** – Stores the secret data
* **metadata/** – Stores the versioning metadata

<Frame>
  ![The image explains how KV V2 is different by adding metadata to key-value entries for versioning, introducing two prefixes: "cloud/data" for storing actual data and "cloud/metadata" for storing metadata about a secret. It also features a Vault certification badge and a cartoon character.](https://kodekloud.com/kk-media/image/upload/v1752878474/notes-assets/images/HashiCorp-Certified-Vault-Operations-Professional-2022-KeyValue-Secrets-Engine/kv-v2-metadata-versioning-diagram.jpg)
</Frame>

For a KV v2 engine mounted at `cloud/` with a secret path `apps/AWS/network`:

* Data path: `cloud/data/apps/AWS/network`
* Metadata path: `cloud/metadata/apps/AWS/network`

<Frame>
  ![The image explains the structure of KV V2, showing a hierarchy of paths for storing secrets in a cloud environment, with a specific path format and a "data/" prefix for reading secrets. It also features a Vault certification badge and a cartoon character.](https://kodekloud.com/kk-media/image/upload/v1752878475/notes-assets/images/HashiCorp-Certified-Vault-Operations-Professional-2022-KeyValue-Secrets-Engine/kv-v2-structure-secrets-cloud-diagram.jpg)
</Frame>

When working with the API or writing policies, you must include the `data/` and `metadata/` prefixes. The `vault kv` CLI commands automatically handle these prefixes for you:

<Frame>
  ![The image provides information about KV V2, highlighting that the data/ and metadata/ prefixes are required for API and Vault policies, but it does not change CLI interactions. It also features a Vault certification badge and a cartoon character.](https://kodekloud.com/kk-media/image/upload/v1752878477/notes-assets/images/HashiCorp-Certified-Vault-Operations-Professional-2022-KeyValue-Secrets-Engine/kv-v2-api-metadata-cli-interactions.jpg)
</Frame>

***

## Next Steps

You’re now ready to get hands-on with KV v1 and KV v2 in Vault. Practice writing policies, making API calls, and exploring the versioning features to master static secret management.

## Links and References

* [Vault KV Secrets Engine Documentation](https://www.vaultproject.io/docs/secrets/kv)
* [Vault Policies Guide](https://www.vaultproject.io/docs/concepts/policies)
* [Vault CLI Documentation](https://www.vaultproject.io/docs/commands)

<CardGroup>
  <Card title="Watch Video" icon="video" cta="Learn more" href="https://learn.kodekloud.com/user/courses/hashicorp-certified-vault-operations-professional-2022/module/b59936f2-3ed0-4ec2-b1fd-971dcce5c2ca/lesson/d1ee3cbb-649f-4986-83e6-d5acbbb94658" />
</CardGroup>
