Skip to main content
In this guide, we’ll dive into HashiCorp Vault’s Key/Value (KV) Secrets Engine Version 2. You’ll learn how to:
  • List and inspect enabled secrets engines
  • Upgrade a KV v1 mount to KV v2
  • Enable a brand-new KV v2 engine
  • Write, read, and version secrets
  • Perform soft deletes (undelete) and hard deletes (destroy)
  • Manage metadata and custom metadata
  • Configure KV v2 prefixes in ACL policies
  • Interact with KV v2 via the HTTP API
We’ll cover both the CLI and the Vault web UI to give you a complete picture of versioned secret management.

1. List Existing Secrets Engines

First, verify which engines are enabled:
Example output:
By default, the training/ mount is KV v1. See Vault CLI documentation for more on the vault secrets list command.

2. Upgrade an Existing KV v1 Mount to KV v2

To enable versioning on the existing training/ mount:
  1. Inspect the mount in detail:
  2. Enable versioning:
  3. Confirm the mount now uses KV v2:
You should see options: {version: 2} for the training/ path.
Upgrading to v2 is non-destructive. All existing KV v1 data remains accessible under the new KV v2 mount.

3. Enable a New KV v2 Engine

To create a fresh KV v2 mount at kvv2/:
Verify:
Look for kvv2/ with type: kv and options: {version: 2}.

4. Writing and Reading Versioned Secrets

4.1 Write a Secret

Output example:
The CLI automatically prepends /data/ when writing, so you only specify kvv2/apps/circleci.

4.2 Read the Latest Version


5. Versioning Secrets

Update to create version 2:
Retrieve specific versions:

6. Soft Delete and Undelete

6.1 Soft Delete

Now, vault kv get kvv2/apps/circleci shows metadata without data.

6.2 Undelete

Version 2 is restored and data is visible again.

7. Hard Delete (Destroy)

Permanently remove version 1:
Reading that version now shows destroyed = true; it cannot be undeleted.
Destroying versions is irreversible. Always ensure you have backups or retention policies if you need historic data.

8. Metadata Operations

8.1 View All Metadata

You’ll see:
  • cas_required
  • current_version
  • max_versions
  • Per-version status (created, deleted, destroyed)

8.2 Add Custom Metadata

Reading the secret shows your custom key-value pairs under Metadata.

9. JSON Output and Filtering

Fetch JSON and parse with jq:
This is useful for automation and CI pipelines.

10. Cleanup: Delete All Metadata

To remove both data and metadata for a secret path:
Running vault kv list kvv2/apps now returns nothing.

11. KV v2 Prefixes in ACL Policies

When you write ACL policies for KV v2, include both data/ and metadata/ paths:

12. Managing Secrets via the Web UI

Vault’s UI offers point-and-click management for KV v2 secrets: Browse secrets and create a new entry
Click Secrets > kvv2 and select Create secret.
The image shows a web interface for managing secrets in HashiCorp Vault, with options for "azuredevops" and "jenkins" under the "training" section. The interface includes a search bar and a "Create secret" button."
Enter secret data
Provide artifact = "jenkins" or other key-value pairs, then save.
The image shows a web interface for creating a secret in HashiCorp Vault, with fields for specifying the secret path and data. There are options to save or cancel the entry."
View stored JSON
Select the secret to see its JSON key-value data.
The image shows a web interface for HashiCorp Vault, displaying a secret stored under the path "apps/artifactory" with a JSON key-value pair. The secret's value is obscured for security."
Create an ACL policy
Under Policies, click Create policy, enter a name and HCL, then save.
The image shows a user interface for creating an ACL policy, with fields for entering a name and policy details, and options to create or cancel the policy."

13. Accessing KV v2 via the HTTP API

To retrieve secret data over HTTP, include /data/ in the path:
Response:
For KV v1 mounts, omit the /data/ prefix.

References

That wraps up our deep dive into the KV v2 engine. Enjoy secure, versioned secret management with HashiCorp Vault!

Watch Video