Commit 96f2c0c
feat: Complete encryption key management system v1.10.0
- Implement comprehensive encryption key lifecycle management with secure storage, rotation, and retirement
- Add KeyManager<DB> with full PostgreSQL and MySQL support for enterprise-grade key operations
- Support for multiple encryption algorithms: AES-256-GCM and ChaCha20-Poly1305 with configurable key strengths
- Master key encryption (KEK) system ensuring data encryption keys are never stored in plaintext
- Automatic key rotation with configurable intervals and next rotation scheduling
- Key versioning system supporting up to configurable maximum versions per key ID
- Secure key derivation using Argon2 with customizable memory cost, time cost, and parallelism parameters
Database Schema and Migration Support:
- New hammerwork_encryption_keys table with comprehensive metadata tracking and optimized indexes
- New hammerwork_key_audit_log table for complete audit trail of all key operations
- Database migration files for both PostgreSQL (013_add_key_audit.postgres.sql) and MySQL (013_add_key_audit.mysql.sql)
- Proper constraint validation ensuring data integrity and encryption consistency
- Optimized indexes for key lookup, rotation queries, expiration tracking, and audit log searches
Advanced Key Operations:
- store_key() and load_key() operations with automatic encryption and version management
- retire_key_version() for secure key retirement while maintaining decryption capabilities
- cleanup_old_key_versions() with configurable retention policies preventing key sprawl
- get_keys_due_for_rotation() for automated rotation scheduling and compliance
- record_key_usage() with comprehensive usage statistics and last access tracking
- record_audit_event() providing complete audit trails for compliance and security monitoring
Security and Compliance Features:
- External Key Management Service (KMS) integration support for AWS KMS, Azure Key Vault, HashiCorp Vault
- Key source management supporting environment variables, static keys, generated keys, and external services
- Comprehensive audit logging with operation type, success/failure tracking, and error message capture
- Key purpose categorization: Encryption, MAC (Message Authentication Code), and KEK (Key Encryption Key)
- Key status management: Active, Retired, Revoked, and Expired with proper lifecycle transitions
- Configurable key expiration, rotation intervals, and automated cleanup policies
Key Management Statistics and Monitoring:
- KeyManagerStats providing comprehensive metrics: total keys, active/retired/revoked/expired counts
- Key usage analytics: total access operations, rotations performed, average key age
- Proactive monitoring: keys expiring soon alerts and rotation due notifications
- Performance metrics and key management health indicators
Configuration and Flexibility:
- KeyManagerConfig with fluent builder pattern for easy configuration management
- Support for auto-rotation with configurable intervals and maximum key version limits
- Audit logging enable/disable with comprehensive event tracking
- External KMS configuration with service type, endpoint, authentication, and namespace support
- Key derivation configuration with Argon2 parameter tuning for security vs. performance optimization
Testing and Quality:
- Added 20 comprehensive unit tests covering all key management functionality
- Error handling tests validating robust parsing and graceful failure modes
- Database operation tests ensuring proper integration with both PostgreSQL and MySQL
- Configuration validation tests for all builder patterns and default values
- Serialization/deserialization tests ensuring cross-system compatibility
Code Quality and Maintainability:
- Exposed parsing helper functions (parse_algorithm, parse_key_source, parse_key_purpose, parse_key_status) for extensibility
- Implemented Display traits for all key management enums enabling human-readable output
- Added comprehensive error types and messages for debugging and troubleshooting
- Proper feature flag isolation ensuring encryption functionality is optional and self-contained
🤖 Generated with [Claude Code](https://claude.ai/code)
Co-Authored-By: Claude <[email protected]>1 parent af64389 commit 96f2c0c
File tree
9 files changed
+1977
-236
lines changed- src
- encryption
- migrations
- queue
- tests
9 files changed
+1977
-236
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
5 | 5 | | |
6 | 6 | | |
7 | 7 | | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
8 | 77 | | |
9 | 78 | | |
10 | 79 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
9 | 9 | | |
10 | 10 | | |
11 | 11 | | |
12 | | - | |
| 12 | + | |
13 | 13 | | |
14 | 14 | | |
15 | 15 | | |
| |||
19 | 19 | | |
20 | 20 | | |
21 | 21 | | |
22 | | - | |
| 22 | + | |
23 | 23 | | |
24 | 24 | | |
25 | 25 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
60 | 60 | | |
61 | 61 | | |
62 | 62 | | |
63 | | - | |
| 63 | + | |
| 64 | + | |
64 | 65 | | |
65 | 66 | | |
66 | 67 | | |
| |||
0 commit comments