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-origins): list access level for 404 response #32059

Merged
merged 11 commits into from
Jan 17, 2025

Conversation

Tietew
Copy link
Contributor

@Tietew Tietew commented Nov 8, 2024

Issue # (if applicable)

Closes #13983.
Closes #31689.

Reason for this change

When we want to receive HTTP 404 response where the requested object does not exist,
s3:ListBucket permission is needed in the S3 bucket policy.

Unlike errorResponses to convert 403 response to 404, This is useful to distinguish between responses blocked by WAF (403) and responses where the file does not exist (404).

Description of changes

Added a new AccessLevel.LIST to allow s3:ListBucket.

Description of how you validated changes

Unit test and integration test. The integ test also tests the response is 404.

Checklist


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

@github-actions github-actions bot added the admired-contributor [Pilot] contributed between 13-24 PRs to the CDK label Nov 8, 2024
@aws-cdk-automation aws-cdk-automation requested a review from a team November 8, 2024 04:24
@github-actions github-actions bot added effort/medium Medium work item – several days of effort feature-request A feature should be added or improved. p2 labels Nov 8, 2024
@aws-cdk-automation aws-cdk-automation added the pr/needs-community-review This PR needs a review from a Trusted Community Member or Core Team Member. label Nov 8, 2024
@aws-cdk-automation aws-cdk-automation removed the pr/needs-community-review This PR needs a review from a Trusted Community Member or Core Team Member. label Nov 19, 2024
@gracelu0 gracelu0 added the needs-security-review Related to feature or issues that needs security review label Nov 19, 2024
@Tietew
Copy link
Contributor Author

Tietew commented Nov 19, 2024

@gracelu0 Thank you for your review!
I will add a warning annotation when LIST is specified.

@Tietew
Copy link
Contributor Author

Tietew commented Nov 19, 2024

I created an example CDK project.
It creates an S3 bucket and a CloudFront distribution with OAC. The S3 bucket allows the distribution to s3:GetObject and s3:ListBucket.
https://github.com/Tietew/cdk-cloudfront-listbucket-example

The root path returns the list of objects in the bucket:
https://d1s2487zo3mtd6.cloudfront.net/

A missing object returns 404:
https://d1s2487zo3mtd6.cloudfront.net/missing.html

Regular objects return 200 and their contents:
https://d1s2487zo3mtd6.cloudfront.net/folder/index.html
https://d1s2487zo3mtd6.cloudfront.net/non-folder/index.html

A folder created by S3 console returns 200 and empty content (content-type: application/x-directory):
https://d1s2487zo3mtd6.cloudfront.net/folder/

Without a folder, S3 returns 404:
https://d1s2487zo3mtd6.cloudfront.net/non-folder/

@mergify mergify bot dismissed gracelu0’s stale review November 19, 2024 04:18

Pull request has been modified.

Copy link

codecov bot commented Nov 19, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 81.48%. Comparing base (ddaad47) to head (46103a2).
Report is 1 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main   #32059   +/-   ##
=======================================
  Coverage   81.48%   81.48%           
=======================================
  Files         226      226           
  Lines       13768    13768           
  Branches     2416     2416           
=======================================
  Hits        11219    11219           
  Misses       2271     2271           
  Partials      278      278           
Flag Coverage Δ
suite.unit 81.48% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

Components Coverage Δ
packages/aws-cdk 80.89% <ø> (ø)
packages/aws-cdk-lib/core 82.10% <ø> (ø)

@aws-cdk-automation aws-cdk-automation added the pr/needs-community-review This PR needs a review from a Trusted Community Member or Core Team Member. label Nov 19, 2024
@gracelu0
Copy link
Contributor

@Mergifyio update

Copy link
Contributor

mergify bot commented Jan 17, 2025

update

✅ Branch has been successfully updated

Copy link
Contributor

@gracelu0 gracelu0 left a comment

Choose a reason for hiding this comment

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

Thank you for contributing!

@aws-cdk-automation
Copy link
Collaborator

AWS CodeBuild CI Report

  • CodeBuild project: AutoBuildv2Project1C6BFA3F-wQm2hXv2jqQv
  • Commit ID: 46103a2
  • Result: SUCCEEDED
  • Build Logs (available for 30 days)

Powered by github-codebuild-logs, available on the AWS Serverless Application Repository

Copy link
Contributor

mergify bot commented Jan 17, 2025

Thank you for contributing! Your pull request will be updated from main and then merged automatically (do not update manually, and be sure to allow changes to be pushed to your fork).

@mergify mergify bot merged commit 2b2443d into aws:main Jan 17, 2025
19 of 20 checks passed
Copy link

Comments on closed issues and PRs are hard for our team to see.
If you need help, please open a new issue that references this one.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jan 17, 2025
@Tietew Tietew deleted the cf-oac-listbucket branch January 17, 2025 03:20
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
admired-contributor [Pilot] contributed between 13-24 PRs to the CDK effort/medium Medium work item – several days of effort feature-request A feature should be added or improved. needs-security-review Related to feature or issues that needs security review p2 pr/needs-community-review This PR needs a review from a Trusted Community Member or Core Team Member.
Projects
None yet
3 participants