AWS CloudTrail Configuration
CloudTrail records API activity across an AWS account, providing audit trails for security analysis, compliance, and operational troubleshooting. This guide covers trail configuration, log validation, encryption, and integration with monitoring services.
Quick Start
Create a multi-region trail with default settings:
aws cloudtrail create-trail \
--name organization-trail \
--s3-bucket-name my-cloudtrail-logs \
--is-multi-region-trail \
--include-global-service-events \
--enable-log-file-validation
# Start logging
aws cloudtrail start-logging --name organization-trail CloudTrail begins recording API activity immediately. An S3 bucket with appropriate permissions is required before creating the trail. See the AWS CloudTrail documentation for complete setup details.
Trail Types
CloudTrail supports different trail configurations:
| Trail Type | Scope | Use Case |
|---|---|---|
| Single-Region Trail | One region | Region-specific compliance requirements |
| Multi-Region Trail | All regions | Comprehensive audit logging (recommended) |
| Organization Trail | All accounts in organization | Centralized logging for AWS Organizations |
Configuration Options
Standard Multi-Region Trail
Recommended configuration for single-account environments:
resource "aws_cloudtrail" "main" {
name = "organization-trail"
s3_bucket_name = aws_s3_bucket.cloudtrail_logs.id
is_multi_region_trail = true
include_global_service_events = true
enable_log_file_validation = true
kms_key_id = aws_kms_key.cloudtrail.arn
cloud_watch_logs_group_arn = "${aws_cloudwatch_log_group.cloudtrail.arn}:*"
cloud_watch_logs_role_arn = aws_iam_role.cloudtrail_cloudwatch.arn
tags = {
Environment = "production"
ManagedBy = "terraform"
}
} Organization Trail
Centralized logging for AWS Organizations:
resource "aws_cloudtrail" "organization" {
name = "organization-trail"
s3_bucket_name = aws_s3_bucket.cloudtrail_logs.id
is_organization_trail = true
is_multi_region_trail = true
include_global_service_events = true
enable_log_file_validation = true
kms_key_id = aws_kms_key.cloudtrail.arn
tags = {
Environment = "production"
ManagedBy = "terraform"
}
} Key Configuration Options
| Option | Description | Recommendation |
|---|---|---|
is_multi_region_trail | Record events from all regions | Enable (required for CIS compliance) |
include_global_service_events | Include IAM, STS, CloudFront events | Enable |
enable_log_file_validation | Create digest files for integrity verification | Enable (required for CIS compliance) |
is_organization_trail | Apply trail to all organization accounts | Enable for multi-account environments |
Event Types
CloudTrail captures different categories of events:
Data Event Configuration
Data events require explicit configuration and incur additional costs:
resource "aws_cloudtrail" "main" {
# ... base configuration ...
event_selector {
read_write_type = "All"
include_management_events = true
data_resource {
type = "AWS::S3::Object"
values = ["arn:aws:s3:::sensitive-bucket/"]
}
}
event_selector {
read_write_type = "All"
include_management_events = true
data_resource {
type = "AWS::Lambda::Function"
values = ["arn:aws:lambda"]
}
}
} Log File Validation
Log file validation ensures log integrity through digest files:
- Digest files: Created hourly with SHA-256 hashes of log files
- Chain of custody: Each digest references the previous digest
- Tamper detection: Validates logs have not been modified or deleted
# Validate log file integrity
aws cloudtrail validate-logs \
--trail-arn arn:aws:cloudtrail:us-east-1:123456789012:trail/organization-trail \
--start-time 2024-01-01T00:00:00Z \
--end-time 2024-01-31T23:59:59Z Encryption
CloudTrail supports encryption with AWS KMS:
| Encryption Type | Description | Use Case |
|---|---|---|
| SSE-S3 | S3-managed keys (default) | Basic encryption requirements |
| SSE-KMS | Customer-managed KMS keys | Compliance requirements, key rotation control |
KMS Key Policy Requirements
The KMS key policy must grant CloudTrail permission to encrypt logs:
kms:GenerateDataKey*- Generate data keys for encryptionkms:Decrypt- Decrypt logs when accessedkms:DescribeKey- Describe key metadata
CloudWatch Integration
Stream CloudTrail logs to CloudWatch Logs for real-time monitoring:
Common Metric Filters
| Event | Filter Pattern |
|---|---|
| Root account usage | {$.userIdentity.type = "Root"} |
| Console login without MFA | {$.eventName = "ConsoleLogin" && $.additionalEventData.MFAUsed != "Yes"} |
| IAM policy changes | {$.eventName = "Put*Policy" || $.eventName = "Delete*Policy"} |
| Security group changes | {$.eventName = "AuthorizeSecurityGroup*" || $.eventName = "RevokeSecurityGroup*"} |
| Network ACL changes | {$.eventName = "*NetworkAcl*"} |
Multi-Account Setup
For AWS Organizations, create an organization trail in the management account:
# Create organization trail (from management account)
aws cloudtrail create-trail \
--name organization-trail \
--s3-bucket-name central-cloudtrail-logs \
--is-organization-trail \
--is-multi-region-trail Recommended Architecture
- Management Account: Creates and manages the organization trail
- Log Archive Account: Hosts the S3 bucket for centralized log storage
- Member Accounts: Automatically included in organization trail logging
Cost Considerations
CloudTrail pricing components:
| Component | Pricing | Notes |
|---|---|---|
| First management trail | Free | One free copy of management events per region |
| Additional management trails | $2.00 per 100,000 events | Additional copies of management events |
| Data events | $0.10 per 100,000 events | S3 object, Lambda invocation logging |
| CloudTrail Insights | $0.35 per 100,000 events analyzed | Anomaly detection |
| S3 storage | Standard S3 pricing | Log storage and retrieval costs |
Integration Points
CloudTrail provides foundational logging for other AWS security services:
Next Steps
- Enable GuardDuty to analyze CloudTrail events for threats
- Configure Security Hub CIS standards requiring CloudTrail
- Set up CloudWatch metric filters for security-relevant events
- Configure EventBridge rules for real-time alerting