Skip to main content
In this guide, you’ll learn how to manage secrets in HashiCorp Vault’s Key/Value (KV) Secrets Engine using the Vault CLI. We’ll cover writing, reading, deleting, and listing secrets in both KV v1 and v2, plus advanced v2-only operations: undelete, destroy, patch, and rollback.
Ensure you have Vault CLI installed and authenticated. For installation instructions, see the Vault Installation Guide.

KV CLI Command Overview

Vault provides a unified vault kv command with these core subcommands: KV v2 adds these metadata and versioning operations:
The image is a guide on using the vault kv command in the CLI, detailing commands like put, get, delete, and list, with additional commands for KV V2 such as undelete, destroy, patch, and rollback. It also features a cartoon character and a certification badge.

Comparing KV Version 1 vs. Version 2

Although vault kv put kv/app/db pass=123 uses the same syntax in both versions, the output and data paths differ:

KV Version 1

KV Version 2

Version 2 automatically prefixes your path with data/ and returns metadata, including version details.

Writing Secrets to the KV Store

Basic Write

Bulk Write from File

Vault will read key/value pairs from secrets.json and store them at the specified path.
Each put command replaces the entire data set at that path. It does not merge with existing keys.

Overwriting vs. Patching

To overwrite all data:
To update a single key without removing others:

Managing Versions: Rollback

Restore a previous version as the latest:
A new version (3) is created based on version 1, restoring the old data.

Reading Secrets

Retrieve the latest version:

JSON Output

For machine-friendly output, use -format=json or set VAULT_OUTPUT=json:

Working with Specific Versions

  • Latest version:
  • Specific version (N):

Deleting and Destroying Secrets

The image explains the differences between deleting secrets in KV V1 and KV V2 stores, highlighting that KV V1 deletes are permanent, KV V2 deletes are soft and restorable, and KV V2 destroys are permanent. It also features a Vault certification badge and a cartoon character.

KV Version 1

A delete permanently removes the data:

KV Version 2

  • delete performs a soft delete (marks data without purging).
  • destroy permanently purges specified versions.

Soft Delete

Destroy

Once destroyed, the data cannot be recovered without a snapshot restore.

Summary

Vault’s KV Secrets Engine is your go-to store for arbitrary secrets. KV v2 enhances this with:
  • Versioning and detailed metadata
  • Soft deletes and permanent destroys
  • Granular updates via patch
  • Recovery operations: undelete and rollback
With these commands, you can confidently manage, version, and protect your secrets in Vault.

Watch Video