Skip to main content

Triage and Remediation

Remediation

Using Console

Sure, here are the steps to remediate the misconfiguration “Origin Access Identity should be enabled for CloudFront distributions” in AWS using AWS console:
  1. Log in to the AWS Management Console.
  2. Navigate to the CloudFront service.
  3. Select the distribution for which you want to enable Origin Access Identity.
  4. Click on the “Behaviors” tab.
  5. Select the behavior for which you want to enable Origin Access Identity.
  6. Click on the “Edit” button.
  7. In the “Origin Settings” section, select “Yes” for “Restrict Bucket Access”.
  8. Select “Create a New Identity” under “Origin Access Identity”.
  9. Provide a name for the new identity and click on the “Create” button.
  10. Click on the “Yes, Edit” button to save the changes.
By following these steps, you have successfully enabled Origin Access Identity for the CloudFront distribution and remediated the misconfiguration.

To remediate this misconfiguration in 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 CloudFront distributions in your AWS account:
  1. Identify the distribution for which the Origin Access Identity should be enabled.
  2. Run the following command to update the distribution configuration and enable Origin Access Identity:
Replace the following placeholders with actual values:
  • <distribution-id>: The ID of the CloudFront distribution.
  • <origin-id>: The ID of the origin for which Origin Access Identity should be enabled.
  • <origin-domain-name>: The domain name of the origin for which Origin Access Identity should be enabled.
  • <origin-access-identity>: The ARN of the Origin Access Identity that should be associated with the origin.
  1. After running the command, the CloudFront distribution configuration will be updated, and Origin Access Identity will be enabled for the specified origin.
Note: Make sure you have the necessary permissions to update the CloudFront distribution configuration.
To remediate the misconfiguration “Origin Access Identity should be enabled for CloudFront distributions” in AWS using Python, follow the below steps:
  1. Import the required libraries:
  1. Create a CloudFront client:
  1. Get the list of all distributions:
  1. Loop through the distributions and check if Origin Access Identity is enabled:
  1. Replace 'origin-access-identity/cloudfront/XXXXXXXXXXXX' with the actual Origin Access Identity that you want to use.
  2. Run the Python script to remediate the misconfiguration.
With these steps, you can remediate the misconfiguration “Origin Access Identity should be enabled for CloudFront distributions” in AWS using Python.
Substitute:
  • S3_ORIGIN_BUCKET_NAME with your S3 origin bucket name.
  • Add all other required arguments to aws_cloudfront_distribution.CLOUDFRONT_DISTRIBUTION (commented as “…”).
This change updates the CloudFront distribution in place (it does not force resource replacement) but will trigger a distribution update that must propagate to edge locations.For verification, terraform plan should show:
  • A new aws_cloudfront_origin_access_control resource.
  • An in-place update to aws_cloudfront_distribution adding origin_access_control_id and removing any OAI usage.
  • A create or update of aws_s3_bucket_policy with a statement allowing cloudfront.amazonaws.com with the AWS:SourceArn condition referencing the distribution ARN.