Expand description
Key Management Service (KMS) abstraction.
Provides a vendor-agnostic interface for external KMS integration:
- AWS KMS - Amazon’s managed KMS
- HashiCorp Vault - Open-source secrets management
- GCP Cloud KMS - Google’s managed KMS
- Azure Key Vault - Microsoft’s managed KMS
- Local/Env - For development only (keys from environment)
§Architecture
This module uses envelope encryption:
┌─────────────────────────────────────────────────────────────┐
│ Envelope Encryption │
├─────────────────────────────────────────────────────────────┤
│ │
│ ┌──────────┐ encrypts ┌──────────┐ │
│ │ Master │ ─────────────▶ │ Data │ │
│ │ Key │ │Encryption│ │
│ │ (KEK) │ ◀───────────── │ Key │ │
│ └──────────┘ decrypts │ (DEK) │ │
│ │ └──────────┘ │
│ │ stored in │ │
│ ▼ │ encrypts │
│ ┌──────────┐ ▼ │
│ │ KMS │ ┌──────────┐ │
│ │(AWS/GCP/ │ │ Data │ │
│ │ Vault) │ │(metadata,│ │
│ └──────────┘ │ API keys)│ │
│ └──────────┘ │
└─────────────────────────────────────────────────────────────┘Benefits of envelope encryption:
- Master key never leaves KMS (hardware-backed security)
- DEKs can be cached locally (reduced latency)
- Key rotation only requires re-encrypting DEKs, not all data
- Reduced KMS API calls (cost optimization)
§Security Properties
- Master keys are stored in external KMS (never in memory long-term)
- DEKs are cached with configurable TTL (default: 5 minutes)
- All key material uses
SecretByteswith zeroize-on-drop - Key versioning supports seamless rotation
- All operations are instrumented with tracing spans
- Retry logic with exponential backoff for transient failures
Structs§
- Cache
Stats - Cache statistics for monitoring.
- Cached
Kms - Cached wrapper around a KMS provider.
- Circuit
Breaker Config - Configuration for circuit breaker behavior.
- Circuit
Breaker Kms - Circuit breaker wrapper around a KMS provider.
- Data
Encryption Key - Data Encryption Key (DEK) with metadata.
- Encrypted
Envelope - Helper for envelope encryption operations.
- Encryption
Context - Encryption context provides additional authenticated data (AAD).
- EnvKey
Provider - KMS provider that loads keys from environment variables.
- KeyRotation
Manager - Manager for coordinating key rotation across the system.
- KeyRotation
Result - Result of a key rotation operation.
- KmsAudit
Event - Audit event for KMS operations.
- KmsCache
Config - Configuration for KMS caching.
- KmsMetrics
- Metrics for KMS operations.
- KmsMetrics
Snapshot - Snapshot of KMS metrics at a point in time.
- Resilient
KmsConfig - Configuration for a production-grade resilient KMS stack.
- Retry
Config - Configuration for retry behavior on transient KMS failures.
- Retry
Kms - KMS wrapper that adds retry logic with exponential backoff.
Enums§
- Circuit
State - State of the circuit breaker.
- KmsConfig
- Configuration for KMS providers.
- KmsError
- Errors that can occur during KMS operations.
- KmsOperation
- Types of KMS operations for auditing.
- Vault
Auth - Vault authentication methods.
Traits§
- KeyManagement
Service - Key Management Service trait.
Functions§
- create_
kms - Creates a KMS provider from configuration.
- create_
resilient_ kms - Creates a resilient KMS stack with layered protection.