Skip to main content

More Info:

AWS S3 buckets should not be publicly accessible via bucket policies in order to protect against unauthorized access. Granting public access to your S3 buckets via bucket policies can allow malicious users to view, get, upload, modify and delete S3 objects, actions that can lead to data loss and unexpected charges on your AWS bill.

Risk Level

Critical

Address

Security

Compliance Standards

  • APRA CPS 234 (Australia)
  • AWS Startup Security Baseline
  • BSI C5 (Germany)
  • Brazil LGPD
  • CCPA / CPRA (California)
  • CIS AWS
  • CIS Critical Security Controls v8
  • CMMC 2.0
  • CSA Cloud Controls Matrix v4
  • Cloudanix Best Practice
  • DPDPA
  • Digital Operational Resilience Act (EU)
  • GDPR
  • ISO/IEC 27017
  • ISO/IEC 27018
  • ISO/IEC 27701
  • KSA PDPL
  • MAS Technology Risk Management (Singapore)
  • MITRE ATT&CK (Cloud)
  • NIS2 Directive
  • NIST SP 800-171
  • NYDFS 23 NYCRR 500
  • Reserve Bank of India (RBI) Master Direction – Information Technology Framework
  • SWIFT Customer Security Controls Framework
  • Sarbanes-Oxley IT General Controls
  • Securities and Exchange Board of India (SEBI) - Cloud Security Adoption Framework
  • UK NCSC Cyber Assessment Framework

Triage and Remediation

Remediation

Using Console

  1. Open the AWS S3 Console.
  2. Navigate to the specific S3 bucket for which you want to block public access.
  3. Click on the “Permissions” tab.
  4. Scroll down to the “Block public access” section.
  5. Edit the settings to block all public access.
  6. Save the changes.
Alternate option
  1. Sign in to the AWS Management Console**.
  2. Navigate to the S3 service**.
  3. Select the bucket you want to remediate**.
  4. Review Bucket Policy**:
    • Click on the Permissions tab.
    • Click on Bucket Policy.
    • Review the JSON policy document displayed.
  5. Identify Statements Allowing Public Access**:
    • Look for statements with "Effect": "Allow" and "Principal": "*".
    • These statements grant public access to resources in the bucket.
  6. Modify the Bucket Policy**:
    • Remove or modify the identified statements to restrict public access.
    • You can remove the entire statement or modify the Principal or Action to limit access.
    • For example, you can change "Principal": "*" to "Principal": {"AWS": "arn:aws:iam::ACCOUNT_ID:root"} to grant access only to the AWS account root user.
  7. Save Changes**:
    • After making modifications, click Save or Apply Changes to save the updated bucket policy.
  8. Repeat for Other Buckets**:
    • Repeat the above steps for each bucket listed in the script that requires remediation.

Example:

Suppose the bucket policy contains a statement allowing public access:
To remediate, you would remove this statement or modify it to restrict access. For example:
After saving the updated policy, public access to objects in the bucket would be denied.Ensure that you have appropriate permissions to modify the bucket policy in the AWS Management Console.

Replace YOUR_BUCKET_NAME with the name of your S3 bucket.Alternate option
  1. Retrieve Bucket Policy**:
Replace BUCKET_NAME with the name of the bucket you want to remediate.
  1. Analyze the Bucket Policy**:
    • Review the policy stored in the bucket_policy.json file to identify any statements allowing public access ("Effect": "Allow" with "Principal": "*").
  2. Update Bucket Policy**:
    • Modify the bucket_policy.json file to remove or modify the statements allowing public access.
  3. Apply Remediated Policy**:
Replace BUCKET_NAME with the name of the bucket.

Example Remediation:

Suppose the bucket_policy.json file contains a policy allowing public access:
You want to remediate it by removing the statement. Modify the bucket_policy.json file to remove the statement:
Then, apply the remediated policy to the bucket:
This will remove all statements from the bucket policy, effectively revoking public access.Ensure that you have appropriate IAM permissions to modify the bucket policy using the put-bucket-policy command.
This script checks for public access statements in the bucket policy and prints a message if any are found. For remediation, you would need to implement steps to modify the bucket policy accordingly, such as removing the statements allowing public access or updating the policy to restrict public access.You can call this function check_and_remediate_s3_public_access for each bucket to check and remediate the public access issues in your S3 buckets.

Example Usage:

Replace "your_bucket_name" with the actual name of the bucket you want to check and remediate. Make sure to have appropriate permissions to modify the bucket policy.

Example usage

bucket_name = ‘YOUR_BUCKET_NAME’ aws_access_key_id = ‘YOUR_ACCESS_KEY’ aws_secret_access_key = ‘YOUR_SECRET_KEY’ region = ‘us-east-1’ # Replace with your desired regionremediate_s3_public_access_via_policy(bucket_name, aws_access_key_id, aws_secret_access_key, region)
Note: Ensure that you have the necessary permissions to make these changes, and exercise caution when applying changes to production environments.
This Terraform snippet enables all four S3 Block Public Access settings on the bucket, matching the put-public-access-block CLI remediation. This may disrupt any intentional public access (for example, static website hosting), so review before applying; it does not force replacement of the bucket, only an in-place change to its access controls.To verify, terraform plan should show the aws_s3_bucket_public_access_block resource being created or updated with all four arguments set to true.

Additional Reading: