Skip to content
This repository has been archived by the owner on Jan 28, 2025. It is now read-only.

fix(nextjs-cdk-construct): disable public read access of s3 bucket an… #1758

Merged
merged 1 commit into from
Sep 28, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -1742,6 +1742,10 @@ Object {
"GET",
"HEAD",
"OPTIONS",
"PUT",
"PATCH",
"POST",
"DELETE",
],
"CachePolicyId": Object {
"Ref": "StackNextLambdaCacheF214CEF2",
Expand Down Expand Up @@ -2165,25 +2169,6 @@ Object {
},
"PolicyDocument": Object {
"Statement": Array [
Object {
"Action": "s3:GetObject",
"Effect": "Allow",
"Principal": "*",
"Resource": Object {
"Fn::Join": Array [
"",
Array [
Object {
"Fn::GetAtt": Array [
"StackPublicAssets8F0F4FE8",
"Arn",
],
},
"/*",
],
],
},
},
Object {
"Action": Array [
"s3:GetObject*",
Expand Down Expand Up @@ -4280,6 +4265,10 @@ Object {
"GET",
"HEAD",
"OPTIONS",
"PUT",
"PATCH",
"POST",
"DELETE",
],
"CachePolicyId": Object {
"Ref": "StackNextLambdaCacheF214CEF2",
Expand Down Expand Up @@ -4703,25 +4692,6 @@ Object {
},
"PolicyDocument": Object {
"Statement": Array [
Object {
"Action": "s3:GetObject",
"Effect": "Allow",
"Principal": "*",
"Resource": Object {
"Fn::Join": Array [
"",
Array [
Object {
"Fn::GetAtt": Array [
"StackPublicAssets8F0F4FE8",
"Arn",
],
},
"/*",
],
],
},
},
Object {
"Action": Array [
"s3:GetObject*",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ export class NextJSLambdaEdge extends cdk.Construct {
this.defaultManifest = this.readDefaultManifest();
this.prerenderManifest = this.readPrerenderManifest();
this.bucket = new s3.Bucket(this, "PublicAssets", {
publicReadAccess: true,
publicReadAccess: false, // CloudFront/Lambdas are granted access so we don't want it publicly available

// Given this resource is created internally and also should only contain
// assets uploaded by this library we should be able to safely delete all
Expand Down Expand Up @@ -308,7 +308,7 @@ export class NextJSLambdaEdge extends cdk.Construct {
viewerProtocolPolicy:
cloudfront.ViewerProtocolPolicy.REDIRECT_TO_HTTPS,
origin: new origins.S3Origin(this.bucket),
allowedMethods: cloudfront.AllowedMethods.ALLOW_GET_HEAD_OPTIONS,
allowedMethods: cloudfront.AllowedMethods.ALLOW_ALL,
cachedMethods: cloudfront.CachedMethods.CACHE_GET_HEAD_OPTIONS,
compress: true,
cachePolicy: this.nextLambdaCachePolicy,
Expand Down