This guide explains how to set up HashiCorp Vault for encrypting LoRA adapter weights in ThemisDB.
ThemisDB supports production-ready encryption for LoRA adapter weights using HashiCorp Vault for key management. This replaces the MockKeyProvider used in development with a secure, enterprise-grade solution.
- HashiCorp Vault 1.15+ (running and accessible)
- Network connectivity from ThemisDB to Vault server
- Valid Vault authentication token or credentials
# Enable KV v2 secrets engine at "themis" mount path
vault secrets enable -version=2 -path=themis kv# Generate and store a 256-bit encryption key for LoRA adapters
vault kv put themis/keys/lora_adapters \
key=$(openssl rand -base64 32) \
algorithm="AES-256-GCM" \
version=1Create a policy file themis-lora-policy.hcl:
# Read access to LoRA adapter encryption keys
path "themis/data/keys/lora_adapters" {
capabilities = ["read"]
}
# Read metadata for key versioning
path "themis/metadata/keys/lora_adapters" {
capabilities = ["read"]
}Apply the policy:
vault policy write themis-lora themis-lora-policy.hcl# Generate a token with the themis-lora policy
vault token create -policy=themis-lora -period=24h
# Output will include:
# Key Value
# --- -----
# token hvs.CAESI...
# token_accessor abc123...
# token_duration 24hImportant: Store the token securely. This token will be used by ThemisDB to authenticate with Vault.
Update your ThemisDB configuration:
LoRAStorageService::Config config;
config.enable_encryption = true;
config.use_vault_for_encryption = true;
config.vault_addr = "http://localhost:8200"; // Your Vault server
config.vault_token = "hvs.CAESI..."; // Token from step 4
config.vault_kv_mount = "themis"; // KV mount path
config.encryption_key_id = "lora_adapters"; // Key ID in VaultSet environment variables:
export VAULT_ADDR="http://localhost:8200"
export VAULT_TOKEN="hvs.CAESI..."Then configure ThemisDB:
LoRAStorageService::Config config;
config.enable_encryption = true;
config.use_vault_for_encryption = true;
config.vault_kv_mount = "themis";
config.encryption_key_id = "lora_adapters";
// vault_addr and vault_token will be read from environment- Comply with security policies (e.g., rotate every 90 days)
- Mitigate risk if a key is compromised
- Meet compliance requirements (PCI-DSS, HIPAA, etc.)
ThemisDB uses envelope encryption with automatic key versioning:
- Each encrypted adapter stores the key version used
- Old adapters can still be decrypted with their original key version
- New adapters use the latest active key version
- No data migration required!
# Create a new version of the key
vault kv put themis/keys/lora_adapters \
key=$(openssl rand -base64 32) \
algorithm="AES-256-GCM" \
version=2
# Vault automatically marks the new version as active
# Old adapters will still decrypt with version 1
# New adapters will encrypt with version 2# List all versions of the key
vault kv metadata get themis/keys/lora_adapters
# Get specific version
vault kv get -version=1 themis/keys/lora_adaptersEnable TLS for Vault connections:
config.vault_addr = "https://vault.example.com:8200"; // Use HTTPSConfigure Vault with a valid TLS certificate:
vault server \
-config=/etc/vault/config.hcl \
-tls-cert-file=/path/to/cert.pem \
-tls-key-file=/path/to/key.pem- Use separate tokens for each service
- Grant only necessary permissions (read-only for ThemisDB)
- Avoid using root tokens in production
Token Rotation:
# Generate a new token before the old one expires
vault token create -policy=themis-lora -period=24h
# Update ThemisDB configuration with new token
# Restart ThemisDB or use dynamic reloading if availableToken Lifecycle:
- Use periodic tokens with automatic renewal
- Set appropriate TTL (e.g., 24 hours)
- Monitor token expiration
Enable Vault audit logging:
vault audit enable file file_path=/var/log/vault/audit.logMonitor audit logs for:
- Failed authentication attempts
- Unauthorized key access
- Unusual access patterns
ThemisDB logs key retrieval statistics:
[INFO] Using VaultKeyProvider for encryption (Production-Ready)
[DEBUG] Vault Address: http://localhost:8200
[DEBUG] KV Mount: themis
[DEBUG] Key ID: lora_adapters
[DEBUG] Encrypted adapter data with key version 2
- Cold fetch (first request): ~50-100ms
- Cached fetch (subsequent): <0.1ms
- Cache TTL: 1 hour (configurable)
- Cache hit rate: >95% expected
Monitor Vault connectivity:
# Check Vault status
vault status
# Test key retrieval
vault kv get themis/keys/lora_adaptersError: "Vault connection failed (transient)"
Solutions:
- Check Vault server is running:
vault status - Verify network connectivity:
curl http://localhost:8200/v1/sys/health - Check firewall rules
Error: "Vault initialization failed: 403 Forbidden"
Solutions:
- Verify token is valid:
vault token lookup - Check token has required policy:
vault token lookup -format=json | jq .data.policies - Regenerate token if expired
Error: "Key not found: lora_adapters"
Solutions:
- Verify key exists:
vault kv get themis/keys/lora_adapters - Check KV mount path matches configuration
- Ensure key_id matches Vault path
Error: "Decryption failed: Key version 1 not found"
Solutions:
- Verify all key versions are available:
vault kv metadata get themis/keys/lora_adapters - Don't delete old key versions while adapters still use them
- Check Vault audit logs for access denials
- Vault server deployed with TLS
- KV v2 secrets engine enabled
- Encryption keys generated and stored
- Vault policies created with least privilege
- Service tokens generated and distributed securely
- ThemisDB configured with Vault credentials
- Connection tested and verified
- Audit logging enabled
- Monitoring and alerting configured
- Key rotation schedule defined
- Backup and disaster recovery plan documented
# Start Vault in dev mode
docker run --rm --cap-add=IPC_LOCK \
-e 'VAULT_DEV_ROOT_TOKEN_ID=myroot' \
-p 8200:8200 \
vault
# Configure ThemisDB
export VAULT_ADDR="http://localhost:8200"
export VAULT_TOKEN="myroot"apiVersion: v1
kind: Secret
metadata:
name: themisdb-vault-token
type: Opaque
stringData:
token: "hvs.CAESI..."
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: themisdb
spec:
template:
spec:
containers:
- name: themisdb
env:
- name: VAULT_ADDR
value: "https://vault.example.com:8200"
- name: VAULT_TOKEN
valueFrom:
secretKeyRef:
name: themisdb-vault-token
key: tokenFor issues or questions:
- GitHub Issues: https://github.com/makr-code/ThemisDB/issues
- Security issues: See SECURITY.md