Courseiva
VA-003Chapter 5 of 16Objective 2.2

KV Secrets Engine (Version 1 & 2)

Failing to understand how Vault stores your secrets can lead to accidental data loss — or, worse, permanent deletion of credentials your applications depend on. The KV (Key-Value) Secrets Engine is the most fundamental storage backend in HashiCorp Vault, and the VA-003 exam expects you to know the difference between its two versions inside and out. Mastering this distinction is your first real step toward using Vault for everyday secret management.

12 min read
Beginner
Updated Jul 23, 2026
Reviewed by Johnson Ajibi· Senior Network & Security Engineer · MSc IT Security

A simple way to picture KV Secrets Engine (Version 1 & 2)

The Old Filing Cabinet vs. The New Digital Locker Analogy

The dusty basement of 'Retro Relics' garage sale shop.

The shop has two storage systems for customer receipts. Version 1 is an old, rusty filing cabinet. When a customer buys a vintage lamp, the owner, Bert, opens the drawer labelled 'Receipts' and drops the receipt inside. If he wants to update it — say, to add a warranty note — he takes the entire pile out, scribbles on the paper, shreds the old one, and puts the new one back. You can only see the latest version of each receipt; all previous revisions are gone forever. If Bert makes a mistake, there is no 'undo'.

Version 2 is a brand-new digital locker. This time, when Bert stores a receipt, the system automatically takes a snapshot of the drawer's entire contents before allowing any change. Now, if a customer returns the lamp two years later and Bert needs to check the original sale details, he can scroll back through time to see every version of every receipt — like flipping through an organised photo album of his filing cabinet. He can also delete a receipt permanently, or just 'soft delete' it so it hides from view but still sits in a recycle bin for 30 days. The digital locker even lets him set a maximum number of snapshots to save, preventing the basement from overflowing with old data.

The core difference is permanence: Version 1 forgets everything but the latest version; Version 2 remembers the entire history of changes.

How It Actually Works

The KV Secrets Engine — short for Key-Value Secrets Engine — is a built-in storage backend within Vault that lets you store and retrieve arbitrary secrets as simple key-value pairs. A 'key' is like a label (for example, 'api-key'), and a 'value' is the actual secret data (for example, 'abc123xyz'). This is the simplest way to get secrets into Vault, and it does not require any external database or cloud service.

Vault offers two versions of this engine: Version 1 (sometimes called KV v1) and Version 2 (KV v2). They both store data in the same basic key-value format, but they behave very differently when you read, write, or delete secrets.

On Version 1, there is no versioning. When you write a secret to a path — a path is like a folder location in a filesystem, for example 'secret/myapp/database' — Vault simply overwrites whatever was there before. If you read the secret back, you get only the most recent value. If you delete the secret, it is gone forever. There is no undo, no history, no recovery. This is fine for static secrets that rarely change and where old values have no value. However, if a developer accidentally overwrites a production database password, you cannot roll it back. This lack of safety is the biggest limitation of Version 1.

Version 2 introduces full secret versioning. Think of it like Git for secrets. Every time you write a new value to the same path, Vault increments the version number and keeps the previous version intact. By default, Vault stores the ten most recent versions, but you can configure this 'max-versions' parameter to any number you like — including unlimited, though that consumes more storage. When you read a path in KV v2, you always get the latest version unless you explicitly request an older one by appending '?version=1' to your read request.

Version 2 also adds soft delete capabilities. With soft delete, you can delete a secret but not permanently erase it. Instead, the secret is marked as deleted and hidden from normal listing operations. It remains in storage for a configurable period — typically 30 days — after which a 'destroy' operation permanently removes it. This mimics a recycle bin: if you accidentally delete a production certificate, you can undelete it as long as the grace period has not expired.

Another important feature is the 'delete-version' operation in v2. You can delete a specific version number — for example, delete version 3 of a secret while keeping versions 1, 2, and 4. This is useful if a secret was compromised and you need to remove only the leaked version from history, while keeping others for auditing.

The choice between versions depends on your use case:

Choose Version 1 if you need maximum simplicity and performance, and you are certain you never need secret history. For example, storing a one-time setup token that changes only during initial provisioning.

Choose Version 2 if there is any chance you will need to audit changes, recover from accidental overwrites, or comply with retention policies. This is the recommended default for production environments.

Both versions support listing all secrets under a path (like 'ls' on a directory) and reading individual secrets. However, they use different API endpoints internally. A Vault administrator enables the engine on a mount path — typically 'secret/' — and specifies the version parameter: either 1 or 2. Once enabled, the version is fixed for that mount path; you cannot change it later without migrating data manually.

