AWS

Tutorials

Finding Potentially Public AWS S3 Buckets

If you are utilizing AWS S3 in your cloud environments, you may want to know which buckets are not configured correctly to block public access. Use CloudQuery to export your data from AWS to PostgreSQL and ensure that the aws_s3_buckets and aws_s3_bucket_public_access_blocks tables are included in your AWS source configuration. Once you have synced this data to your PostgreSQL database, here’s how to view any potentially publicly accessible S3 buckets:

select
b.account_id,
b.arn,
b.name as bucket_name,
b.creation_date,
b.region as bucket_region,
b.tags,
CASE when
-- check that all public access block configurations are true
((pab.public_access_block_configuration -> 'BlockPublicAcls')::boolean
or (pab.public_access_block_configuration -> 'IgnorePublicAcls')::boolean
or (pab.public_access_block_configuration -> 'BlockPublicPolicy')::boolean
or (pab.public_access_block_configuration -> 'RestrictPublicBuckets')::boolean)
-- check if s3 bucket policy status 'IsPublic' is set to false
or b.policy_status ->> 'IsPublic' = 'false'
THEN true ELSE false
END AS public_access_blocked
FROM
aws_s3_buckets b
LEFT JOIN
aws_s3_bucket_public_access_blocks pab on pab._cq_parent_id = b._cq_id

This query will yield a result that looks like this:

account_idarnbucket_namecreation_datebucket_regiontagspublic_access_blocked
1234567890arn:aws:s3:::test_bucket_1test_bucket_12024-03-01 15:34:05us-east-1{"tag":"test-value"}true
1234567890arn:aws:s3:::test_bucket_2test_bucket_22023-05-03 11:42:07us-east-1{"tag":"test-value"}false

This query leverages PostgreSQL built-in JSON functions to parse the AWS configuration fields which are stored as jsonb data types. It first checks that all public access blocks are configured properly and then checks that the S3 bucket policy is not public. If all public access blocks are configured then the query will return true in the public_access_blocked field, meaning you can target only those that return false when reviewing your cloud security configurations.

You can also use this query to search for specific S3 buckets by tag, to do that we will keep the above query and after the final line we can add a WHERE clause to target specifically tagged buckets. For example, let’s say you want to grab all buckets tagged with a specific EUID, you can use the following query:

select
b.account_id,
b.arn,
b.name as bucket_name,
b.creation_date,
b.region as bucket_region,
b.tags,
CASE when
-- check that all public access block configurations are true
((pab.public_access_block_configuration -> 'BlockPublicAcls')::boolean
or (pab.public_access_block_configuration -> 'IgnorePublicAcls')::boolean
or (pab.public_access_block_configuration -> 'BlockPublicPolicy')::boolean
or (pab.public_access_block_configuration -> 'RestrictPublicBuckets')::boolean)
-- check if s3 bucket policy status 'IsPublic' is set to false
or b.policy_status ->> 'IsPublic' = 'false'
THEN false ELSE true
END AS public_access_blocked
FROM
aws_s3_buckets b
LEFT JOIN
aws_s3_bucket_public_access_blocks pab on pab._cq_parent_id = b._cq_id
WHERE
b.tags ->> 'EUID' = 'EUID1'

This query will yield a slightly different result, note the EUID in the tags field:

account_idarnbucket_namecreation_datebucket_regiontagspublic_access_blocked
7890123456arn:aws:s3:::euid_bucket_1euid_bucket_12024-03-01 15:34:05eu-central-1{"EUID":"EUID1"}true

Want to see CloudQuery in action? Schedule a demo with our team or check out the platform documentation to learn more.

Try CloudQuery yourself

Self-hosted, open source, and free to start. Or schedule a demo to see the managed version.

Related posts

AWS

Security

Tutorials

Finding AWS Unrestricted Outbound Access in 2026: EC2, Lambda, and Beyond

Find EC2, Lambda, and ECS Fargate resources with unrestricted outbound access in AWS using SQL. Why egress controls still break attack chains in 2026.

Joe Karlsson

Joe Karlsson

May 5, 2026

AWS

Security

Tutorials

AWS IAM Identity Center with Google Workspace as an IdP: 2026 Step-by-Step Guide

Set up AWS IAM Identity Center with Google Workspace: SAML authentication, SCIM user provisioning, and group sync with CLI or ssosync. Updated for 2026.

Joe Karlsson

Joe Karlsson

May 5, 2026

AWS

Cloud Infrastructure

Security

Tutorials

Integrate AbuseIPDB Threat Intelligence with CloudQuery

Enrich your cloud asset inventory with AbuseIPDB threat intelligence to identify public cloud IPs with known abuse reports.

Joe Karlsson

Joe Karlsson

April 20, 2026

AWS

Cloud Infrastructure

Tutorials

How to Query ipinfo.io Data with CloudQuery

Learn how to enrich your cloud asset inventory with ipinfo.io IP geolocation and threat intelligence data using CloudQuery.

Joe Karlsson

Joe Karlsson

April 20, 2026

AWS

Security

Tutorials

AWS IAM Identity Center (Formerly AWS SSO): The Complete 2026 Guide

AWS IAM Identity Center replaced AWS SSO in 2022. Learn how to set it up, configure permission sets, use the AWS CLI, and audit access with CloudQuery.

Joe Karlsson

Joe Karlsson

April 6, 2026

AWS

Tutorials

AWS Pinpoint Is Being Deprecated: How to Assess Your Migration Scope

AWS Pinpoint reaches end of support October 2026. Query your Pinpoint usage across all accounts to find what needs migrating before the deadline.

Joe Karlsson

Joe Karlsson

March 24, 2026

AWS

Best Practices

Tutorials

CloudQuery Sync Performance: A Practical Troubleshooting Guide

Diagnose why CloudQuery syncs slow down after plugin upgrades, identify expensive tables, and use the CLI command that replaces the tables wildcard.

Joe Karlsson

Joe Karlsson

March 6, 2026

AWS

Security

Tutorials

Set Up AWS CLI with SSO (IAM Identity Center) — Step by Step

Set up AWS CLI v2 with IAM Identity Center in 5 minutes. Covers SSO registration scopes, sso-session config, token refresh, and multi-account profiles.

Yevgeny Pats

Yevgeny Pats

February 25, 2026

AWS

Cloud Infrastructure

Tutorials

AWS Lambda Python 3.9 End-of-Support: Find and Upgrade Every Affected Function

AWS Lambda Python 3.9 security patches stopped Dec 15, 2025. Find every affected function across all accounts with SQL queries and upgrade to 3.12 or 3.13.

Joe Karlsson

Joe Karlsson

February 10, 2026

Own your pipeline.
Own your data.