This rule ensures that server access logging is enabled for S3 buckets. Non-compliance may lead to security risks.
Rule | S3 bucket server access logging should be enabled |
Framework | AWS Foundational Security Best Practices |
Severity | ✔ Medium |
S3 Bucket Server Access Logging
Description:
Enabling server access logging for your S3 bucket is an essential security best practice recommended by AWS.
When server access logging is enabled, Amazon S3 automatically records detailed information about every request made to your bucket. This includes the source IP address, the request time, the requested action, and the response status and error codes. This logging data provides valuable insights for security monitoring, auditing, and troubleshooting purposes.
Remediation:
To enable server access logging for your S3 bucket, follow these steps:
Troubleshooting:
Server Access Logging not enabled:
If you are unable to enable server access logging for your S3 bucket, please ensure that you have the necessary permissions. To enable server access logging, your IAM user or role should have the
s3:PutBucketLogging
permission on the respective bucket.Invalid Target Bucket:
If you encounter an error indicating an invalid target bucket while enabling server access logging, ensure that the target bucket exists in the same AWS account and is in an accessible region. Also, verify that the IAM user or role has the necessary permissions to write to the target bucket by granting the
s3:PutObject
permission.Log File Prefix Issues:
If you experience any issues setting the log file prefix, make sure it follows the correct format. The prefix should be a valid object key prefix. You can use forward slashes ("/") to create a folder structure within the bucket and organize your logs accordingly.
Additional Considerations:
Code Samples:
There are no specific code samples required for enabling server access logging, as the process is performed through the AWS Management Console. However, if you prefer to use the AWS CLI, you can enable server access logging using the following command:
aws s3api put-bucket-logging --bucket <bucket-name> --logging-configuration '{"LoggingEnabled":{"TargetBucket":"<target-bucket-name>","TargetPrefix":"<log-file-prefix>"}}'
Note: Replace
<bucket-name>
with the name of your bucket, <target-bucket-name>
with the name of the target bucket, and <log-file-prefix>
with the desired log file prefix.For IAM permissions, ensure that the user or role executing the command has the necessary permissions to perform
s3:PutBucketLogging
and s3:PutObject
actions on the respective buckets.