Table: aws_s3_bucket - Query AWS S3 Buckets using SQL
An AWS S3 Bucket is a public cloud storage resource available in Amazon Web Services' (AWS) Simple Storage Service (S3). It is used to store objects, which consist of data and its descriptive metadata. S3 makes it possible to store and retrieve varying amounts of data, at any time, from anywhere on the web.
Table Usage Guide
The aws_s3_bucket
table in Steampipe provides you with information about S3 buckets within Amazon Simple Storage Service (S3). This table allows you, as a DevOps engineer, to query bucket-specific details, including configuration, policies, and permissions. You can utilize this table to gather insights on buckets, such as bucket policies, access controls, versioning status, and more. The schema outlines for you the various attributes of the S3 bucket, including the bucket name, creation date, region, and associated tags.
Examples
Basic info
Explore which AWS S3 buckets are set as public in different regions to enhance your data security by identifying potential vulnerabilities. This allows you to manage your AWS resources more effectively by pinpointing specific locations where public access may be a concern.
select name, region, account_id, bucket_policy_is_publicfrom aws_s3_bucket;
select name, region, account_id, bucket_policy_is_publicfrom aws_s3_bucket;
List buckets with versioning disabled
Discover the segments that have versioning disabled in your Amazon S3 buckets. This could be useful in identifying potential risks or compliance issues related to data version control.
select name, region, account_id, versioning_enabledfrom aws_s3_bucketwhere not versioning_enabled;
select name, region, account_id, versioning_enabledfrom aws_s3_bucketwhere versioning_enabled is not 1;
List buckets with default encryption disabled
Uncover the details of S3 buckets that lack default encryption, a potential security risk, to enhance data protection measures in your AWS environment.
select name, server_side_encryption_configurationfrom aws_s3_bucketwhere server_side_encryption_configuration is null;
select name, server_side_encryption_configurationfrom aws_s3_bucketwhere server_side_encryption_configuration is null;
List buckets that do not block public access
Identify instances where AWS S3 buckets may be vulnerable due to not blocking public access. This query is useful for assessing potential security risks associated with unrestricted public access to your data.
select name, block_public_acls, block_public_policy, ignore_public_acls, restrict_public_bucketsfrom aws_s3_bucketwhere not block_public_acls or not block_public_policy or not ignore_public_acls or not restrict_public_buckets;
select name, block_public_acls, block_public_policy, ignore_public_acls, restrict_public_bucketsfrom aws_s3_bucketwhere block_public_acls = 0 or block_public_policy = 0 or ignore_public_acls = 0 or restrict_public_buckets = 0;
List buckets that block public access through bucket policies
Identify instances where certain storage buckets have implemented measures to block public access, enhancing data security and privacy. This could be useful in ensuring compliance with privacy regulations and preventing unauthorized data access.
select name, bucket_policy_is_publicfrom aws_s3_bucketwhere bucket_policy_is_public;
select name, bucket_policy_is_publicfrom aws_s3_bucketwhere bucket_policy_is_public = 1;
List buckets where the server access logging destination is the same as the source bucket
Identify instances where the destination for server access logging is the same as the source bucket in AWS S3. This can help in understanding potential security risks or misconfigurations in your logging setup.
select name, logging ->> 'TargetBucket' as target_bucketfrom aws_s3_bucketwhere logging ->> 'TargetBucket' = name;
select name, json_extract(logging, '$.TargetBucket') as target_bucketfrom aws_s3_bucketwhere json_extract(logging, '$.TargetBucket') = name;
List buckets without the 'application' tags key
Discover the buckets that have not been tagged specifically for application purposes. This is particularly useful for managing and organizing your buckets based on their intended application usage.
select name, tags ->> 'fizz' as fizzfrom aws_s3_bucketwhere tags ->> 'application' is null;
select name, json_extract(tags, '$.fizz') as fizzfrom aws_s3_bucketwhere json_extract(tags, '$.application') is null;
List buckets that enforce encryption in transit
Determine the areas in which AWS S3 buckets have encryption in transit enforced. This query is useful in identifying potential security vulnerabilities, as buckets without this feature may be at risk of data interception during transfer.
select name, p as principal, a as action, s ->> 'Effect' as effect, s ->> 'Condition' as conditions, sslfrom aws_s3_bucket, jsonb_array_elements(policy_std -> 'Statement') as s, jsonb_array_elements_text(s -> 'Principal' -> 'AWS') as p, jsonb_array_elements_text(s -> 'Action') as a, jsonb_array_elements_text(s -> 'Condition' -> 'Bool' -> 'aws:securetransport') as sslwhere p = '*' and s ->> 'Effect' = 'Deny' and ssl :: bool = false;
select name, json_extract(p.value, '$') as principal, json_extract(a.value, '$') as action, json_extract(s.value, '$.Effect') as effect, json_extract(s.value, '$.Condition') as conditions, json_extract(ssl.value, '$') as sslfrom aws_s3_bucket, json_each(json_extract(policy_std, '$.Statement')) as s, json_each(json_extract(s.value, '$.Principal.AWS')) as p, json_each(json_extract(s.value, '$.Action')) as a, json_each( json_extract(s.value, '$.Condition.Bool."aws:securetransport"') ) as sslwhere json_extract(p.value, '$') = '*' and json_extract(s.value, '$.Effect') = 'Deny' and json_extract(ssl.value, '$') = 'false';
List buckets that do not enforce encryption in transit
Determine the areas in your AWS S3 service where encryption in transit is not enforced. This is useful for identifying potential security risks and ensuring that your data is always protected during transmission.
select namefrom aws_s3_bucketwhere name not in ( select name from aws_s3_bucket, jsonb_array_elements(policy_std -> 'Statement') as s, jsonb_array_elements_text(s -> 'Principal' -> 'AWS') as p, jsonb_array_elements_text(s -> 'Action') as a, jsonb_array_elements_text(s -> 'Condition' -> 'Bool' -> 'aws:securetransport') as ssl where p = '*' and s ->> 'Effect' = 'Deny' and ssl :: bool = false );
select namefrom aws_s3_bucketwhere name not in ( select aws_s3_bucket.name from aws_s3_bucket, json_each(json_extract(policy_std, '$.Statement')) as s, json_each(json_extract(s.value, '$.Principal.AWS')) as p, json_each(json_extract(s.value, '$.Action')) as a, json_each( json_extract(s.value, '$.Condition.Bool."aws:securetransport"') ) as ssl where json_extract(p.value, '$') = '*' and json_extract(s.value, '$.Effect') = 'Deny' and json_extract(ssl.value, '$') = 'false' );
List bucket policy statements that grant external access for each bucket
Determine the areas in which your S3 bucket policies may be granting external access. This is useful for identifying potential security risks and ensuring only authorized access to your buckets.
select title, p as principal, a as action, s ->> 'Effect' as effect, s -> 'Condition' as conditionsfrom aws_s3_bucket, jsonb_array_elements(policy_std -> 'Statement') as s, jsonb_array_elements_text(s -> 'Principal' -> 'AWS') as p, string_to_array(p, ':') as pa, jsonb_array_elements_text(s -> 'Action') as awhere s ->> 'Effect' = 'Allow' and ( pa [ 5 ] != account_id or p = '*' );
Error: SQLite does not support string_to_array functions.
List buckets with object lock enabled
Determine the areas in which AWS S3 buckets have the object lock feature enabled. This is useful for understanding where additional data protection measures are in place.
select name, object_lock_configuration ->> 'ObjectLockEnabled' as object_lock_enabledfrom aws_s3_bucketwhere object_lock_configuration ->> 'ObjectLockEnabled' = 'Enabled';
select name, json_extract(object_lock_configuration, '$.ObjectLockEnabled') as object_lock_enabledfrom aws_s3_bucketwhere json_extract(object_lock_configuration, '$.ObjectLockEnabled') = 'Enabled';
List buckets with website hosting enabled
Discover the segments that have website hosting enabled within your AWS S3 buckets. This can be useful in identifying where your web content is stored or determining which buckets are serving as websites.
select name, website_configuration -> 'IndexDocument' ->> 'Suffix' as suffixfrom aws_s3_bucketwhere website_configuration -> 'IndexDocument' ->> 'Suffix' is not null;
select name, json_extract(website_configuration, '$.IndexDocument.Suffix') as suffixfrom aws_s3_bucketwhere json_extract(website_configuration, '$.IndexDocument.Suffix') is not null;
List object ownership control rules of buckets
Explore which AWS S3 buckets have specific object ownership control rules. This can be useful in managing access permissions and ensuring appropriate data governance.
select b.name, r ->> 'ObjectOwnership' as object_ownershipfrom aws_s3_bucket as b, jsonb_array_elements(object_ownership_controls -> 'Rules') as r;
select b.name, json_extract(r.value, '$.ObjectOwnership') as object_ownershipfrom aws_s3_bucket as b, json_each(b.object_ownership_controls, '$.Rules') as r;
Query examples
- bucket_policy_stds_for_s3_bucket
- cloudtrail_trail_bucket
- cloudtrail_trails_for_s3_bucket
- ec2_application_load_balancers_for_s3_bucket
- ec2_classic_load_balancers_for_s3_bucket
- ec2_network_load_balancers_for_s3_bucket
- kms_keys_for_s3_bucket
- lambda_functions_for_s3_bucket
- logging_destination_s3_buckets_for_s3_bucket
- logging_source_s3_buckets_for_s3_bucket
- s3_bucket_1_year_count
- s3_bucket_24_hours_count
- s3_bucket_30_90_days_count
- s3_bucket_30_days_count
- s3_bucket_90_365_days_count
- s3_bucket_age_table
- s3_bucket_block_public_acls_disabled_count
- s3_bucket_block_public_policy_disabled_count
- s3_bucket_by_account
- s3_bucket_by_creation_month
- s3_bucket_by_region
- s3_bucket_count
- s3_bucket_encryption
- s3_bucket_https_enforce
- s3_bucket_ignore_public_acls_disabled_count
- s3_bucket_input
- s3_bucket_lifecycle_policy
- s3_bucket_lifecycle_table
- s3_bucket_logging
- s3_bucket_logging_disabled_count
- s3_bucket_logging_table
- s3_bucket_overview
- s3_bucket_public
- s3_bucket_public_access
- s3_bucket_public_access_table
- s3_bucket_public_block_count
- s3_bucket_public_policy_count
- s3_bucket_restrict_public_buckets_disabled_count
- s3_bucket_server_side_encryption
- s3_bucket_tags_detail
- s3_bucket_unencrypted_count
- s3_bucket_versioning
- s3_bucket_versioning_disabled_count
- s3_bucket_versioning_mfa_disabled_count
- s3_buckets_for_cloudfront_distribution
- s3_buckets_for_cloudtrail_trail
- s3_buckets_for_codebuild_project
- s3_buckets_for_codepipeline_pipeline
- s3_buckets_for_dynamodb_table
- s3_buckets_for_ec2_application_load_balancer
- s3_buckets_for_ec2_classic_load_balancer
- s3_buckets_for_ec2_gateway_load_balancer
- s3_buckets_for_ec2_network_load_balancer
- s3_buckets_for_emr_cluster
- s3_buckets_for_kms_key
- s3_buckets_for_lambda_function
- s3_buckets_for_sns_topic
- s3_buckets_for_sqs_queue
- s3_buckets_for_vpc_flow_log
- sns_topics_for_s3_bucket
- sqs_queues_for_s3_bucket
Control examples
- All Controls > CloudFront > CloudFront distributions should not point to non-existent S3 origins
- All Controls > CloudTrail > CloudTrail trail S3 buckets MFA delete should be enabled
- All Controls > CloudTrail > Ensure that Object-level logging for read events is enabled for S3 bucket
- All Controls > CloudTrail > Ensure that Object-level logging for write events is enabled for S3 bucket
- All Controls > S3 > Ensure all data in AWS S3 has been discovered, classified and secured when required
- All Controls > S3 > S3 bucket ACLs should not be accessible to all authenticated user
- All Controls > S3 > S3 buckets object logging should be enabled
- All Controls > S3 > S3 buckets static website hosting should be disabled
- All S3 buckets should log S3 data events in CloudTrail
- AWS Foundational Security Best Practices > CloudFront > 12 CloudFront distributions should not point to non-existent S3 origins
- AWS Foundational Security Best Practices > S3 > 10 S3 buckets with versioning enabled should have lifecycle policies configured
- AWS Foundational Security Best Practices > S3 > 11 S3 buckets should have event notifications enabled
- AWS Foundational Security Best Practices > S3 > 12 S3 access control lists (ACLs) should not be used to manage user access to buckets
- AWS Foundational Security Best Practices > S3 > 13 S3 buckets should have lifecycle policies configured
- AWS Foundational Security Best Practices > S3 > 2 S3 buckets should prohibit public read access
- AWS Foundational Security Best Practices > S3 > 3 S3 buckets should prohibit public write access
- AWS Foundational Security Best Practices > S3 > 5 S3 buckets should require requests to use Secure Socket Layer
- AWS Foundational Security Best Practices > S3 > 6 Amazon S3 permissions granted to other AWS accounts in bucket policies should be restricted
- AWS Foundational Security Best Practices > S3 > 8 S3 Block Public Access setting should be enabled at the bucket level
- AWS Foundational Security Best Practices > S3 > 9 S3 bucket server access logging should be enabled
- AWS S3 permissions granted to other AWS accounts in bucket policies should be restricted
- CIS v1.2.0 > 2 Logging > 2.3 Ensure the S3 bucket used to store CloudTrail logs is not publicly accessible
- CIS v1.2.0 > 2 Logging > 2.6 Ensure S3 bucket access logging is enabled on the CloudTrail S3 bucket
- CIS v1.3.0 > 1 Identity and Access Management > 1.20 Ensure that S3 Buckets are configured with 'Block public access (bucket settings)'
- CIS v1.3.0 > 2 Storage > 2.1 Simple Storage Service (S3) > 2.1.1 Ensure all S3 buckets employ encryption-at-rest
- CIS v1.3.0 > 2 Storage > 2.1 Simple Storage Service (S3) > 2.1.2 Ensure S3 Bucket Policy allows HTTPS requests
- CIS v1.3.0 > 3 Logging > 3.10 Ensure that Object-level logging for write events is enabled for S3 bucket
- CIS v1.3.0 > 3 Logging > 3.11 Ensure that Object-level logging for read events is enabled for S3 bucket
- CIS v1.3.0 > 3 Logging > 3.3 Ensure the S3 bucket used to store CloudTrail logs is not publicly accessible
- CIS v1.3.0 > 3 Logging > 3.6 Ensure S3 bucket access logging is enabled on the CloudTrail S3 bucket
- CIS v1.4.0 > 2 Storage > 2.1 Simple Storage Service (S3) > 2.1.1 Ensure all S3 buckets employ encryption-at-rest
- CIS v1.4.0 > 2 Storage > 2.1 Simple Storage Service (S3) > 2.1.2 Ensure S3 Bucket Policy is set to deny HTTP requests
- CIS v1.4.0 > 2 Storage > 2.1 Simple Storage Service (S3) > 2.1.3 Ensure MFA Delete is enabled on S3 buckets
- CIS v1.4.0 > 2 Storage > 2.1 Simple Storage Service (S3) > 2.1.4 Ensure all data in Amazon S3 has been discovered, classified and secured when required
- CIS v1.4.0 > 2 Storage > 2.1 Simple Storage Service (S3) > 2.1.5 Ensure that S3 Buckets are configured with 'Block public access (bucket settings)'
- CIS v1.4.0 > 3 Logging > 3.10 Ensure that Object-level logging for write events is enabled for S3 bucket
- CIS v1.4.0 > 3 Logging > 3.11 Ensure that Object-level logging for read events is enabled for S3 bucket
- CIS v1.4.0 > 3 Logging > 3.3 Ensure the S3 bucket used to store CloudTrail logs is not publicly accessible
- CIS v1.4.0 > 3 Logging > 3.6 Ensure S3 bucket access logging is enabled on the CloudTrail S3 bucket
- CIS v1.5.0 > 2 Storage > 2.1 Simple Storage Service (S3) > 2.1.1 Ensure all S3 buckets employ encryption-at-rest
- CIS v1.5.0 > 2 Storage > 2.1 Simple Storage Service (S3) > 2.1.2 Ensure S3 Bucket Policy is set to deny HTTP requests
- CIS v1.5.0 > 2 Storage > 2.1 Simple Storage Service (S3) > 2.1.3 Ensure MFA Delete is enabled on S3 buckets
- CIS v1.5.0 > 2 Storage > 2.1 Simple Storage Service (S3) > 2.1.4 Ensure all data in Amazon S3 has been discovered, classified and secured when required
- CIS v1.5.0 > 2 Storage > 2.1 Simple Storage Service (S3) > 2.1.5 Ensure that S3 Buckets are configured with 'Block public access (bucket settings)'
- CIS v1.5.0 > 3 Logging > 3.10 Ensure that Object-level logging for write events is enabled for S3 bucket
- CIS v1.5.0 > 3 Logging > 3.11 Ensure that Object-level logging for read events is enabled for S3 bucket
- CIS v1.5.0 > 3 Logging > 3.3 Ensure the S3 bucket used to store CloudTrail logs is not publicly accessible
- CIS v1.5.0 > 3 Logging > 3.6 Ensure S3 bucket access logging is enabled on the CloudTrail S3 bucket
- CIS v2.0.0 > 2 Storage > 2.1 Simple Storage Service (S3) > 2.1.1 Ensure S3 Bucket Policy is set to deny HTTP requests
- CIS v2.0.0 > 2 Storage > 2.1 Simple Storage Service (S3) > 2.1.2 Ensure MFA Delete is enabled on S3 buckets
- CIS v2.0.0 > 2 Storage > 2.1 Simple Storage Service (S3) > 2.1.3 Ensure all data in Amazon S3 has been discovered, classified and secured when required
- CIS v2.0.0 > 2 Storage > 2.1 Simple Storage Service (S3) > 2.1.4 Ensure that S3 Buckets are configured with 'Block public access (bucket settings)'
- CIS v2.0.0 > 3 Logging > 3.10 Ensure that Object-level logging for write events is enabled for S3 bucket
- CIS v2.0.0 > 3 Logging > 3.11 Ensure that Object-level logging for read events is enabled for S3 bucket
- CIS v2.0.0 > 3 Logging > 3.3 Ensure the S3 bucket used to store CloudTrail logs is not publicly accessible
- CIS v2.0.0 > 3 Logging > 3.6 Ensure S3 bucket access logging is enabled on the CloudTrail S3 bucket
- CIS v3.0.0 > 2 Storage > 2.1 Simple Storage Service (S3) > 2.1.1 Ensure S3 Bucket Policy is set to deny HTTP requests
- CIS v3.0.0 > 2 Storage > 2.1 Simple Storage Service (S3) > 2.1.2 Ensure MFA Delete is enabled on S3 buckets
- CIS v3.0.0 > 2 Storage > 2.1 Simple Storage Service (S3) > 2.1.3 Ensure all data in Amazon S3 has been discovered, classified and secured when required
- CIS v3.0.0 > 2 Storage > 2.1 Simple Storage Service (S3) > 2.1.4 Ensure that S3 Buckets are configured with 'Block public access (bucket settings)'
- CIS v3.0.0 > 3 Logging > 3.4 Ensure S3 bucket access logging is enabled on the CloudTrail S3 bucket
- CIS v3.0.0 > 3 Logging > 3.8 Ensure that Object-level logging for write events is enabled for S3 bucket
- CIS v3.0.0 > 3 Logging > 3.9 Ensure that Object-level logging for read events is enabled for S3 bucket
- Ensure MFA Delete is enabled on S3 buckets
- Ensure S3 bucket access logging is enabled on the CloudTrail S3 bucket
- Ensure the S3 bucket CloudTrail logs to is not publicly accessible
- S3 bucket cross-region replication should be enabled
- S3 bucket default encryption should be enabled
- S3 bucket default encryption should be enabled with KMS
- S3 bucket logging should be enabled
- S3 bucket object lock should be enabled
- S3 bucket policy should prohibit public access
- S3 bucket versioning should be enabled
- S3 buckets access control lists (ACLs) should not be used to manage user access to buckets
- S3 buckets should enforce SSL
- S3 buckets should have event notifications enabled
- S3 buckets should have lifecycle policies configured
- S3 buckets should prohibit public read access
- S3 buckets should prohibit public write access
- S3 buckets with versioning enabled should have lifecycle policies configured
- S3 public access should be blocked at account and bucket levels
- S3 public access should be blocked at bucket levels
Schema for aws_s3_bucket
Name | Type | Operators | Description |
---|---|---|---|
_ctx | jsonb | Steampipe context in JSON form. | |
account_id | text | =, !=, ~~, ~~*, !~~, !~~* | The AWS Account ID in which the resource is located. |
acl | jsonb | The access control list (ACL) of a bucket. | |
akas | jsonb | Array of globally unique identifier strings (also known as) for the resource. | |
arn | text | The ARN of the AWS S3 Bucket. | |
block_public_acls | boolean | Specifies whether Amazon S3 should block public access control lists (ACLs) for this bucket and objects in this bucket. | |
block_public_policy | boolean | Specifies whether Amazon S3 should block public bucket policies for this bucket. If TRUE it causes Amazon S3 to reject calls to PUT Bucket policy if the specified bucket policy allows public access. | |
bucket_policy_is_public | boolean | The policy status for an Amazon S3 bucket, indicating whether the bucket is public. | |
creation_date | timestamp with time zone | The date and time when bucket was created. | |
event_notification_configuration | jsonb | A container for specifying the notification configuration of the bucket. If this element is empty, notifications are turned off for the bucket. | |
ignore_public_acls | boolean | Specifies whether Amazon S3 should ignore public ACLs for this bucket and objects in this bucket. Setting this element to TRUE causes Amazon S3 to ignore all public ACLs on this bucket and objects in this bucket. | |
lifecycle_rules | jsonb | The lifecycle configuration information of the bucket. | |
logging | jsonb | The logging status of a bucket and the permissions users have to view and modify that status. | |
name | text | The user friendly name of the bucket. | |
object_lock_configuration | jsonb | The specified bucket's object lock configuration. | |
object_ownership_controls | jsonb | The Ownership Controls for an Amazon S3 bucket. | |
partition | text | The AWS partition in which the resource is located (aws, aws-cn, or aws-us-gov). | |
policy | jsonb | The resource IAM access document for the bucket. | |
policy_std | jsonb | Contains the policy in a canonical form for easier searching. | |
region | text | The AWS Region in which the resource is located. | |
replication | jsonb | The replication configuration of a bucket. | |
restrict_public_buckets | boolean | Specifies whether Amazon S3 should restrict public bucket policies for this bucket. Setting this element to TRUE restricts access to this bucket to only AWS service principals and authorized users within this account if the bucket has a public policy. | |
server_side_encryption_configuration | jsonb | The default encryption configuration for an Amazon S3 bucket. | |
sp_connection_name | text | =, !=, ~~, ~~*, !~~, !~~* | Steampipe connection name. |
sp_ctx | jsonb | Steampipe context in JSON form. | |
tags | jsonb | A map of tags for the resource. | |
tags_src | jsonb | A list of tags assigned to bucket. | |
title | text | Title of the resource. | |
versioning_enabled | boolean | The versioning state of a bucket. | |
versioning_mfa_delete | boolean | The MFA Delete status of the versioning state. | |
website_configuration | jsonb | The website configuration information of the bucket. |
Export
This table is available as a standalone Exporter CLI. Steampipe exporters are stand-alone binaries that allow you to extract data using Steampipe plugins without a database.
You can download the tarball for your platform from the Releases page, but it is simplest to install them with the steampipe_export_installer.sh
script:
/bin/sh -c "$(curl -fsSL https://steampipe.io/install/export.sh)" -- aws
You can pass the configuration to the command with the --config
argument:
steampipe_export_aws --config '<your_config>' aws_s3_bucket