AWS Introduction
AWS Pricing
AWS Threats
AWS Misconfigurations
- Getting Started with AWS Audit
- Permissions required for Misconfigurations Detection
- API Gateway Audit
- Cloudformation Audit
- CloudFront Audit
- CloudTrail Audit
- Cloudwatch Audit
- DynamoDB Audit
- EC2 Audit
- Elastic Search Audit
- ELB Audit
- IAM Audit
- KMS Audit
- Kubernetes Audit
- Lambda Audit
- RDS Audit
- Redshift Audit
- Route53 Audit
- S3 Audit
- Security Groups Audit
- SES Audit
- SNS Audit
- IAM Deep Dive
- App Sync Audit
- Code Build Audit
- Open Search Audit
- Shield Audit
- SQS Audit
S3 Buckets Should Be Encrypted with Customer-Provided CMKs
More Info:
AWS S3 buckets should be configured to use Server-Side Encryption with customer managed CMKs instead of S3-Managed Keys (SSE-S3) in order to obtain a fine-grained control over Amazon S3 data-at-rest encryption and decryption process.
Risk Level
Low
Address
Security
Compliance Standards
NIST, AWSWAF, HITRUST, SOC2, NISTCSF, PCIDSS
Triage and Remediation
Remediation
To remediate the misconfiguration of S3 Buckets not being encrypted with Customer-Provided CMKs in AWS, follow these step-by-step instructions:
- Log in to the AWS Management Console.
- Go to the S3 service.
- Select the bucket that needs to be encrypted with a Customer-Provided CMK.
- Click on the “Properties” tab.
- Scroll down to the “Default encryption” section and click on “Edit”.
- Select “AWS-KMS” as the encryption type.
- Choose “Customer managed CMK” for the master key.
- Select the CMK that you want to use for encryption from the drop-down menu.
- Click on “Save changes”.
Once you have completed these steps, all objects in the selected S3 bucket will be encrypted with the Customer-Provided CMK that you have chosen. It is important to note that you will need to ensure that the appropriate IAM policies are in place to allow access to the CMK for the appropriate users or roles.
To remediate S3 Buckets not being encrypted with Customer-Provided CMKs in AWS using AWS CLI, follow these steps:
-
Open the AWS CLI on your computer.
-
Identify the S3 bucket that needs to be remediated.
-
Check if the S3 bucket is encrypted with a Customer-Provided CMK by running the following command:
aws s3api get-bucket-encryption --bucket <bucket-name>
-
If the output of the above command shows that the S3 bucket is not encrypted with a Customer-Provided CMK, proceed with the following steps.
-
Create a Customer-Provided CMK in AWS Key Management Service (KMS) by running the following command:
aws kms create-key --description "Customer-Provided CMK for S3 Bucket Encryption"
-
Take note of the
KeyId
value returned by the above command, as it will be used in the next step. -
Create a new bucket policy for the S3 bucket by running the following command:
aws s3api put-bucket-policy --bucket <bucket-name> --policy '{ "Version": "2012-10-17", "Id": "PutEncryptedBucketPolicy", "Statement": [ { "Sid": "DenyUnEncryptedObjectUploads", "Effect": "Deny", "Principal": "*", "Action": "s3:PutObject", "Resource": "arn:aws:s3:::<bucket-name>/*", "Condition": { "StringNotEquals": { "s3:x-amz-server-side-encryption": "aws:kms" } } }, { "Sid": "RequireCustomerProvidedCMK", "Effect": "Deny", "Principal": "*", "Action": "s3:PutObject", "Resource": "arn:aws:s3:::<bucket-name>/*", "Condition": { "Null": { "s3:x-amz-server-side-encryption-aws-kms-key-id": "true" } } }, { "Sid": "AllowEncryptedObjectUploads", "Effect": "Allow", "Principal": "*", "Action": "s3:PutObject", "Resource": "arn:aws:s3:::<bucket-name>/*", "Condition": { "StringEquals": { "s3:x-amz-server-side-encryption": "aws:kms" }, "StringEquals": { "s3:x-amz-server-side-encryption-aws-kms-key-id": "<KeyId>" } } } ] }'
Replace
<bucket-name>
with the name of the S3 bucket and<KeyId>
with theKeyId
value obtained in step 6. -
Verify that the S3 bucket is now encrypted with the Customer-Provided CMK by running the following command:
aws s3api get-bucket-encryption --bucket <bucket-name>
The output of the above command should show that the S3 bucket is now encrypted with the Customer-Provided CMK.
-
Repeat the above steps for any other S3 buckets that need to be remediated.
To remediate the S3 Buckets should be encrypted with customer-provided CMKs misconfiguration in AWS using Python, follow these steps:
- Identify the S3 buckets that are not encrypted with customer-provided CMKs. You can use the following Python code to list all the S3 buckets in your AWS account:
import boto3
s3 = boto3.client('s3')
response = s3.list_buckets()
for bucket in response['Buckets']:
print(bucket['Name'])
- For each S3 bucket that is not encrypted with customer-provided CMKs, enable default encryption with a customer-provided CMK. You can use the following Python code to enable default encryption for an S3 bucket:
import boto3
s3 = boto3.client('s3')
bucket_name = 'your-bucket-name'
kms_key_id = 'your-kms-key-id'
s3.put_bucket_encryption(
Bucket=bucket_name,
ServerSideEncryptionConfiguration={
'Rules': [
{
'ApplyServerSideEncryptionByDefault': {
'SSEAlgorithm': 'aws:kms',
'KMSMasterKeyID': kms_key_id
}
}
]
}
)
Replace your-bucket-name
with the name of the S3 bucket and your-kms-key-id
with the ID of the customer-provided CMK.
- Verify that the S3 bucket is now encrypted with the customer-provided CMK. You can use the following Python code to check the encryption status of an S3 bucket:
import boto3
s3 = boto3.client('s3')
bucket_name = 'your-bucket-name'
response = s3.get_bucket_encryption(
Bucket=bucket_name
)
print(response)
This will print the encryption configuration for the S3 bucket, including the customer-provided CMK ID.
Repeat these steps for all the S3 buckets that are not encrypted with customer-provided CMKs.