Learn to use Vault's Transit secrets engine for encryption operations.
Time to Complete: 20-25 minutes
Preview Mode: Use Cmd/Ctrl + Shift + V
in VSCode to see a nicely formatted version of this lab!
- Create a Codespace from this repo (click the button below).
- Once the Codespace is running, open the integrated terminal.
- Follow the instructions in each lab to complete the exercises.
- Enable the Transit engine:
# Log in with a valid token
vault login root
# Enable the Transit secrets engine
vault secrets enable transit
- Create an encryption key:
vault write -f transit/keys/my-app
- Encrypt data:
# Encode data in base64
echo -n "sensitive data" | base64
# Encrypt the data
vault write transit/encrypt/my-app plaintext=$(echo -n "sensitive data" | base64)
- Decrypt data:
# Store the ciphertext from previous step
CIPHER="vault:v1:abc123..." # Use your actual ciphertext
# Decrypt
vault write transit/decrypt/my-app ciphertext=$CIPHER
- Decode the result:
echo "base64-output" | base64 -d # Replace with actual output
- Rotate the encryption key:
vault write -f transit/keys/my-app/rotate
- Check key details:
vault read transit/keys/my-app
- Encrypt new data (uses latest key version):
vault write transit/encrypt/my-app plaintext=$(echo -n "new data" | base64)
- Update key configuration:
# Set minimum decryption version
vault write transit/keys/my-app/config min_decryption_version=1
# Set minimum encryption version
vault write transit/keys/my-app/config min_encryption_version=1
# Enable key deletion
vault write transit/keys/my-app/config deletion_allowed=true
- Create key with specific parameters:
vault write transit/keys/my-app-2 \
type="aes256-gcm96" \
exportable=false \
deletion_allowed=true
- Generate data key:
vault write -f transit/datakey/plaintext/my-app
- Generate wrapped data key:
vault write -f transit/datakey/wrapped/my-app
Create an encryption workflow:
- Create new encryption key
- Encrypt 3 pieces of data
- Rotate the key
- Encrypt new data
- Verify old data still decrypts
- List all key versions
vault delete transit/keys/my-app
vault delete transit/keys/my-app-2
vault secrets disable transit
- Key rotation
- Configurable key types
- Versioning support
- Data key generation
- Secure key storage