Control: 3.8 Ensure that Object-level logging for write events is enabled for S3 bucket
Description
S3 object-level API operations such as GetObject, DeleteObject, and PutObject are called data events. By default, CloudTrail trails don't log data events and so it is recommended to enable Object-level logging for S3 buckets.
Enabling object-level logging will help you meet data compliance requirements within your organization, perform comprehensive security analysis, monitor specific patterns of user behavior in your AWS account or take immediate actions on any object-level API activity within your S3 Buckets using Amazon CloudWatch Events.
Remediation
From Console:
- Login to the AWS Management Console and navigate to S3 dashboard at https://console.aws.amazon.com/s3/.
- In the left navigation panel, click
bucketsand then click on the S3 Bucket Name that you want to examine. - Click
Propertiestab to see in detail bucket configuration. - In the
AWS Cloud Trail data events' section select the CloudTrail name for the recording activity. You can choose an existing Cloudtrail or create a new one by slicking theConfigure in Cloudtrailbutton or navigating to the Cloudtrail console linkhttps://console.aws.amazon.com/cloudtrail/ - Once the Cloudtrail is selected, Select the data
Data Eventscheck box. - Select
S3from the `Data event type drop down. - Select
Log all eventsfrom theLog selector templatedrop down. - Repeat steps 2 to 5 to enable object-level logging of write events for other S3 buckets.
From Command Line:
- To enable
object-leveldata events logging for S3 buckets within your AWS account, runput-event-selectorscommand using the name of the trail that you want to reconfigure as identifier:
aws cloudtrail put-event-selectors --region <region-name> --trail-name <trail-name> --event-selectors '[{ "ReadWriteType": "WriteOnly", "IncludeManagementEvents":true, "DataResources": [{ "Type": "AWS::S3::Object", "Values": ["arn:aws:s3:::<s3-bucket-name>/"] }] }]'
- The command output will be
object-levelevent trail configuration. - If you want to enable it for all buckets at once then change Values parameter to
["arn:aws:s3"]in command given above. - Repeat step 1 for each s3 bucket to update
object-levellogging of write events. - Change the AWS region by updating the
--regioncommand parameter and perform the process for other regions.
Usage
Run the control in your terminal:
powerpipe control run aws_compliance.control.cis_v300_3_8Snapshot and share results via Turbot Pipes:
powerpipe loginpowerpipe control run aws_compliance.control.cis_v300_3_8 --shareSQL
This control uses a named query:
with s3_selectors as( select name as trail_name, is_multi_region_trail, bucket_selector from aws_cloudtrail_trail, jsonb_array_elements(event_selectors) as event_selector, jsonb_array_elements(event_selector -> 'DataResources') as data_resource, jsonb_array_elements_text(data_resource -> 'Values') as bucket_selector where is_multi_region_trail and data_resource ->> 'Type' = 'AWS::S3::Object' and event_selector ->> 'ReadWriteType' in ( 'WriteOnly', 'All' ))select b.arn as resource, case when count(bucket_selector) > 0 then 'ok' else 'alarm' end as status, case when count(bucket_selector) > 0 then b.name || ' object-level write events logging enabled.' else b.name || ' object-level write events logging disabled.' end as reason , region, account_idfrom aws_s3_bucket as b left join s3_selectors on bucket_selector like (b.arn || '%') or bucket_selector = 'arn:aws:s3'group by b.account_id, b.region, b.arn, b.name, b.tags, b._ctx;