When using the Vault CLI helper (vault kv), you can omit internal KV v2 prefixes (data/ and metadata/). The CLI will show internal paths in output but does not require you to type them.Write a secret at kvv2/apps/circleci:
A normal vault kv delete performs a soft delete: it marks the latest version as deleted but retains metadata and previous versions. You can undelete specific versions later.Soft-delete the latest version:
Copy
bk@Bryans-MBP ~ % vault kv delete kvv2/apps/circleciSuccess! Data deleted (if it existed) at: kvv2/apps/circlecibk@Bryans-MBP ~ %
After a soft delete, vault kv get may show metadata but no data for the deleted version. To recover, use vault kv undelete and specify one or more versions to restore:
Copy
bk@Bryans-MBP ~ % vault kv undelete -versions=2 kvv2/apps/circleciSuccess! Data written to: kvv2/undelete/apps/circlecibk@Bryans-MBP ~ % vault kv get kvv2/apps/circleci====== Secret Path ======kvv2/data/apps/circleci====== Metadata =======Key Value--- -----created_time 2022-03-25T14:19:38.741912Zcustom_metadata <nil>deletion_time n/adestroyed falseversion 2==== Data ====Key Value--- -----admin P@ssw0rd!bk@Bryans-MBP ~ %
Undelete accepts multiple versions via the -versions flag (for example: -versions=2,3), which lets you restore several deleted versions at once.
vault kv destroy permanently removes specified versions from storage — this is irreversible without restoring from a Vault snapshot/backup.
Destroying KV v2 versions is permanent. You cannot recover destroyed versions with vault kv undelete. Only a Vault snapshot/backup can restore destroyed data.
Example: destroy version 1 and observe that it is removed:
Attach key/value annotations to a secret using vault kv metadata put with -custom-metadata:
Copy
bk@Bryans-MBP ~ % vault kv metadata put -custom-metadata="abc=123" kvv2/apps/circleciSuccess! Metadata written to: kvv2/metadata/apps/circlecibk@Bryans-MBP ~ %
A JSON vault kv get -format=json response will include custom_metadata. Use jq to extract fields:
List keys and fully delete a secret (metadata + data)
List keys under a mount:
Copy
bk@Bryans-MBP ~ % vault kv list kvv2Keys-----apps/bk@Bryans-MBP ~ % vault kv list kvv2/appsKeys-----circlecibk@Bryans-MBP ~ %
To permanently remove a secret path (all versions and the metadata), delete its metadata:
Copy
bk@Bryans-MBP ~ % vault kv metadata delete kvv2/apps/circleciSuccess! Data deleted (if it existed) at: kvv2/metadata/apps/circlecibk@Bryans-MBP ~ %bk@Bryans-MBP ~ % vault kv list kvv2No value found at kvv2/metadatabk@Bryans-MBP ~ %
Deleting metadata removes both metadata and all versioned data for that path.
You can manage KV v2 mounts and keys in the Vault Web UI. Below are screenshots demonstrating the secrets engines list, creating a KV v2 secret, and viewing a saved secret (with masked values):
Note: CLI helper commands (e.g., vault kv put/get/list) hide these prefixes for convenience, but policies and direct API calls must reference the internal prefixes.
CLI helper commands — vault kv put/get/list — abstract away the internal data/ and metadata/ prefixes. When writing policies or calling the HTTP API directly, always include data/ or metadata/ as appropriate.
If you omit data/ in the URL for KV v2 reads, you will not receive the expected data payload structure and policy matches may fail. Use metadata/ for metadata API endpoints (e.g., .../kvv2/metadata/<path>).
Convert KV v1 mounts to KV v2 with vault kv enable-versioning.
Enable new KV v2 mounts via vault secrets enable -path=<mount> kv-v2.
Use vault kv put/get/delete CLI helpers — they hide data/ and metadata/ prefixes.
Use vault kv undelete to recover soft-deleted versions; use vault kv destroy to permanently remove versions.
Manage retention with metadata (max_versions, delete_version_after) and annotate secrets with custom metadata.
For policies and direct API calls, always include the data/ and metadata/ prefixes in paths.
If you want details on CAS (compare-and-swap), conflict handling, or examples for tuning max_versions and delete_version_after, ask and I’ll provide targeted examples.