Control: S3 Block Public Access setting should be enabled at the bucket level
Description
This control checks whether S3 buckets have bucket-level public access blocks applied.
Usage
Run the control in your terminal:
powerpipe control run terraform_aws_compliance.control.s3_bucket_public_access_blocked
Snapshot and share results via Turbot Pipes:
powerpipe loginpowerpipe control run terraform_aws_compliance.control.s3_bucket_public_access_blocked --share
SQL
This control uses a named query:
select address as resource, case when (attributes_std ->> 'block_public_acls')::boolean and (attributes_std ->> 'block_public_policy')::boolean and (attributes_std ->> 'ignore_public_acls')::boolean and (attributes_std ->> 'restrict_public_buckets')::boolean then 'ok' else 'alarm' end as status, case when attributes_std -> 'block_public_acls' is null or attributes_std -> 'block_public_policy' is null or attributes_std -> 'ignore_public_acls' is null or attributes_std -> 'restrict_public_buckets' is null then concat_ws(', ', case when attributes_std -> 'block_public_acls' is null then 'block_public_acls' end, case when attributes_std -> 'block_public_policy' is null then 'block_public_policy' end, case when attributes_std -> 'ignore_public_acls' is null then 'ignore_public_acls' end, case when attributes_std -> 'restrict_public_buckets' is null then 'restrict_public_buckets' end ) || ' not defined' when (attributes_std ->> 'block_public_acls')::boolean and (attributes_std ->> 'block_public_policy')::boolean and (attributes_std ->> 'ignore_public_acls')::boolean and (attributes_std ->> 'restrict_public_buckets')::boolean then 'Public access blocks enabled' else 'Public access not enabled for: ' || concat_ws(', ', case when not ((attributes_std ->> 'block_public_acls')::boolean) then 'block_public_acls' end, case when not ((attributes_std ->> 'block_public_policy')::boolean) then 'block_public_policy' end, case when not ((attributes_std ->> 'ignore_public_acls')::boolean ) then 'ignore_public_acls' end, case when not ((attributes_std ->> 'restrict_public_buckets')::boolean) then 'restrict_public_buckets' end ) end || '.' as reason , path || ':' || start_linefrom terraform_resourcewhere type = 'aws_s3_bucket_public_access_block';