Chapter 94: HashiCorp Vault and Secrets Management
94.6 Versions, check-and-set and deletion safety
Story (fictional teaching scenario). At a fictional Pune publisher, Priya and Noah from Toronto edit the same config. Without a version check, the later write can overwrite the earlier change.
Why
History helps recovery, while a conditional write helps prevent accidental overwrites.
What
- Version is a numbered stored revision.
- CAS (check-and-set) accepts a write only when the expected current version matches.
- Soft delete hides a version but leaves underlying data recoverable through undelete.
- Destroy permanently removes selected version data. Deleting all metadata removes all versions. These are not ordinary rotation steps.
How
-
Read the current version before a write.
-
Use CAS when concurrent edits are possible.
-
Distinguish hiding from destroying; never practise destruction on retained backups or real values.
Example 1: Conditional update
- Read the command or request.
vault kv put -mount=secret -cas=1 shop label=DEMO_V2
- Read the result.
Output (illustrative; NOT executed against Vault)
Version: 2
- Line by line:
-cas=1requires current version one. If someone already wrote version two, this request fails instead of silently replacing it. CAS zero permits only creation when the key has no version information.
Example 2: Read a selected version
- Read the command or request.
vault kv get -mount=secret -version=1 -field=label shop
- Read the result.
Output (illustrative; NOT executed against Vault)
DEMO_ONLY
- Line by line: The explicit version requests the older value. It does not reset the latest version. A destroyed version cannot be recovered with this read command.
Example 3: Deletion vocabulary only
- Read the command or request.
Soft-delete version -> hidden but may be undeleted
Destroy version -> data permanently removed
- Read the result.
Output (illustrative; NOT executed against Vault)
No delete or destroy operation is run in this chapter.
- Line by line: Soft delete and destroy are different lifecycle operations. Version retention limits can also permanently remove older history. Plan retention explicitly; never assume KV history replaces a backup.
Ravindra Bagale's Tip
A version history is useful, but it is not a restore-tested backup.
Version history उपयोगी आहे, पण restore test केलेला backup नाही.
Version history उपयोगी है, पर restore-tested backup नहीं.
Did you understand? Let us try it once more.