> ## Documentation Index
> Fetch the complete documentation index at: https://cloudanix.com/docs/llms.txt
> Use this file to discover all available pages before exploring further.

# S3 Block Public Access Feature Should Be Enabled

### More Info:

Amazon S3 Block Public Access feature should be enabled for your S3 buckets to restrict public access to all objects available within these buckets, including those that you upload in the future.

### 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)
* Essential 8
* FedRAMP
* GDPR
* HIPAA
* HITRUST CSF
* ISO/IEC 27017
* ISO/IEC 27018
* ISO/IEC 27701
* KSA PDPL
* MAS Technology Risk Management (Singapore)
* MITRE ATT\&CK (Cloud)
* NIS2 Directive
* NIST
* NIST CSF
* NIST SP 800-171
* NYDFS 23 NYCRR 500
* PCI
* Reserve Bank of India (RBI) Cyber Security Framework
* Reserve Bank of India (RBI) Master Direction – Information Technology Framework
* SOC2
* 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

<Tabs>
  <Tab title="Remediation">
    ### Remediation

    <AccordionGroup>
      <Accordion title="Using Console" defaultOpen="true">
        Sure, here are the step-by-step instructions to remediate the misconfiguration in AWS:

        1. Login to your AWS Management Console.

        2. Navigate to the S3 service.

        3. Click on the bucket name you want to remediate.

        4. Click on the "Permissions" tab.

        5. Scroll down to the "Block public access" section.

        6. Click on the "Edit" button.

        7. Enable the "Block all public access" option.

        8. Click on the "Save changes" button.

        9. Repeat the above steps for all the buckets in your AWS account.

        By following the above steps, you have successfully enabled the S3 Block Public Access feature in your AWS account and remediated the misconfiguration.

        #
      </Accordion>

      <Accordion title="Using CLI">
        To remediate the misconfiguration "S3 Block Public Access Feature Should Be Enabled" for AWS using AWS CLI, follow these steps:

        1. Open the AWS CLI on your local machine or instance.
        2. Run the following command to enable the S3 Block Public Access feature on your AWS account:

        ```
        aws s3api put-public-access-block --public-access-block-configuration BlockPublicAcls=true,IgnorePublicAcls=true,BlockPublicPolicy=true,RestrictPublicBuckets=true
        ```

        This command sets the `BlockPublicAcls`, `IgnorePublicAcls`, `BlockPublicPolicy`, and `RestrictPublicBuckets` parameters to `true`, which blocks public access to S3 buckets and objects.

        3. Verify that the S3 Block Public Access feature is enabled by running the following command:

        ```
        aws s3api get-public-access-block
        ```

        This command retrieves the current public access block configuration for your AWS account.

        4. If the S3 Block Public Access feature is not enabled, repeat step 2 to enable it.

        5. Once the S3 Block Public Access feature is enabled, you can verify that all S3 buckets in your AWS account have the feature enabled by running the following command:

        ```
        aws s3api get-bucket-policy-status --bucket <bucket-name>
        ```

        Replace `<bucket-name>` with the name of the S3 bucket you want to verify. This command retrieves the current policy status for the specified S3 bucket.

        6. If the policy status for the S3 bucket is not compliant, update the bucket policy to ensure that public access is blocked. You can use the following policy as an example:

        ```
        {
            "Version": "2012-10-17",
            "Statement": [
                {
                    "Sid": "DenyPublicAccess",
                    "Effect": "Deny",
                    "Principal": "*",
                    "Action": [
                        "s3:GetObject",
                        "s3:PutObject",
                        "s3:ListBucket"
                    ],
                    "Resource": [
                        "arn:aws:s3:::<bucket-name>",
                        "arn:aws:s3:::<bucket-name>/*"
                    ],
                    "Condition": {
                        "Bool": {
                            "aws:SecureTransport": "false"
                        }
                    }
                }
            ]
        }
        ```

        Replace `<bucket-name>` with the name of the S3 bucket you want to update. This policy denies all public access to the specified S3 bucket.

        7. Repeat step 5 and 6 for all S3 buckets in your AWS account to ensure that public access is blocked.
      </Accordion>

      <Accordion title="Using Python">
        To remediate the "S3 Block Public Access Feature Should Be Enabled" misconfiguration in AWS using Python, follow these steps:

        1. Install the AWS SDK for Python (Boto3) by running the following command in your command prompt or terminal:

        ```
        pip install boto3
        ```

        2. Import the Boto3 library and create a client for S3:

        ```python theme={null}
        import boto3

        s3 = boto3.client('s3')
        ```

        3. Enable the "Block Public Access" feature for all existing and future S3 buckets by setting the BlockPublicAcls, IgnorePublicAcls, BlockPublicPolicy, and RestrictPublicBuckets parameters to True:

        ```python theme={null}
        response = s3.put_public_access_block(
            PublicAccessBlockConfiguration={
                'BlockPublicAcls': True,
                'IgnorePublicAcls': True,
                'BlockPublicPolicy': True,
                'RestrictPublicBuckets': True
            }
        )
        ```

        4. Verify that the "Block Public Access" feature has been enabled by checking the response from the put\_public\_access\_block() method:

        ```python theme={null}
        print(response)
        ```

        The response should contain the following JSON object:

        ```json theme={null}
        {
            "ResponseMetadata": {
                "RequestId": "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx",
                "HTTPStatusCode": 200,
                "HTTPHeaders": {
                    "x-amz-id-2": "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
                    "x-amz-request-id": "xxxxxxxxxxxxxxxx",
                    "date": "Wed, 19 May 2021 00:00:00 GMT",
                    "content-length": "0",
                    "server": "AmazonS3"
                },
                "RetryAttempts": 0
            }
        }
        ```

        By following these steps, you should be able to remediate the "S3 Block Public Access Feature Should Be Enabled" misconfiguration in AWS using Python.
      </Accordion>

      <Accordion title="Using Terraform">
        ```hcl theme={null}
        resource "aws_s3_bucket" "THIS_BUCKET" {
          bucket = "YOUR_BUCKET_NAME" # replace with the bucket name from the finding
        }

        # WARNING: Enabling Block Public Access may cause applications that legitimately
        # rely on public access to the bucket to fail. Review usage before applying.
        resource "aws_s3_bucket_public_access_block" "this" {
          bucket = aws_s3_bucket.THIS_BUCKET.id

          block_public_acls       = true
          ignore_public_acls      = true
          block_public_policy     = true
          restrict_public_buckets = true
        }
        ```

        This change does not force bucket replacement; it updates the bucket’s public access block configuration in place.

        Verification: `terraform plan` should show a new `aws_s3_bucket_public_access_block.this` resource being created (or its four arguments changing from `false`/`null` to `true`) attached to the target bucket.
      </Accordion>
    </AccordionGroup>
  </Tab>
</Tabs>

### Additional Reading:

* [https://docs.aws.amazon.com/AmazonS3/latest/userguide/access-control-block-public-access.html](https://docs.aws.amazon.com/AmazonS3/latest/userguide/access-control-block-public-access.html)