In summary, the KV secrets engine solves the problem of storing static secrets — secrets that do not automatically rotate — in a central, secure location. It replaces scattered configuration files, environment variables, and hard-coded passwords that are difficult to manage and audit. The version 2 improvements add the safety net of history and recovery, which is why most production Vault deployments use KV v2 despite its slightly higher storage overhead.

Decision flowchart showing the two KV engine versions and their key operational differences.

Walk-Through

1

Enable the KV Secrets Engine

Run 'vault secrets enable -path=secret -version=2 kv' to activate the engine on the 'secret/' mount path. The -version=2 flag is critical; omitting it defaults to version 1, which has no versioning. This step creates the entry point where all your secrets will live.

2

Write a Secret (First Version)

Use 'vault kv put secret/myapp/database username=admin password=pass1'. This creates the first version (version 1) of the secret at that path. Vault stores the data and automatically assigns version 1. In v2, this operation always increments the version counter.

3

Overwrite the Secret (Creates Version 2)

Run 'vault kv put secret/myapp/database password=newpass' to update the password. Vault creates version 2, preserving version 1 in its history. You can now retrieve either version by specifying '?version=1' or '?version=2' in your read request.

4

Soft Delete the Secret

Execute 'vault kv delete secret/myapp/database' to soft delete the secret. The secret is hidden from normal 'vault kv list' commands but remains in storage. You can recover it later with 'vault kv undelete' or by specifying the version explicitly.

5

Rollback to a Previous Version

If you need to revert to version 1 (before the accidental overwrite), run 'vault kv rollback secret/myapp/database 1'. This creates a new version (version 3) that is an exact copy of version 1. The rollback does not delete version 2; it just adds a new version with the old data.

6

Permanently Destroy a Specific Version

To permanently remove version 2 (the compromised version), run 'vault kv destroy secret/myapp/database 2'. This wipes version 2 from storage irreversibly. Other versions remain intact. You cannot recover a destroyed version — use this with extreme caution.

7

Configure Max Versions and Undelete Period

Run 'vault kv metadata put -max-versions=20 -delete-version-after=60d secret/myapp/database' to set a retention policy. This limits the number of stored versions to 20 and sets a 60-day grace period for soft-deleted secrets before they are automatically destroyed.

What This Looks Like on the Job

Imagine you are the sole IT administrator for 'GreenLeaf Tech', a small software company that builds a customer relationship management (CRM) application. The CRM needs to connect to a PostgreSQL database, an external payment API, and an SMTP email server. Currently, the database password is stored in a plain text file on a shared network drive. The payment API key is hard-coded in the application source code. This is a security nightmare: any employee who accesses the shared drive can read the database password, and the API key is exposed in the Git repository history.

You decide to implement HashiCorp Vault to centralise and secure these secrets. For your first deployment, you choose the KV secrets engine because all three secrets are static — they do not change automatically, and you manage them manually.

Here is the step-by-step process you follow:

Enable the KV secrets engine on the 'secret/' mount path, specifying version 2 for safety. The Vault command is: vault secrets enable -path=secret -version=2 kv.

Create a policy that defines which paths the CRM application can read. For example, you write a policy 'crm-reader' that allows read and list on 'secret/crm/*'. You attach this policy to a Vault token that the CRM application will use to authenticate.

Store the database password: vault kv put secret/crm/database username=admin password=SuperSecure!2024 host=db.greenleaf.local. Vault stores this as version 1.

Store the payment API key: vault kv put secret/crm/payment api_key=pk_live_XXXXXXXXXXXXXXXXXXXX. This becomes version 1 of the 'payment' secret.

Store the SMTP credentials: vault kv put secret/crm/smtp username=noreply@greenleaf.com password=MailPass2024 server=smtp.greenleaf.local.

Three months later, a security audit reveals that the payment API key has been compromised. You need to rotate the key immediately. You generate a new key from the payment provider and write it to the same path: vault kv put secret/crm/payment api_key=pk_live_YYYYYYYYYYYYYYYYYYYY. Vault stores this as version 2. The audit log shows that you overwrote the secret at 2:15 PM on Tuesday.

During the rotation, a junior developer accidentally writes the old compromised key back to the path, thinking they are restoring the 'correct' value. This creates version 3 — which is actually the compromised key again. You detect this error within hours. Because you are using KV v2, you can run: vault kv rollback secret/crm/payment 2. This command restores version 2 as the latest version, effectively undoing the developer's mistake. The compromised version 3 still exists in the history, but it is no longer the active secret.

