|
| 1 | +# CloudTrail trail logging S3 object-level data events |
| 2 | +resource "aws_cloudtrail" "s3_data_events" { |
| 3 | + # checkov:skip=CKV_AWS_252: Justification: No CMK required by design; default SSE-S3 encryption is sufficient. |
| 4 | + # checkov:skip=CKV2_AWS_10: Justification: CloudWatch Logs integration is not required for this S3 data events trail. |
| 5 | + name = "${local.resource_prefix}-${var.cloudtrail_trail_name}" |
| 6 | + |
| 7 | + s3_bucket_name = module.cloudtrail_s3_bucket.s3_bucket_id |
| 8 | + |
| 9 | + # Regional, non-aggregated trail (same region delivery, no multi-region) |
| 10 | + is_multi_region_trail = false |
| 11 | + include_global_service_events = false |
| 12 | + |
| 13 | + # Requirement: log file validation |
| 14 | + enable_log_file_validation = true |
| 15 | + |
| 16 | + # S3 object-level write events — satisfies [S3.22] |
| 17 | + advanced_event_selector { |
| 18 | + name = "Log S3 object-level write events (S3.22)" |
| 19 | + |
| 20 | + field_selector { |
| 21 | + field = "eventCategory" |
| 22 | + equals = ["Data"] |
| 23 | + } |
| 24 | + |
| 25 | + field_selector { |
| 26 | + field = "resources.type" |
| 27 | + equals = ["AWS::S3::Object"] |
| 28 | + } |
| 29 | + |
| 30 | + field_selector { |
| 31 | + field = "readOnly" |
| 32 | + equals = ["false"] |
| 33 | + } |
| 34 | + |
| 35 | + # Exclude the CloudTrail delivery bucket itself to prevent a feedback loop |
| 36 | + field_selector { |
| 37 | + field = "resources.ARN" |
| 38 | + not_starts_with = ["${module.cloudtrail_s3_bucket.s3_bucket_arn}/"] |
| 39 | + } |
| 40 | + } |
| 41 | + |
| 42 | + # S3 object-level read events — satisfies [S3.23] |
| 43 | + advanced_event_selector { |
| 44 | + name = "Log S3 object-level read events (S3.23)" |
| 45 | + |
| 46 | + field_selector { |
| 47 | + field = "eventCategory" |
| 48 | + equals = ["Data"] |
| 49 | + } |
| 50 | + |
| 51 | + field_selector { |
| 52 | + field = "resources.type" |
| 53 | + equals = ["AWS::S3::Object"] |
| 54 | + } |
| 55 | + |
| 56 | + field_selector { |
| 57 | + field = "readOnly" |
| 58 | + equals = ["true"] |
| 59 | + } |
| 60 | + |
| 61 | + # Exclude the CloudTrail delivery bucket itself to prevent a feedback loop |
| 62 | + field_selector { |
| 63 | + field = "resources.ARN" |
| 64 | + not_starts_with = ["${module.cloudtrail_s3_bucket.s3_bucket_arn}/"] |
| 65 | + } |
| 66 | + } |
| 67 | +} |
0 commit comments