-
Notifications
You must be signed in to change notification settings - Fork 1
Security Key Management
Document Version: 1.0
Last Updated: 2026-04-06
Status: Active
Classification: Confidential
Owner: Chief Information Security Officer (CISO)
This policy establishes standards and procedures for the lifecycle management of cryptographic keys used in ThemisDB systems, ensuring secure generation, storage, distribution, rotation, and destruction of encryption keys.
This policy covers:
- All cryptographic keys used in ThemisDB systems
- Data encryption keys (DEKs), Key encryption keys (KEKs), Master keys
- Key generation, storage, backup, rotation, and destruction
- All environments: development, staging, and production
ThemisDB uses a hierarchical key management system:
βββββββββββββββββββββββββββββββββββββββ
β Master Key (Root of Trust) β
β Storage: HSM / Cloud KMS β
β Rotation: Every 3 years β
ββββββββββββββββ¬βββββββββββββββββββββββ
β
βββββββββ΄ββββββββ
β β
ββββββββΌβββββββ ββββββΌβββββββββββ
β Key β β Data β
β Encryption β β Encryption β
β Keys (KEK) β β Keys (DEK) β
β β β β
β Rotation: β β Rotation: β
β Every 2 β β Annually β
β years β β β
βββββββββββββββ βββββ¬ββββββββββββ
β
ββββββββββββββΌβββββββββββββ
β β β
ββββββΌββββββ βββββΌβββββ ββββββΌβββββββ
β Field β β Blob β β Audit Log β
β Encrypt β β Encryptβ β Keys β
β Keys β β Keys β β β
ββββββββββββ ββββββββββ βββββββββββββ
- Purpose: Root of trust, encrypts KEKs
- Storage: Hardware Security Module (HSM) or Cloud KMS
- Lifetime: 3 years
- Backup: Encrypted split across multiple secure locations
- Access: Extremely restricted (CISO, designated key custodians only)
- Purpose: Encrypt data encryption keys for storage
- Storage: Encrypted by master key, stored in secure key store
- Lifetime: 2 years
- Backup: Encrypted with master key
- Access: Automated systems with service accounts
- Purpose: Encrypt actual data (fields, blobs, logs)
- Storage: Encrypted by KEK, stored with encrypted data or in key store
- Lifetime: 1 year (production), unlimited (development)
- Rotation: Annual or event-triggered
- Access: Application-level, retrieved via key provider interface
Random Number Generation:
- Use cryptographically secure random number generators (CSRNG)
- Linux:
/dev/urandomorgetrandom() - OpenSSL:
RAND_bytes() - Never use
rand(),random(), or time-based seeds
Key Strength:
| Key Type | Minimum Strength | Recommended |
|---|---|---|
| AES Symmetric | 128 bits | 256 bits |
| RSA Asymmetric | 2048 bits | 3072 bits |
| ECC | P-256 (256 bits) | P-384 (384 bits) |
Key Generation Location:
- Production: HSM or KMS with FIPS 140-2 Level 2+ certification
- Staging: KMS or secure key generation service
- Development: Mock key provider (never use in production)
- Request Authorization: Key generation must be authorized by security team
- Generate Key: Use approved CSRNG with sufficient entropy
- Encrypt Key: Immediately encrypt with KEK (for DEKs) or store in HSM (for Master Keys)
- Record Metadata: Key ID, creation date, purpose, algorithm, creator
- Audit Log: Log key generation event
Implementation: src/security/key_provider.h
Master Keys:
- β Stored in Hardware Security Module (HSM)
- β FIPS 140-2 Level 2 or higher certified
- β Multi-party authorization for access
- β Tamper-evident and tamper-resistant
Key Encryption Keys:
- β Encrypted by master key
- β Stored in secure, encrypted key store
- β Access controlled via service accounts
- β Replicated across availability zones
Data Encryption Keys:
- β Encrypted by KEK
- β Stored in metadata database or with encrypted data
- β Cached in memory (with protection)
- β Never stored in plaintext
Development/Testing:
- File-based key storage acceptable (encrypted)
- Mock key provider for unit tests
- Separate keys from production (never copy production keys)
- Keys can be regenerated as needed
Access Controls:
- Principle of least privilege
- Service accounts with minimal permissions
- No human access to plaintext keys in production
- MFA required for HSM access
Encryption at Rest:
- All stored keys encrypted (except master key in HSM)
- AES-256-GCM for key wrapping
- Key metadata can be stored in plaintext (but not keys themselves)
- HSM/KMS Integration: Keys retrieved via secure API
- Service Accounts: Application retrieves keys via authenticated API
- Secrets Management: Keys distributed via Vault, AWS Secrets Manager, etc.
- Manual Distribution: Encrypted channel with out-of-band verification (development only)
β Never Distribute Keys Via:
- Instant messaging
- Source code repositories
- Configuration files in version control
- Unencrypted network protocols
- Removable media without encryption
β Approved Methods:
- HSM/KMS API calls with mutual TLS
- Secrets management systems
- Encrypted and authenticated protocols
- Split-knowledge key sharing (for recovery)
| Key Type | Rotation Frequency | Event-Triggered |
|---|---|---|
| Master Key | Every 3 years | Security incident, HSM compromise |
| KEK | Every 2 years | Security incident |
| Data Encryption Keys | Annually | Security incident, suspected compromise |
| API Keys | Every 90 days | Suspected compromise, user termination |
| TLS Certificates | Annually | Compromise, algorithm deprecation |
Implementation: src/security/field_encryption.cpp::decryptAndReEncrypt()
Advantages:
- Zero downtime
- No large-scale data migration required
- Gradual transition
Process:
- Generate New Key: New key version created
- Deploy Key: New key deployed to all nodes
- Update Configuration: New key marked as active
-
Lazy Re-encryption:
- Reads decrypt with old key
- Writes re-encrypt with new key
- Data migrated over time
- Background Migration: Optional batch update for remaining data
- Retire Old Key: After migration complete, old key retired (but retained for emergency)
Status Check: needsReEncryption() method detects data encrypted with old keys
Used when old key is compromised:
- Revoke Old Key: Immediately mark old key as compromised
- Generate New Key: Create replacement key
- Batch Re-encryption: Re-encrypt all data with new key (scheduled job)
- Verification: Verify all data re-encrypted successfully
- Destroy Old Key: Securely destroy compromised key
Key Versioning:
- Each key has version identifier (e.g.,
data-encryption-key-v1,data-encryption-key-v2) - Encrypted data tagged with key version used
- Multiple versions active simultaneously during rotation
- Old versions retained read-only after rotation
Backward Compatibility:
- System can decrypt with any historical key version
- Old keys retained for configured retention period (default: 1 year post-rotation)
- Emergency recovery procedures documented
Master Keys:
- Split into shares using Shamir's Secret Sharing (minimum 3-of-5)
- Each share stored in separate secure location
- Geographic distribution of shares
- Annual verification of recovery process
Key Encryption Keys:
- Encrypted backup stored in secure offsite location
- Multiple copies across availability zones
- Encrypted with master key or separate backup key
Data Encryption Keys:
- Backed up with encrypted data
- Included in database backups
- Versioned with data snapshots
Trigger: HSM failure, data center disaster, corruption
Process:
- Assemble Key Custodians: Minimum 3 of 5 share holders
- Retrieve Shares: Each custodian retrieves their share
- Reconstruct Key: Combine shares to reconstruct master key
- Load into HSM: Load recovered key into new HSM
- Verify: Test decryption with recovered key
- Audit: Log recovery event and participants
Authorization: Requires CISO approval and dual control
Trigger: Key loss, corruption, accidental deletion
Process:
- Identify Lost Key: Determine key ID and version
- Restore from Backup: Retrieve encrypted key from backup
- Decrypt with Master Key: Unwrap key using master key
- Verify: Test key with encrypted data
- Re-deploy: Deploy recovered key to systems
- Audit: Log recovery event
- Key rotation complete and retention period expired
- Key compromised (after incident resolution)
- System decommissioned
- End of data retention period
- Regulatory requirement
- Destroy master key or KEK
- Encrypted data becomes permanently unrecoverable
- Fast and effective
- Suitable for large datasets
For keys stored on physical media:
- HSM: Follow manufacturer's key zeroization procedures
- Hard drives: Degaussing followed by physical destruction
- Certificates: Secure shredding
- Backup tapes: Degaussing or incineration
For keys in software:
- Overwrite memory with random data (minimum 3 passes)
- Use secure deletion APIs (e.g.,
sodium_memzero()) - Verify deletion
- Clear all copies (cache, logs, backups)
- Certificate of Destruction: Required for physical media
- Audit Log: All key destructions logged
- Verification: Attempt decryption fails after key destruction
- Compliance: Meet regulatory destruction requirements (GDPR "right to erasure")
Prometheus Metrics (include/security/field_encryption.h):
-
encryption_keys_active_total- Number of active keys -
encryption_keys_rotated_total- Key rotation events -
encryption_key_age_days- Age of each active key -
encryption_reencryption_operations_total- Lazy re-encryption operations
Reports:
- Monthly key lifecycle report
- Key age analysis
- Rotation compliance status
- Key usage patterns
Alerts Configured:
- Key approaching expiration (30 days before)
- Key expired but still in use
- Failed key rotation
- Unusual key access patterns
- Key generation failures
| Role | Permissions | MFA Required |
|---|---|---|
| CISO | Full key lifecycle management | Yes |
| Security Admin | Key generation, rotation, monitoring | Yes |
| Key Custodian | Master key shard holder | Yes |
| Application Service | DEK retrieval for encryption/decryption | No (service authentication) |
| DBA | View key metadata (not keys) | Yes |
| Developer | Development keys only | No |
| Auditor | Read-only access to audit logs | Yes |
| Action | CISO | Security Admin | Key Custodian | App Service | DBA | Developer | Auditor |
|---|---|---|---|---|---|---|---|
| Generate Master Key | β | β | β | β | β | β | β |
| Generate DEK | β | β | β | β | β | β * | β |
| Rotate Keys | β | β | β | β | β | β | β |
| Access Master Key | β | β | β | β | β | β | β |
| Retrieve DEK | β | β | β | β | β | β * | β |
| View Audit Logs | β | β | β | β | β | β | β |
| Destroy Keys | β | β ** | β | β | β | β | β |
*Development environment only
**With CISO approval
GDPR Article 32: Security of Processing
- β Encryption of personal data (keys managed per this policy)
- β Ongoing confidentiality, integrity, availability
- β Regular testing and evaluation
PCI DSS (if applicable):
- β Requirement 3.5: Protect keys against disclosure and misuse
- β Requirement 3.6: Fully document and implement key management processes
ISO 27001:
- β Control A.10.1.2: Key management
NIST SP 800-57: Recommendations for Key Management
- Followed for key strength, lifecycle, and procedures
All key management operations logged:
- Key generation (with requester, timestamp, purpose)
- Key access (application, timestamp, key ID)
- Key rotation (old version, new version, timestamp)
- Key destruction (key ID, method, authorizer)
- Failed access attempts
- Configuration changes
Implementation: Audit logs encrypted and signed (Saga Logger)
Quarterly:
- Review key access logs
- Verify key rotation schedule compliance
- Check for expired keys still in use
- Review key access permissions
Annual:
- Comprehensive key management audit
- Test master key recovery procedures
- Review and update policy
- Security assessment of key storage systems
Security Team:
- Cryptography fundamentals
- HSM/KMS operation
- Key recovery procedures
- Incident response for key compromise
Developers:
- Secure key usage in applications
- Never hardcode keys
- Use key provider interface
- Proper key lifecycle management
Operations:
- Key rotation procedures
- Monitoring and alerting
- Backup and recovery
- Incident escalation
Indicators:
- Unauthorized key access
- Key exported from HSM
- Suspicious decryption operations
- Key found in logs or repositories
Response Procedure:
- Contain: Revoke compromised key immediately
- Assess: Determine scope of compromise
- Notify: Alert CISO, security team, affected parties
- Rotate: Emergency key rotation
- Investigate: Forensic analysis
- Report: Regulatory notification if required
- Remediate: Address root cause
- Review: Post-incident analysis
Timeline:
- Detection to containment: < 15 minutes
- Complete key rotation: < 4 hours
- Incident report: Within 24 hours
- encryption_strategy.md - Encryption standards and algorithms
- INFORMATION_SECURITY_POLICY.md - Overall security framework
-
docs/encryption_metrics.md- Monitoring and metrics -
include/security/key_provider.h- Key provider interface -
src/security/field_encryption.cpp- Encryption implementation
| Version | Date | Author | Changes |
|---|---|---|---|
| 1.0 | 2026-01-11 | CISO | Initial Encryption Key Management Policy |
Drafted by: Security Team
Reviewed by: CISO, Legal, Compliance
Approved by: CTO, CEO
Effective Date: 2026-01-11
Next Review Date: 2027-01-11
Security Questions: security@themisdb.org
Key Management Issues: keymanagement@themisdb.org
Emergency Key Compromise: security-incidents@themisdb.org (24/7)
ThemisDB 1.9.0-beta Β· Home Β· Module-Index Β· GitHub Β· Issues
ThemisDB 1.9.0-beta Β· Home Β· Wiki-Index Β· Module-Index Β· FAQ Β· Quick-Reference Β· GitHub Β· Issues Β· Discussions Β· License
- Batch Operations
- Best Practices
- CRUD Tutorial
- Custom Document Ingestion
- Getting Started Tutorial
- Interactive Examples
- Schema Design
- Video Tutorials
- AQL Reference
- AQL Examples
- AQL Overview
- AQL Feature Roadmap
- AQL Geospatial Guide
- AQL LLM Migration Guide
- AQL API
- AQL Grammar (EBNF)
- AQL Root Overview
- AQL Examples (root)
- API Reference
- API Module README
- OpenAPI Overview
- Client SDK Overview
- SDK Overview
- Operations
- Operations Overview
- Operations Runbook
- Operations Handbook
- ThemisCtl Admin Guide
- Pipeline E2E SOPs
- Deploy Overview
- Docker Overview
- Docker Hub README
- Helm Overview
- Packaging Overview
- Operator Overview
- Security Policy
- Production Hardening Checklist
- Security Hardening Guide
- Encryption Key Management
- Access Control Framework
- Zero Trust Policy
- API Authentication & Authorization
- HSM Production Setup
- PKCS11 Integration
- DSGVO / SOC2 Checklist
- Access Model Runbooks
- Access Model Dashboard
- Maturity Automation Runbook
- Access Review Automation
- Access Model Dashboard
- Access Model Runbooks
- Rights Revocation
- Dr Checklists
- Dr Testing
- Incident Response Playbook
- Incident Response Testing
- GPU Oom Recovery
- Grammar Debugging
- Metrics Scrape Troubleshooting
- Model Swap Procedure
- Quota Tuning
- Subagent Deployment
- Logging Configuration
- Content Model
- Crypto & Keys
- Feature Flags Reference
- Modular Architecture Roadmap
- Modularization Guide
- Module Architecture Index
- PostgreSQL Wire Protocol
- Query Scheduling
- Raft Consensus Design
- Resource Pooling
- Source Directory Guide
- Unified Access Model
- E1 001 Layered Retrieval Design
- E1 002 Ann Abstraction Strategy
- E1 003 Tensor Summary Types
- E1 004 Lora Package Distinction
- E1 005 Model Switch Compatibility
- E1 006 Federated Tensor Summaries
- E2 001 Evaluation Framework Design
- E2 002 Hardware Profile Strategy
- E2 003 Query Planner Routing Model
- E2 004 Approximation Governance Rules
- E2 005 Cross Layer Fallback Confidence Policy
- E3 001 Distributed Tensor Design
- E3 002 Manifest Coordination Strategy
- E3 003 Recovery And Erasure Choice
- E3 004 Tensor Fabric Infrastructure
- Contributing
- Contributing (root)
- Code of Conduct
- Support
- Maintainers
- CTest Guide
- Build Quick Reference
- Developer Wiki Index
- Build / Test / CI
- Module Index
- Branching Strategy
- Disabled Stub Policy
- Docs PR Policy
- GA Promotion Sign Off
- Github Milestones Setup
- Maturity Claim Verification Checklist
- Maturity Evidence Registry
- Merge Gate Bot Config
- Merge Gate Status Live
- Phase 1 Closure Report
- Phase Closure Policy
- Phase Dependency Graph
- Phase3 Enforcement Runbook
- Plugin Submodule Rollback
- PR Version Targeting
- PR Version Targeting Backfill
- Production Ready 2026 Delivery Plan
- Query Module Status
- Readme
- Release Promotion Gate Policy
- Release Validation Checklist
- Security Module 5671 Evidence Summary
- Sharding P6 Residual Risk Acceptance
- Sourcecode Compliance Governance
- Updates Development Status Sign Off
- Wave C Implementation Complete
- Blob Storage
- Cuda
- Ethics Ai
- Exporters
- Huggingface
- Image Analysis
- Importers
- RPC
- Scraper
- Themisdb Ai Watermark Detector
- User Storage Encrypted
- Chimera Architecture
- Chimera Future
- Chimera Readme
- Chimera Roadmap
- Covina Fastapi Ingestion Architecture
- Covina Fastapi Ingestion Future
- Covina Fastapi Ingestion Roadmap
- Vcc Base Architecture
- Vcc Base Future
- Vcc Base Roadmap
- Vcc Clara Ingestion Architecture
- Vcc Clara Ingestion Future
- Vcc Clara Ingestion Roadmap
- Vcc Veritas Architecture
- Vcc Veritas Future
- Vcc Veritas Roadmap
- 01 Hello World
- 02 Todo App
- 03 Contact Manager
- 04 Inventory System
- 05 Time Series Monitor
- 06 Graph Social Network
- 07 Vector Search Documents
- 08 Dms Erp System
- 09 Iot Sensor Network
- 10 Drone Image Analysis
- 11 Blog Wiki
- 12 Expense Tracker
- 13 Recipe Manager
- 14 Ecommerce Catalog
- 15 Event Management
- 16 Kanban Board
- 17 Crm
- 18 Realtime Chat
- 19 Recommendation Engine
- 20 Smart Home
- 21 Coding Platform
- 22 AQL Diagram Tool
- 23 Traveling Salesman
- 24 Moral Philosophy Debates
- API Versioning
- Distributed Sharding
- Feedback Plugins
- Geo
- Gnn
- Image Analysis
- Legal Lora Training
- LLM
- Lora Sync
- Migration
- Nlp
- Performance
- Railway
- Replication
- Rope Visualization
- Sample Product Config
- Security
- Client SDK Overview
- Quickstart
- Sdk Enhancements
- Sdk Implementation Summary
- Test Suite Readme
- Go
- Java
- Javascript
- Php
- Python
- Ruby
- Rust
- Typescript
- 01 Grundlegende Operationen
- 02 AQL Queries
- 03 Graph Daten
- 04 Multimodell Anwendung
- 01 Quickstart Guide
- 02 AQL Referenz Kurzuebersicht
- 03 Datenmodellierung Guide
- 04 Uebungsaufgaben
- 05 Best Practices Guide
- Training Documents
- Training Overview
- 01 Einfuehrung Und Uebersicht
- 02 Datenmodelle Und Architektur
- 03 AQL Abfragesprache
- 04 Installation Und Setup
- 05 Anwendungsbeispiele
- Training Presentations
- Dependencies Readme
- Processmonitor Readme
- Themis.admintools.shared Readme
- Themis.aqlquerybuilder Readme
- Themis.aqlquerybuilder Roadmap
- Themis.auditlogviewer Readme
- Themis.auditlogviewer Roadmap
- Themis.classificationdashboard Readme
- Themis.classificationdashboard Roadmap
- Themis.compliancereports Readme
- Themis.compliancereports Roadmap
- Themis.gisviewer.controlpanel Readme
- Themis.gisviewer.controlpanel Roadmap
- Themis.impactanalysisviewer Readme
- Themis.impactanalysisviewer Roadmap
- Themis.ingestiontool Readme
- Themis.ingestiontool Roadmap
- Themis.keyrotationdashboard Readme
- Themis.keyrotationdashboard Roadmap
- Themis.piimanager Readme
- Themis.piimanager Roadmap
- Themis.retentionmanager Readme
- Themis.retentionmanager Roadmap
- Themis.sagaverifier Readme
- Themis.sagaverifier Roadmap
- Themis.usbadmintool Readme
- Themis.usbadmintool Roadmap
- CI Readme
- CI Roadmap
- Compiler Diagnostics Readme
- Compiler Diagnostics Roadmap
- Completion Readme
- Copilot Ollama Router Readme
- Copilot Ollama Router Roadmap
- Gnn Readme
- Gnn Roadmap
- Rope Visualizer Readme
- Rope Visualizer Roadmap
- Tco Calculator Readme
- Tco Calculator Roadmap
- Tests Readme
- Tests Roadmap
- Themis Config Wx Readme
- Themis Docs Builder Readme
- Wikipedia Ingestion Readme