Later, you decide to decommission the old SMTP server. You soft delete its credentials: vault kv metadata delete secret/crm/smtp. The secret disappears from normal listings, but it remains recoverable for 30 days in case another service still references it. After 30 days, a periodic cleanup job runs vault kv destroy secret/crm/smtp, which permanently removes the data.

As the company grows, you configure the maximum versions to 20 for the CRM path, ensuring you always have enough history for auditing but not wasting storage on infinite old versions. You also enable soft delete with a 60-day undelete period for all critical secrets.

This real-world scenario shows how KV v2 gives you operational safety without sacrificing simplicity. The VA-003 exam will expect you to recognise exactly this kind of workflow: when to use put, get, delete, destroy, and rollback, and which version supports each operation.

How VA-003 Actually Tests This

The VA-003 exam tests your understanding of the KV secrets engine in two main ways: concept recognition and command knowledge. You will see multiple-choice questions that ask you to choose the correct command syntax, or to identify which version of the engine a particular feature belongs to. The exam loves to trap candidates on the differences between v1 and v2.

Here are the specific exam topics you must master:

Version identification: Given a scenario (e.g., 'a developer needs to recover an accidentally overwritten secret'), you must select the correct version (v2) and the correct command (vault kv rollback).

Command-line operations: You must know the difference between 'vault kv put' (writes a new version in v2, overwrites in v1), 'vault kv get' (reads the latest version by default in v2, reads the only version in v1), 'vault kv delete' (marks a secret as deleted in v2, permanently deletes in v1), and 'vault kv destroy' (permanently removes a secret in v2, but does not exist in v1).

Path structure: The exam expects you to know that KV v2 stores metadata and data under separate paths. For example, 'secret/data/mypath' is the data endpoint for v2, while 'secret/mypath' is the direct data endpoint for v1. The 'metadata' path for v2 is 'secret/metadata/mypath'.

Max-versions parameter: Understand that the default is 10 versions, and you can adjust it per path using 'vault kv metadata put -max-versions=5 secret/mypath'.

Soft delete vs. hard delete: Soft delete (vault kv delete) hides the secret but keeps it recoverable. Hard delete (vault kv destroy) permanently removes a specific version. The exam will present a scenario and ask which operation to use.

Rollback: The 'vault kv rollback' command is exclusive to v2 and restores a specific version as the latest. This is a frequent exam topic.

Common trap patterns you will encounter:

Trap: 'A team wants to keep only the most recent 3 versions of a secret. Which command should they use?' Wrong answer: 'vault kv put -max-versions=3'. Correct answer: They must use 'vault kv metadata put' or a tune operation on the path. The put command does NOT accept the max-versions parameter.

Trap: 'The vault kv delete command permanently removes data in both versions.' This is false. In v2, delete is soft. In v1, delete is immediate and permanent.

Trap: 'You can use vault kv rollback in KV v1.' Wrong. Rollback is only available in v2 because v1 has no version history to roll back to.

Trap: 'Destroying a secret in v2 removes the entire secret.' Actually, destroy removes a specific version number. To remove all versions, you destroy each version individually or use metadata delete followed by metadata destroy for the entire path.

Trap: 'The vault kv get command always returns the latest version.' In v2, it returns the latest undeleted version. If the latest version was soft-deleted, it returns the previous undeleted version. This catches many candidates.

Key definitions to memorise for the exam:

KV v1: No versioning, no history, permanent delete. Simple and fast.

KV v2: Versioning, metadata, soft delete, rollback, max-versions. Recommended for production.

Mount path: The file-system-like prefix where the engine is enabled (commonly 'secret/').

Data path (v2): 'secret/data/<path>' for reading/writing secret data.

Metadata path (v2): 'secret/metadata/<path>' for viewing or modifying version metadata, like max-versions.

By internalising these distinctions, you can confidently answer the 2–4 KV-specific questions on the VA-003 exam.

Key Takeaways

KV v1 stores no version history; every write overwrites the previous value permanently.

KV v2 stores up to 10 versions by default, with a configurable max-versions cap per path.

In KV v2, vault kv delete performs a soft delete, keeping the secret recoverable for a grace period.

The vault kv destroy command in v2 permanently removes a specific version number, not the entire secret.

You cannot convert a KV v1 mount to v2; you must create a new mount and migrate data manually.

Use vault kv rollback in v2 to create a new version that copies an older version's data, effectively undoing a mistake.

The data path for KV v2 is secret/data/ — never secret/ directly for read/write operations.

The metadata path for KV v2 (secret/metadata/) allows you to view and edit max-versions and deletion settings.

Easy to Mix Up

These come up on the exam all the time. Here's how to tell them apart.

KV v1 (Key-Value Version 1)

