turbot/tailpipe-mod-aws-cloudtrail-log-detections

Detection: S3 Bucket Policy Granted Public Access

Overview

Detect when public access was granted to an S3 bucket by modifying its policy. Public access to S3 buckets exposes sensitive data to unauthorized users, increasing the risk of data breaches or misuse. Restricting public access ensures data confidentiality and integrity while maintaining compliance with security best practices.

References:

Usage

Run the detection in your terminal:

powerpipe detection run aws_cloudtrail_log_detections.detection.s3_bucket_policy_granted_public_access

Snapshot and share results via Turbot Pipes:

powerpipe login
powerpipe detection run aws_cloudtrail_log_detections.detection.s3_bucket_policy_granted_public_access --share

SQL

This detection uses a named query:

select
tp_timestamp as timestamp,
string_split(event_source, '.')[1] || ':' || event_name as operation,
request_parameters ->> 'bucketName' as resource,
user_identity.arn as actor,
tp_source_ip as source_ip,
tp_index as account_id,
aws_region as region,
tp_id as source_id,
*
from
aws_cloudtrail_log
where
event_source = 's3.amazonaws.com'
and event_name = 'PutBucketPolicy'
and (json_contains(request_parameters -> 'bucketPolicy', '{"Principal": "*"}')
or json_contains(request_parameters -> 'bucketPolicy', '{"Principal": {"AWS": "*"}}'))
and json_contains(request_parameters -> 'bucketPolicy', '{"Effect": "Allow"}')
and error_code is null
order by
event_time desc;

Tags