Cloudfront Insecure Ssl Remediation
Triage and Remediation
- Remediation
Remediation
Using Console
To remediate the misconfiguration "CloudFront Distributions Should Not Use Insecure SSL Protocols" in AWS using AWS console, follow the below steps:
- Login to your AWS console.
- Go to the CloudFront service.
- Select the distribution which is using insecure SSL protocols.
- Click on the "Edit" button.
- Scroll down to the "SSL Certificate" section.
- In the "Minimum SSL Protocol Version" dropdown, select "TLSv1.2_2018".
- Click on the "Yes, Edit" button to save the changes.
By doing this, you have successfully remediated the misconfiguration "CloudFront Distributions Should Not Use Insecure SSL Protocols" in AWS using AWS console.
Using CLI
To remediate the CloudFront Distributions Should Not Use Insecure SSL Protocols misconfiguration in AWS using AWS CLI, you can follow the below steps:
-
Open your terminal and install AWS CLI if it is not installed already.
-
Run the following command to update the CloudFront distribution to use only secure SSL protocols:
aws cloudfront update-distribution --id <distribution-id> --viewer-protocol-policy https-only
Note: Replace <distribution-id> with the ID of the CloudFront distribution that you want to update.
-
After running the above command, the CloudFront distribution will be updated to use only secure SSL protocols.
-
Verify the changes by checking the SSL protocols used by the CloudFront distribution using the following command:
aws cloudfront get-distribution-config --id <distribution-id> --query "DistributionConfig.ViewerCertificate.MinimumProtocolVersion"
Note: Replace <distribution-id> with the ID of the CloudFront distribution that you updated.
- The output of the above command should show that the minimum SSL protocol version is TLSv1.1 or higher.
By following these steps, you can remediate the CloudFront Distributions Should Not Use Insecure SSL Protocols misconfiguration in AWS using AWS CLI.
Using Python
To remediate the misconfiguration of CloudFront distributions using insecure SSL protocols in AWS using Python, you can follow the below steps:
- Import the required AWS modules and libraries in your Python script:
import boto3
from botocore.exceptions import ClientError
- Create an AWS client for CloudFront using the boto3 library:
cloudfront_client = boto3.client('cloudfront')
- Get a list of all the CloudFront distributions using the
list_distributionsmethod:
response = cloudfront_client.list_distributions()
- Loop through the list of CloudFront distributions and check if they are using insecure SSL protocols. You can do this by checking the value of the
MinimumProtocolVersionparameter. If it is set toSSLv3orTLSv1, then it is using an insecure SSL protocol.
for distribution in response['DistributionList']['Items']:
if distribution['ViewerCertificate']['MinimumProtocolVersion'] in ['SSLv3', 'TLSv1']:
# Remediation steps go here
- To remediate the misconfiguration, you need to update the CloudFront distribution with a secure SSL protocol. You can do this by updating the
ViewerCertificateparameter with a new value forMinimumProtocolVersion. For example, to set it toTLSv1.2_2018, you can use theupdate_distributionmethod:
distribution_id = distribution['Id']
etag = distribution['ETag']
viewer_certificate = {
'CloudFrontDefaultCertificate': False,
'MinimumProtocolVersion': 'TLSv1.2_2018'
}
try:
cloudfront_client.update_distribution(
DistributionConfig={
'ViewerCertificate': viewer_certificate
},
Id=distribution_id,
IfMatch=etag
)
print(f"Successfully updated CloudFront distribution {distribution_id}")
except ClientError as e:
print(f"Error updating CloudFront distribution {distribution_id}: {e}")
- Finally, run the Python script to remediate the misconfiguration for all the CloudFront distributions using insecure SSL protocols.
Using Terraform
resource "aws_cloudfront_distribution" "CLOUDFRONT_DISTRIBUTION_NAME" {
# Replace CLOUDFRONT_DISTRIBUTION_NAME with a suitable local name.
enabled = true
default_root_object = "index.html"
origin {
domain_name = "CUSTOM_ORIGIN_DOMAIN_NAME" # e.g. myapp.example.com
origin_id = "CUSTOM_ORIGIN_ID"
custom_origin_config {
http_port = 80
https_port = 443
origin_protocol_policy = "https-only"
# FIX: only allow secure TLS protocol(s) from CloudFront to the custom origin
origin_ssl_protocols = [
"TLSv1.2",
]
}
}
default_cache_behavior {
target_origin_id = "CUSTOM_ORIGIN_ID"
viewer_protocol_policy = "redirect-to-https"
allowed_methods = ["GET", "HEAD"]
cached_methods = ["GET", "HEAD"]
forwarded_values {
query_string = false
cookies {
forward = "none"
}
}
}
restrictions {
geo_restriction {
restriction_type = "none"
}
}
viewer_certificate {
acm_certificate_arn = "ACM_CERTIFICATE_ARN"
ssl_support_method = "sni-only"
minimum_protocol_version = "TLSv1.2_2021"
}
aliases = ["CLOUDFRONT_ALIAS_DOMAIN_NAME"] # e.g. cdn.example.com
}
This change updates the origin’s origin_ssl_protocols so CloudFront only uses TLSv1.2 when connecting to your custom origin; it is an in‑place update (no distribution replacement), but propagation can take several minutes globally.
To verify, terraform plan should show the existing aws_cloudfront_distribution with a diff changing custom_origin_config.origin_ssl_protocols from the old list (including SSLv3/TLSv1.0/TLSv1.1) to only ["TLSv1.2"], with no create/destroy actions on the distribution itself.