Description
S3 server access logs record requests to buckets and objects. For object operations you need to audit, also consider CloudTrail data events.
Potential impact
Late or missing records can make a download or deletion hard to trace.
Remediation
- Configure
aws_s3_bucket_loggingwith a separate destination bucket in the same AWS account and Region. If its ACLs are disabled, grant log delivery through the bucket policy. - Restrict read and delete access to the logs, set retention, and verify that log objects arrive.
Examples
The examples use AWS provider 3.x inline syntax. mfa_delete = true reflects existing MFA Delete settings. Enabling MFA Delete requires a separate AWS operation.
Before
hcl
resource "aws_s3_bucket" "example" {
bucket = "my-tf-test-bucket"
acl = "private"
tags = {
Name = "My bucket"
Environment = "Dev"
}
versioning {
mfa_delete = true
}
}
After
hcl
resource "aws_s3_bucket" "example" {
bucket = "my-tf-test-bucket"
acl = "private"
tags = {
Name = "My bucket"
Environment = "Dev"
}
logging {
target_bucket = "logs"
}
versioning {
mfa_delete = true
}
}
The added logging block sends server access logs to the logs bucket.