AWS

Tutorials

How to Find All Publicly Accessible S3 Buckets in Your AWS Account

Publicly accessible S3 buckets are a leading cause of cloud data breaches, exposing millions of sensitive records annually. This guide shows how to use CloudQuery to identify at-risk buckets and enhance your AWS security posture. Finding and blocking public S3 access is also required by CIS AWS Foundations Benchmark control 2.1.5 - so the queries here double as compliance evidence.

By the end of this post, you will:

  1. Learn how to sync your AWS S3 data with CloudQuery.
  2. Understand the risks associated with public S3 buckets.
  3. Run queries to identify publicly accessible buckets using CloudQuery.

What is CloudQuery?

CloudQuery streamlines cloud asset management by enabling you to query and analyze your cloud data across all regions and cloud providers. Beyond listing publicly accessible S3 buckets, it helps you inventory your cloud assets, monitor compliance, optimize cloud costs, and improve overall governance with a centralized, queryable view of your cloud environment.

CloudQuery platform overview showing cloud asset inventory with resource details across AWS regions

How to sync your AWS Cloud Data with CloudQuery

Here is a step-by-step guide on how to configure the AWS Source integration and use the collected data.

  1. Sign Up for CloudQuery
    Start by creating a CloudQuery account to get started.
  2. Set Up Your Sync
    Configure a new sync using the AWS Source Integration. Make sure you have read-only access to your AWS account to enable data syncing.Configure a new sync using the AWS Source Integration. Make sure you have read-only access to your AWS account to enable data syncing. Refer to the authentication guide for details. For this, you will need to sync all the following S3 data tables:
    tables:
    [
    'aws_s3_buckets',
    'aws_s3_bucket_policies',
    'aws_s3_bucket_public_access_blocks',
    'aws_s3_bucket_grants',
    'aws_s3_access_points',
    ]
  3. Run Your Data Sync
    Click the “Run Sync” button to pull your AWS data into CloudQuery. Once synced, you can query and analyze your EC2 inventory.

Analyzing your Data

With CloudQuery, you can run queries about your synced data directly in the integrated SQL Editor.

A screenshot of the CloudQuery platform’s SQL Console interface. The left panel displays a list of available tables, while the central area shows an SQL query being written and executed. At the top, there are options to run or save the query, and below, the results section indicates “No records found.” The interface is designed for analyzing cloud data using SQL queries.

Find All S3 Buckets with Public Policies

Public policies (e.g., Principal: "*") expose buckets to anyone. Use this query to identify such configurations:

SELECT
b.name AS bucket_name,
b.arn AS bucket_arn,
p.policy_json AS access_details
FROM
aws_s3_buckets AS b
LEFT JOIN
aws_s3_bucket_policies AS p
ON
b.arn = p.bucket_arn
WHERE
JSONExtractString(p.policy_json, 'Statement[0].Principal') = '*'
OR JSONExtractString(p.policy_json, 'Statement[0].Effect') = 'Allow';

Find S3 Buckets with Public Grants

Grants to AllUsers or AuthenticatedUsers allow broad access to bucket contents:

SELECT
b.name AS bucket_name,
b.arn AS bucket_arn,
g.permission AS access_details
FROM
aws_s3_buckets AS b
LEFT JOIN
aws_s3_bucket_grants AS g
ON
b.arn = g.bucket_arn
WHERE
g.grantee_type IN ('AllUsers', 'AuthenticatedUsers');

Find S3 Buckets with Disabled Public Access Blocks

Public access blocks prevent accidental exposure. This query finds buckets with these protections disabled:

SELECT
b.name AS bucket_name,
b.arn AS bucket_arn,
pab.public_access_block_configuration AS access_details
FROM
aws_s3_buckets AS b
LEFT JOIN
aws_s3_bucket_public_access_blocks AS pab
ON
b.arn = pab.bucket_arn
WHERE
JSONExtractBool(pab.public_access_block_configuration, 'BlockPublicAcls') = false
OR JSONExtractBool(pab.public_access_block_configuration, 'BlockPublicPolicy') = false;

How to Find All Publicly Accessible S3 Buckets in Your AWS Account

Use this single query to detect all publicly accessible S3 buckets:

-- Query to find all publicly accessible S3 buckets
SELECT *
FROM
(
-- Extract buckets with overly permissive bucket policies
SELECT
b.name AS bucket_name,
b.arn AS bucket_arn,
'policy' AS access_type,
p.policy_json AS access_details
FROM
aws_s3_buckets AS b
LEFT JOIN
aws_s3_bucket_policies AS p
ON
b.arn = p.bucket_arn
WHERE
JSONExtractString(p.policy_json, 'Statement[0].Principal') = '*' OR
JSONExtractString(p.policy_json, 'Statement[0].Effect') = 'Allow'
) AS policy_buckets
UNION ALL
SELECT *
FROM
(
-- Extract buckets with public grants
SELECT
b.name AS bucket_name,
b.arn AS bucket_arn,
'grant' AS access_type,
g.permission AS access_details
FROM
aws_s3_buckets AS b
LEFT JOIN
aws_s3_bucket_grants AS g
ON
b.arn = g.bucket_arn
WHERE
g.grantee_type IN ('AllUsers', 'AuthenticatedUsers')
) AS grant_buckets
UNION ALL
SELECT *
FROM
(
-- Extract buckets with disabled public access blocks
SELECT
b.name AS bucket_name,
b.arn AS bucket_arn,
'public_access_block' AS access_type,
pab.public_access_block_configuration AS access_details
FROM
aws_s3_buckets AS b
LEFT JOIN
aws_s3_bucket_public_access_blocks AS pab
ON
b.arn = pab.bucket_arn
WHERE
JSONExtractBool(pab.public_access_block_configuration, 'BlockPublicAcls') = false OR
JSONExtractBool(pab.public_access_block_configuration, 'BlockPublicPolicy') = false
) AS pab_buckets
ORDER BY bucket_name;

Beyond Public Access: Other Key S3 Security Queries

Buckets Without Encryption Enabled

Ensuring that your S3 buckets have encryption enabled is critical for protecting sensitive data at rest. Without encryption, data stored in your buckets is more vulnerable to unauthorized access. Use the following query to identify any S3 buckets that lack encryption configurations:

SELECT
b.name AS bucket_name,
b.arn AS bucket_arn
FROM
aws_s3_buckets AS b
LEFT JOIN
aws_s3_bucket_encryption_rules AS e
ON
b.arn = e.bucket_arn
WHERE
e.bucket_arn IS NULL;

List Buckets with No Object Lock Configurations

Object Lock prevents deletion or modification of objects, which is critical for compliance and data retention. This query checks for buckets without this feature enabled.

SELECT
b.name AS bucket_name,
b.arn AS bucket_arn
FROM
aws_s3_buckets AS b
LEFT JOIN
aws_s3_bucket_object_lock_configurations AS olc
ON
b.arn = olc.bucket_arn
WHERE
olc.bucket_arn IS NULL;

List Buckets with Expired or No Lifecycle Rules

Lifecycle rules are essential for cost optimization by archiving or deleting old objects. This query finds buckets without lifecycle rules or with expired configurations.

SELECT
b.nameAS bucket_name,
b.arn AS bucket_arn
FROM
aws_s3_buckets AS b
LEFT JOIN
aws_s3_bucket_lifecycles AS lc
ON
b.arn = lc.bucket_arn
WHERE
lc.bucket_arn IS NULL OR lc.expiration IS NOT NULL;

Wrap Up

In this blog post, you learned how to identify publicly accessible S3 buckets in your AWS account using CloudQuery. You discovered how to sync your AWS data into CloudQuery, run targeted queries to uncover potential security risks and consolidate everything into a comprehensive solution. With this data, you can take proactive steps to protect sensitive data and strengthen your cloud security posture.

CloudQuery isn’t just about securing S3 buckets. It’s the most customizable cloud governance solution that allows you to pull cloud data from any cloud provider. From smarter audits to better asset inventories, CloudQuery makes it easy for your team to take control of your cloud environments. Prefer to run it yourself? Follow the AWS to PostgreSQL quickstart to sync your AWS data into a local database and start querying immediately. Contact us to start using CloudQuery today.

Have questions or need help? Join our growing CloudQuery Developer Community, where you can connect with fellow developers, share insights, and access a wealth of knowledge. Whether you’re exploring new use cases or solving tricky challenges, the community is here to support you.

Finally, let us know how your team is tackling cloud security! Share your thoughts and use cases with us on LinkedIn, X, or in our Community Forum.

FAQs

Why is it important to check for publicly accessible S3 buckets?

Publicly accessible S3 buckets pose a significant security risk, as they can expose sensitive data to unauthorized users. Identifying and securing these buckets helps prevent data breaches, compliance violations, and other costly incidents.

What’s the difference between bucket policies, grants, and public access blocks?

  • Bucket Policies: Define permissions at the bucket level, specifying who can access the bucket and what actions they can take.
  • Grants: Set permissions for specific users or groups, often at the object level.
  • Public Access Blocks: Provide a high-level control to restrict or block public access to buckets, overriding other permissions.

How can I ensure all my S3 buckets are encrypted?

Run a query to identify buckets without encryption configurations, like the one in this blog post. Then, encryption for those buckets can be enabled using AWS Management Console, AWS CLI, or Infrastructure-as-Code tools.

What should I do if I find a publicly accessible S3 bucket?

  • Review the bucket’s permissions to understand why it’s accessible.
  • Update bucket policies to restrict access.
  • Enable public access blocks to enforce restrictions at a higher level.
  • Notify your team and monitor logs for potential unauthorized access.

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 SSO is now AWS IAM Identity Center. Set it up, configure permission sets, use the AWS CLI, and audit access across accounts with SQL.

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.