Description
S3 server access logs describe requests to the CloudTrail storage bucket itself. For an audit of selected object operations, also review CloudTrail data events.
Potential impact
Missing access records make it harder to investigate attempts to read or delete audit logs. S3 server access records can arrive late or be missing.
Remediation
On the bucket already storing the trail’s files, replace inline logging with aws_s3_bucket_logging. Use a separate destination bucket in the same account and Region. Allow delivery in the destination policy when ACLs are disabled. Verify new records and check access, retention and deletion protection on both buckets.
Examples
These AWS provider 3.x examples use inline logging and ACLs. Supply your bucket names and CloudTrail delivery policy. Review force_destroy = true before applying changes to a bucket with retained logs.
Before
resource "aws_cloudtrail" "example" {
name = "tf-trail-foobar"
s3_bucket_name = aws_s3_bucket.foo.id
s3_key_prefix = "prefix"
include_global_service_events = false
}
resource "aws_s3_bucket" "foo" {
bucket = "tf-test-trail"
force_destroy = true
}
After
resource "aws_cloudtrail" "example" {
name = "tf-trail-foobar"
s3_bucket_name = aws_s3_bucket.foo2.id
s3_key_prefix = "prefix"
include_global_service_events = false
}
resource "aws_s3_bucket" "log_bucket" {
bucket = "my-tf-log-bucket"
acl = "log-delivery-write"
}
resource "aws_s3_bucket" "foo2" {
bucket = "my-tf-test-bucket"
acl = "private"
logging {
target_bucket = aws_s3_bucket.log_bucket.id
target_prefix = "log/"
}
}
The second example also changes the trail’s storage bucket from foo to foo2. To add logging in place, keep the existing bucket and trail reference. log/ is the prefix for server access logs in log_bucket.