> ## 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 Buckets Should Enforce Server Side Encryption

### More Info:

AWS S3 buckets should protect their sensitive data at rest by enforcing Server-Side Encryption (SSE).

### Risk Level

High

### Address

Security

### Compliance Standards

* APRA CPS 234 (Australia)
* AWS Well Architected Framework
* BSI C5 (Germany)
* Brazil LGPD
* CCPA / CPRA (California)
* CIS Critical Security Controls v8
* CMMC 2.0
* CSA Cloud Controls Matrix v4
* DPDPA
* Digital Operational Resilience Act (EU)
* Essential 8
* GDPR
* HIPAA
* HITRUST CSF
* ISO 27001
* 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
* 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 S3 Buckets Should Enforce Server Side Encryption misconfiguration in AWS using the AWS console:

        1. Login to your AWS Management Console.

        2. Navigate to the S3 service.

        3. Select the bucket that you want to remediate.

        4. Click on the "Properties" tab.

        5. Under the "Default encryption" section, click on the "Edit" button.

        6. Select "AES-256" or "AWS-KMS" as the encryption type.

        7. Click on the "Save" button.

        8. Repeat the above steps for all the S3 buckets that need to be remediated.

        By following the above steps, you can enforce server-side encryption for your S3 buckets in AWS, which will help you remediate the S3 Buckets Should Enforce Server Side Encryption misconfiguration.

        #
      </Accordion>

      <Accordion title="Using CLI">
        To remediate the misconfiguration "S3 Buckets Should Enforce Server Side Encryption" for AWS using AWS CLI, you can follow the below steps:

        1. Open the AWS CLI on your local machine.

        2. Run the following command to list all the S3 buckets in your AWS account:

        ```
        aws s3 ls
        ```

        3. Identify the S3 bucket that needs to be remediated.

        4. Run the following command to enable server-side encryption on the identified bucket:

        ```
        aws s3api put-bucket-encryption --bucket <bucket-name> --server-side-encryption-configuration '{"Rules": [{"ApplyServerSideEncryptionByDefault": {"SSEAlgorithm": "AES256"}}]}'
        ```

        Note: Replace `<bucket-name>` with the name of the identified S3 bucket.

        5. Once the command is executed successfully, the identified S3 bucket will enforce server-side encryption.

        6. To verify if the server-side encryption is enabled, run the following command:

        ```
        aws s3api get-bucket-encryption --bucket <bucket-name>
        ```

        Note: Replace `<bucket-name>` with the name of the identified S3 bucket.

        7. If the server-side encryption is enabled, the output of the above command will show the encryption configuration for the S3 bucket.

        By following these steps, you can remediate the misconfiguration "S3 Buckets Should Enforce Server Side Encryption" for AWS using AWS CLI.
      </Accordion>

      <Accordion title="Using Python">
        To remediate the misconfiguration in AWS, you can use the AWS SDK for Python (Boto3) to enforce server-side encryption on all S3 buckets. Here are the steps to follow:

        1. Install Boto3 using pip:

        ```bash theme={null}
        pip install boto3
        ```

        2. Create a Python script and import the required modules:

        ```python theme={null}
        import boto3
        from botocore.exceptions import ClientError
        ```

        3. Instantiate a Boto3 S3 client:

        ```python theme={null}
        s3 = boto3.client('s3')
        ```

        4. Retrieve a list of all S3 buckets:

        ```python theme={null}
        response = s3.list_buckets()
        buckets = [bucket['Name'] for bucket in response['Buckets']]
        ```

        5. For each bucket, check if server-side encryption is already enabled:

        ```python theme={null}
        for bucket in buckets:
            try:
                response = s3.get_bucket_encryption(Bucket=bucket)
                if 'ServerSideEncryptionConfiguration' in response:
                    print(f"{bucket} already has server-side encryption enabled.")
                else:
                    # Enable server-side encryption
                    s3.put_bucket_encryption(
                        Bucket=bucket,
                        ServerSideEncryptionConfiguration={
                            'Rules': [
                                {
                                    'ApplyServerSideEncryptionByDefault': {
                                        'SSEAlgorithm': 'AES256'
                                    }
                                }
                            ]
                        }
                    )
                    print(f"Server-side encryption enabled for {bucket}.")
            except ClientError as e:
                if e.response['Error']['Code'] == 'ServerSideEncryptionConfigurationNotFoundError':
                    # Enable server-side encryption
                    s3.put_bucket_encryption(
                        Bucket=bucket,
                        ServerSideEncryptionConfiguration={
                            'Rules': [
                                {
                                    'ApplyServerSideEncryptionByDefault': {
                                        'SSEAlgorithm': 'AES256'
                                    }
                                }
                            ]
                        }
                    )
                    print(f"Server-side encryption enabled for {bucket}.")
                else:
                    print(f"Error checking encryption status for {bucket}: {e}")
        ```

        6. Run the script to enable server-side encryption on all S3 buckets.

        Note: Before running the script, make sure you have the necessary permissions to modify S3 bucket settings.
      </Accordion>

      <Accordion title="Using Terraform">
        ```hcl theme={null}
        resource "aws_s3_bucket" "this" {
          bucket = "YOUR_BUCKET_NAME" # replace with your bucket name
        }

        # Option 1: Match CLI example using SSE-S3 (AES256)
        resource "aws_s3_bucket_server_side_encryption_configuration" "this_aes256" {
          bucket = aws_s3_bucket.this.id

          rule {
            apply_server_side_encryption_by_default {
              sse_algorithm = "AES256"
            }
          }
        }

        # --- OR ---

        # Option 2: Match CLI example using SSE-KMS with your own CMK
        # WARNING: This overwrites any existing default encryption configuration for the bucket.
        # Ensure the KMS key exists in the same region and IAM principals have kms:Decrypt and kms:GenerateDataKey.
        resource "aws_kms_key" "s3_cmk" {
          description             = "KMS key for S3 default encryption"
          deletion_window_in_days = 30
        }

        resource "aws_s3_bucket_server_side_encryption_configuration" "this_kms" {
          bucket = aws_s3_bucket.this.id

          rule {
            apply_server_side_encryption_by_default {
              sse_algorithm     = "aws:kms"
              kms_master_key_id = aws_kms_key.s3_cmk.arn
            }
          }
        }
        ```

        Enabling or changing `aws_s3_bucket_server_side_encryption_configuration` updates the bucket in place; it does not force bucket replacement, but it will overwrite any existing default encryption configuration.

        To verify, `terraform plan` should show either:

        * `+ aws_s3_bucket_server_side_encryption_configuration.this_aes256` with `sse_algorithm: "AES256"`, or
        * `+ aws_s3_bucket_server_side_encryption_configuration.this_kms` with `sse_algorithm: "aws:kms"` and the CMK ARN,\
          and no `-` (destroy) for the `aws_s3_bucket.this` resource.
      </Accordion>
    </AccordionGroup>
  </Tab>
</Tabs>

### Additional Reading:

* [https://docs.aws.amazon.com/AmazonS3/latest/userguide/bucket-encryption.html](https://docs.aws.amazon.com/AmazonS3/latest/userguide/bucket-encryption.html)
