Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(cloudfront): Add new cloudfront_distributions_s3_origin_access_control check to ensure OAC is configured in distributions #4939

Conversation

HugoPBrito
Copy link
Member

@HugoPBrito HugoPBrito commented Sep 5, 2024

Context

Without OAC, users might be able to access S3 content directly, bypassing CloudFront, which can expose sensitive data. OAC limits access to the S3 bucket exclusively through the CloudFront distribution, preventing direct access and offering better security controls compared to the older Origin Access Identity (OAI). This helps reduce the risk of unauthorized access to the S3 origin.

Description

The cloudfront_distributions_s3_origin_access_control check verifies whether OAC is enabled for CloudFront distributions with S3 origins. If OAC is not configured, the check fails, leaving the S3 content potentially vulnerable to direct access. This check ensures that access to the S3 bucket is properly restricted, allowing only traffic routed through the associated CloudFront distribution, enhancing security by enforcing best practices.

Checklist

License

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

@HugoPBrito HugoPBrito requested review from a team as code owners September 5, 2024 15:38
@github-actions github-actions bot added the provider/aws Issues/PRs related with the AWS provider label Sep 5, 2024
Copy link

codecov bot commented Sep 5, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 88.97%. Comparing base (edbe463) to head (dc9759e).
Report is 1208 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #4939      +/-   ##
==========================================
+ Coverage   88.92%   88.97%   +0.04%     
==========================================
  Files         953      957       +4     
  Lines       29237    29340     +103     
==========================================
+ Hits        25999    26105     +106     
+ Misses       3238     3235       -3     
Components Coverage Δ
prowler 88.97% <100.00%> (+0.04%) ⬆️
api ∅ <ø> (∅)

@@ -0,0 +1,32 @@
{
"Provider": "aws",
"CheckID": "cloudfront_distributions_use_origin_access_control",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
"CheckID": "cloudfront_distributions_use_origin_access_control",
"CheckID": "cloudfront_distributions_s3_origin_access_control",

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why you did not use moto here?

{
"Provider": "aws",
"CheckID": "cloudfront_distributions_use_origin_access_control",
"CheckTitle": "Check if CloudFront distributions use OAC.",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
"CheckTitle": "Check if CloudFront distributions use OAC.",
"CheckTitle": "Check if CloudFront distributions with S3 origin use OAC.",

Please, update the metadata adding that is only for CloudFront distributions with S3 origins.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please, only check for CloudFront distributions with S3 origins.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And iterate for the origins in each distribution

@@ -49,6 +49,14 @@ def _get_distribution_config(self, client, distributions, region) -> dict:
try:
for distribution_id in distributions.keys():
distribution_config = client.get_distribution_config(Id=distribution_id)
oac = False
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not needed, since we already have the origins for each distribution.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use the Origin class please.

@MrCloudSec MrCloudSec changed the title feat(cloudfront): Add new cloudfront_distributions_use_origin_access_control check to ensure OAC is configured in distributions feat(cloudfront): Add new cloudfront_distributions_s3_origin_access_control check to ensure OAC is configured in distributions Sep 13, 2024
@MrCloudSec MrCloudSec merged commit 48c31a1 into master Sep 13, 2024
13 checks passed
@MrCloudSec MrCloudSec deleted the PRWLR-4451-ensure-cloud-front-distributions-use-origin-access-control-oac branch September 13, 2024 14:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
provider/aws Issues/PRs related with the AWS provider
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants