Introduction
Expected Outcome
There are edge cases where all the secrets stored on a specific path on a Kv-v2 secrets engine mount must be permanently removed. Currently there is no API option to achieve this task and permanently delete all the subkeys and secrets.
This operation involves custom filters and special conditions that could potentially produce the complete loss of all the child secrets and the metadata associated with those objects. Incorrect execution or adding a wrong starting Kv-v2 path could reach to complete loss of data for which the single fallback option is the restore of Vault database.
WARNINGS: DO NOT perform these steps if your cluster is experiencing performance issues due to leases/writes.
Prerequisites
- All Vault versions >= 0.10.3
Use Case
Having a secret Kv-v2 mounted and a set of secrets saved under a deep hierarchy structure like:
Enable secrets engine KV and secrets (demo purpose) |
vault secrets enable -path=kv kv-v2 |
Vault secrets engine view |
|-- kv/ |
the requirement is to permanently delete the prefixed kv/prod for setting the environment ready for testing.
Procedure
After creating a consistent backup of the Vault data execute a delete using as argument the path to be permanently deleted.
-
Step 1 - Perform a backup using the guide from Vault SOP and make sure that you save the generated output on a safe location.
-
Step 2 - Save a script on a Linux/MAC OS console that is having the necessary permissions to access the Vault cluster. The script may be named: delete_secrets.sh
#!/bin/bash |
-
Step 3 - Login to the Vault server using a TOKEN with the correct permissions to perform the recursive delete.
-
Step 4 - Add the below code into the script delete_secret.sh
-
Step 5 - Execute the script for the specific path. The path for the secret must contain the secrets engine Kv-v2 mount point!
As example, if the secret engine of typeKv-v2
is enabled at pathkv
and the secret is stored asprod
, then the following table applies.
Operation | Details |
Execution |
bash delete_secrets.sh kv/prod/ |
Output |
### DELETE ALL the secrets on path: kv/ |
Additional Information
-
Vault API Docs Kv-v2 Metadata
-
Vault API Docs Kv-v2 Secrets Engine