LogGuardian applies KMS encryption to CloudWatch log groups with comprehensive safety checks to prevent breaking application access while ensuring compliance.
CloudWatch log group encryption with KMS keys can fail catastrophically if:
- Keys don't exist or are inaccessible in the target region
- Key policies don't allow CloudWatch Logs service access
- Keys are disabled or pending deletion
- Cross-region permissions are misconfigured
LogGuardian prevents these failures through comprehensive pre-validation.
Implementation: See validateKMSKeyAccessibility() and related functions in internal/service/compliance.go
- Existence Check - Verifies key exists and is accessible
- State Validation - Ensures key is enabled and usable
- Policy Verification - Confirms CloudWatch Logs service permissions
- Cross-Region Detection - Identifies and warns about cross-region usage
- Retry Logic - Handles transient failures with exponential backoff
LogGuardian automatically detects cross-region KMS keys and provides appropriate warnings while still allowing the operation.
Environment Configuration:
# Global fallback key
KMS_KEY_ALIAS="alias/cloudwatch-logs-global"
# Region-specific KMS keys
KMS_KEY_ALIAS_CA_CENTRAL_1="alias/cloudwatch-logs-central"
KMS_KEY_ALIAS_CA_WEST_1="alias/cloudwatch-logs-west"LogGuardian provides comprehensive structured logging for all KMS operations for compliance and troubleshooting.
Implementation: All audit logging is handled in the service layer with structured JSON output.
- Encryption Success - Successful KMS key association
- Validation Failures - Key not found, access denied, policy issues
- Cross-Region Usage - Warnings when using keys across regions
- Retry Operations - Exponential backoff retry attempts
Successful Encryption:
{
"level": "INFO",
"msg": "Successfully applied KMS encryption",
"log_group": "/aws/lambda/my-function",
"kms_key_id": "12345678-1234-1234-1234-123456789012",
"operation": "associate_kms_key",
"timestamp": "2025-07-30T12:00:00Z"
}Cross-Region Warning:
{
"level": "WARN",
"msg": "KMS key is in different region than current",
"kms_key_alias": "alias/cloudwatch-logs-compliance",
"key_region": "ca-west-1",
"current_region": "ca-central-1",
"audit_action": "cross_region_key_usage"
}Your KMS key policy must include CloudWatch Logs service permissions:
{
"Effect": "Allow",
"Principal": {"Service": "logs.amazonaws.com"},
"Action": [
"kms:Encrypt", "kms:Decrypt", "kms:ReEncrypt*",
"kms:GenerateDataKey*", "kms:DescribeKey"
],
"Resource": "*"
}The Lambda execution role needs:
kms:Describe*,kms:GetKeyPolicyfor validationlogs:AssociateKmsKeyfor applying encryption
Reference: See Architecture Overview for complete security configuration.
- Use Region-Specific Keys - Avoid cross-region charges and latency
- Pre-validate Keys - Test KMS key access before deploying LogGuardian
- Monitor Failures - Set up CloudWatch alarms for KMS validation failures
- Audit Regularly - Review KMS usage logs for compliance
Troubleshooting: Common issues and solutions are logged with actionable error messages. Check CloudWatch Logs for detailed failure reasons.