No version history; every write overwrites the current value

Delete is immediate and permanent — no recovery possible

Cannot rollback to a previous value; any overwrite is irreversible

KV v2 (Key-Value Version 2)

Stores up to N versions (default 10, configurable) of each secret

Supports soft delete: secret is hidden but recoverable within a grace period

Supports rollback: creates a new version from an older one without destroying intermediate versions

vault kv delete (KV v2)

Performs a soft delete — the secret is hidden but still stored

The secret can be recovered using 'vault kv undelete'

Does not permanently remove any version data from storage

vault kv destroy (KV v2)

Permanently removes a specific version number from storage

The destroyed version is irrecoverable — no undelete operation exists

Affects only the specified version; other versions and the metadata remain intact

KV v2 Data Path (secret/data/)

Used for reading and writing the actual secret values (data)

Does not expose version metadata like creation timestamps or max-versions

Reading from this path returns the secret payload and its version number

KV v2 Metadata Path (secret/metadata/)

Used for viewing and modifying version configuration (e.g., max-versions)

Returns metadata such as created_time, deletion_time, and version list

Writing to this path changes settings like max-versions and delete-version-after

Watch Out for These

Mistake

KV v2 stores every single version of a secret indefinitely until you manually delete it.

Correct

KV v2 stores only the most recent N versions, where N defaults to 10 and is configurable via max-versions. Older versions are automatically pruned when new versions are written.

Beginners assume 'versioning' means 'infinite storage of all history', but Vault prioritises storage efficiency and enforces a retention cap.

Mistake

You can upgrade a KV v1 mount to v2 without losing data by simply changing a parameter.

Correct

You cannot change the version of an existing mount. You must create a new mount with v2, then migrate the data manually using a tool or script.

The version parameter is set at mount creation time and is immutable. This is counterintuitive because most software allows in-place upgrades.

Mistake

The vault kv delete command permanently removes the secret in both versions, so use it with caution.

Correct

In KV v2, vault kv delete performs a soft delete—the secret is hidden but recoverable. Only vault kv destroy permanently removes a specific version.

The word 'delete' in everyday language implies permanent removal, so beginners assume the same for both versions without reading the documentation nuance.

Mistake

KV v2 stores each version as a complete copy of the entire secret, so storage grows linearly with the number of versions.

Correct

Vault stores only the difference (delta) between versions for efficiency, though the API presents each version as a full secret. Storage grows more slowly than with full copies.

This misconception arises because the API returns full objects, leading beginners to believe the backend stores full copies rather than incremental diffs.

Mistake

The vault kv rollback command in v2 deletes the unwanted versions and then makes the target version the latest.

Correct

vault kv rollback creates a new version that is a copy of the target version, advancing the version number. It does not delete any existing versions.

Users expect rollback to 'rewind' the version history, but Vault's immutability model means it always appends new versions, never rewrites history.

Do You Actually Know This?

Reveal each answer, then mark whether you got it right. Score 60%+ to unlock the next chapter.

Frequently Asked Questions

What is the difference between KV v1 and KV v2 in Vault?

KV v1 has no versioning — every write overwrites the previous value permanently, and delete is irreversible. KV v2 keeps a history of changes (up to a configurable number of versions), supports soft delete with recovery, and allows rollback to any previous version.

How do I read a specific older version of a secret in KV v2?

Append '?version=N' to your read request, where N is the version number. For example: 'vault kv get -version=2 secret/myapp/database' retrieves version 2 of that secret. Without the flag, you get the latest undeleted version.

Can I change a KV v1 mount to v2 later?

No. The version parameter is set when you enable the engine on a mount path. You cannot change it afterward. To migrate, you must create a new mount with v2 and copy the data over manually using a script.

What does 'vault kv destroy' do exactly?

It permanently removes a specific version number of a secret from storage. For example, 'vault kv destroy secret/myapp/database 3' irreversibly deletes version 3. Other versions remain. This is different from 'vault kv delete', which is a soft delete.

How do I set the maximum number of versions to keep in KV v2?

Use 'vault kv metadata put -max-versions=20 secret/myapp/database' to set a limit of 20 versions. The default is 10. Vault automatically prunes the oldest versions when a new version is written and the limit is exceeded.

What happens if I overwrite a secret in KV v1?

The previous value is overwritten immediately and permanently. There is no way to recover the old value. This is why v1 is only recommended for secrets that are rarely changed and where history is not needed.

Terms Worth Knowing

Keep going

You've finished KV Secrets Engine (Version 1 & 2). Continue through the VA-003 study guide to build a complete picture of the exam.

Done with this chapter?