-
Notifications
You must be signed in to change notification settings - Fork 3.9k
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
fix(cloudfront): OriginShield not easily disabled once enabled on an origin #22791
Merged
Merged
Changes from 13 commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
8eb4608
fix(cloudfront): OriginShield not easily disabled once enabled on an …
8f9114a
fix(cloudfront-origins): fixed integ and unit tests so they are compa…
dc01ab5
Merge branch 'main' of github.com:bradlead/aws-cdk
d75f098
Added originShieldEnabled and created new tests
4bc9605
Returning integ snapshots to previous state
06d8cf5
updated dependent integ snapshot
e9bc21d
Removing previous changes to integ snapshots
6456dd5
Added and ran integ test
948728e
Delete =
mrgrain 0585c56
Improved description and open ended If statement
d853f84
Merge branch 'main' of github.com:bradlead/aws-cdk
3212956
Merge branch 'main' into main
bradlead 56f5660
Merge branch 'main' of github.com:bradlead/aws-cdk
5487a8c
simplified types
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -82,6 +82,13 @@ export interface OriginOptions { | |||||
*/ | ||||||
readonly originShieldRegion?: string; | ||||||
|
||||||
/** | ||||||
* Origin Shield is enabled by setting originShieldRegion to a valid region, after this to disable Origin Shield again you must set this flag to false. | ||||||
* | ||||||
* @default - true | ||||||
*/ | ||||||
readonly originShieldEnabled?: boolean; | ||||||
|
||||||
/** | ||||||
* A unique identifier for the origin. This value must be unique within the distribution. | ||||||
* | ||||||
|
@@ -114,6 +121,7 @@ export interface OriginBindOptions { | |||||
readonly originId: string; | ||||||
} | ||||||
|
||||||
|
||||||
/** | ||||||
* Represents a distribution origin, that describes the Amazon S3 bucket, HTTP server (for example, a web server), | ||||||
* Amazon MediaStore, or other server from which CloudFront gets your files. | ||||||
|
@@ -124,7 +132,8 @@ export abstract class OriginBase implements IOrigin { | |||||
private readonly connectionTimeout?: Duration; | ||||||
private readonly connectionAttempts?: number; | ||||||
private readonly customHeaders?: Record<string, string>; | ||||||
private readonly originShieldRegion?: string | ||||||
private readonly originShieldRegion?: string; | ||||||
private readonly originShieldEnabled?: (true | boolean); | ||||||
private readonly originId?: string; | ||||||
|
||||||
protected constructor(domainName: string, props: OriginProps = {}) { | ||||||
|
@@ -139,6 +148,7 @@ export abstract class OriginBase implements IOrigin { | |||||
this.customHeaders = props.customHeaders; | ||||||
this.originShieldRegion = props.originShieldRegion; | ||||||
this.originId = props.originId; | ||||||
this.originShieldEnabled = props.originShieldEnabled ?? true; | ||||||
} | ||||||
|
||||||
/** | ||||||
|
@@ -162,7 +172,7 @@ export abstract class OriginBase implements IOrigin { | |||||
originCustomHeaders: this.renderCustomHeaders(), | ||||||
s3OriginConfig, | ||||||
customOriginConfig, | ||||||
originShield: this.renderOriginShield(this.originShieldRegion), | ||||||
originShield: this.renderOriginShield(this.originShieldEnabled ?? true, this.originShieldRegion), | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
}, | ||||||
}; | ||||||
} | ||||||
|
@@ -200,10 +210,11 @@ export abstract class OriginBase implements IOrigin { | |||||
/** | ||||||
* Takes origin shield region and converts to CfnDistribution.OriginShieldProperty | ||||||
*/ | ||||||
private renderOriginShield(originShieldRegion?: string): CfnDistribution.OriginShieldProperty | undefined { | ||||||
return originShieldRegion | ||||||
? { enabled: true, originShieldRegion } | ||||||
: undefined; | ||||||
private renderOriginShield(originShieldEnabled: boolean, originShieldRegion?: string): CfnDistribution.OriginShieldProperty | undefined { | ||||||
if (!originShieldEnabled) { | ||||||
return { enabled: false }; | ||||||
} | ||||||
return originShieldRegion ? { enabled: true, originShieldRegion } : undefined; | ||||||
} | ||||||
} | ||||||
|
||||||
|
19 changes: 19 additions & 0 deletions
19
...in-shield.js.snapshot/DistributionOriginShieldDefaultTestDeployAssertDF7E33F9.assets.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
{ | ||
"version": "21.0.0", | ||
"files": { | ||
"21fbb51d7b23f6a6c262b46a9caee79d744a3ac019fd45422d988b96d44b2a22": { | ||
"source": { | ||
"path": "DistributionOriginShieldDefaultTestDeployAssertDF7E33F9.template.json", | ||
"packaging": "file" | ||
}, | ||
"destinations": { | ||
"current_account-current_region": { | ||
"bucketName": "cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}", | ||
"objectKey": "21fbb51d7b23f6a6c262b46a9caee79d744a3ac019fd45422d988b96d44b2a22.json", | ||
"assumeRoleArn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-file-publishing-role-${AWS::AccountId}-${AWS::Region}" | ||
} | ||
} | ||
} | ||
}, | ||
"dockerImages": {} | ||
} |
36 changes: 36 additions & 0 deletions
36
...-shield.js.snapshot/DistributionOriginShieldDefaultTestDeployAssertDF7E33F9.template.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
{ | ||
"Parameters": { | ||
"BootstrapVersion": { | ||
"Type": "AWS::SSM::Parameter::Value<String>", | ||
"Default": "/cdk-bootstrap/hnb659fds/version", | ||
"Description": "Version of the CDK Bootstrap resources in this environment, automatically retrieved from SSM Parameter Store. [cdk:skip]" | ||
} | ||
}, | ||
"Rules": { | ||
"CheckBootstrapVersion": { | ||
"Assertions": [ | ||
{ | ||
"Assert": { | ||
"Fn::Not": [ | ||
{ | ||
"Fn::Contains": [ | ||
[ | ||
"1", | ||
"2", | ||
"3", | ||
"4", | ||
"5" | ||
], | ||
{ | ||
"Ref": "BootstrapVersion" | ||
} | ||
] | ||
} | ||
] | ||
}, | ||
"AssertDescription": "CDK bootstrap stack version 6 required. Please run 'cdk bootstrap' with a recent version of the CDK CLI." | ||
} | ||
] | ||
} | ||
} | ||
} |
1 change: 1 addition & 0 deletions
1
packages/@aws-cdk/aws-cloudfront/test/integ.distribution-origin-shield.js.snapshot/cdk.out
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
{"version":"21.0.0"} |
19 changes: 19 additions & 0 deletions
19
...integ.distribution-origin-shield.js.snapshot/integ-distribution-origin-shield.assets.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
{ | ||
"version": "21.0.0", | ||
"files": { | ||
"2dad510c7288df819a57567a15bdbfd3396640d1c4a5b7dbb139c67cc8cd290a": { | ||
"source": { | ||
"path": "integ-distribution-origin-shield.template.json", | ||
"packaging": "file" | ||
}, | ||
"destinations": { | ||
"current_account-current_region": { | ||
"bucketName": "cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}", | ||
"objectKey": "2dad510c7288df819a57567a15bdbfd3396640d1c4a5b7dbb139c67cc8cd290a.json", | ||
"assumeRoleArn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-file-publishing-role-${AWS::AccountId}-${AWS::Region}" | ||
} | ||
} | ||
} | ||
}, | ||
"dockerImages": {} | ||
} |
66 changes: 66 additions & 0 deletions
66
...teg.distribution-origin-shield.js.snapshot/integ-distribution-origin-shield.template.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
{ | ||
"Resources": { | ||
"DistB3B78991": { | ||
"Type": "AWS::CloudFront::Distribution", | ||
"Properties": { | ||
"DistributionConfig": { | ||
"DefaultCacheBehavior": { | ||
"CachePolicyId": "658327ea-f89d-4fab-a63d-7e88639e58f6", | ||
"Compress": true, | ||
"TargetOriginId": "integdistributionoriginshieldDistOrigin11F51234E", | ||
"ViewerProtocolPolicy": "allow-all" | ||
}, | ||
"Enabled": true, | ||
"HttpVersion": "http2", | ||
"IPV6Enabled": true, | ||
"Origins": [ | ||
{ | ||
"CustomOriginConfig": { | ||
"OriginProtocolPolicy": "https-only" | ||
}, | ||
"DomainName": "www.example.com", | ||
"Id": "integdistributionoriginshieldDistOrigin11F51234E", | ||
"OriginShield": { | ||
"Enabled": false | ||
} | ||
} | ||
] | ||
} | ||
} | ||
} | ||
}, | ||
"Parameters": { | ||
"BootstrapVersion": { | ||
"Type": "AWS::SSM::Parameter::Value<String>", | ||
"Default": "/cdk-bootstrap/hnb659fds/version", | ||
"Description": "Version of the CDK Bootstrap resources in this environment, automatically retrieved from SSM Parameter Store. [cdk:skip]" | ||
} | ||
}, | ||
"Rules": { | ||
"CheckBootstrapVersion": { | ||
"Assertions": [ | ||
{ | ||
"Assert": { | ||
"Fn::Not": [ | ||
{ | ||
"Fn::Contains": [ | ||
[ | ||
"1", | ||
"2", | ||
"3", | ||
"4", | ||
"5" | ||
], | ||
{ | ||
"Ref": "BootstrapVersion" | ||
} | ||
] | ||
} | ||
] | ||
}, | ||
"AssertDescription": "CDK bootstrap stack version 6 required. Please run 'cdk bootstrap' with a recent version of the CDK CLI." | ||
} | ||
] | ||
} | ||
} | ||
} |
12 changes: 12 additions & 0 deletions
12
...ages/@aws-cdk/aws-cloudfront/test/integ.distribution-origin-shield.js.snapshot/integ.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
{ | ||
"version": "21.0.0", | ||
"testCases": { | ||
"DistributionOriginShield/DefaultTest": { | ||
"stacks": [ | ||
"integ-distribution-origin-shield" | ||
], | ||
"assertionStack": "DistributionOriginShield/DefaultTest/DeployAssert", | ||
"assertionStackName": "DistributionOriginShieldDefaultTestDeployAssertDF7E33F9" | ||
} | ||
} | ||
} |
111 changes: 111 additions & 0 deletions
111
...s/@aws-cdk/aws-cloudfront/test/integ.distribution-origin-shield.js.snapshot/manifest.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,111 @@ | ||
{ | ||
"version": "21.0.0", | ||
"artifacts": { | ||
"Tree": { | ||
"type": "cdk:tree", | ||
"properties": { | ||
"file": "tree.json" | ||
} | ||
}, | ||
"integ-distribution-origin-shield.assets": { | ||
"type": "cdk:asset-manifest", | ||
"properties": { | ||
"file": "integ-distribution-origin-shield.assets.json", | ||
"requiresBootstrapStackVersion": 6, | ||
"bootstrapStackVersionSsmParameter": "/cdk-bootstrap/hnb659fds/version" | ||
} | ||
}, | ||
"integ-distribution-origin-shield": { | ||
"type": "aws:cloudformation:stack", | ||
"environment": "aws://unknown-account/unknown-region", | ||
"properties": { | ||
"templateFile": "integ-distribution-origin-shield.template.json", | ||
"validateOnSynth": false, | ||
"assumeRoleArn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-deploy-role-${AWS::AccountId}-${AWS::Region}", | ||
"cloudFormationExecutionRoleArn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-cfn-exec-role-${AWS::AccountId}-${AWS::Region}", | ||
"stackTemplateAssetObjectUrl": "s3://cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}/2dad510c7288df819a57567a15bdbfd3396640d1c4a5b7dbb139c67cc8cd290a.json", | ||
"requiresBootstrapStackVersion": 6, | ||
"bootstrapStackVersionSsmParameter": "/cdk-bootstrap/hnb659fds/version", | ||
"additionalDependencies": [ | ||
"integ-distribution-origin-shield.assets" | ||
], | ||
"lookupRole": { | ||
"arn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-lookup-role-${AWS::AccountId}-${AWS::Region}", | ||
"requiresBootstrapStackVersion": 8, | ||
"bootstrapStackVersionSsmParameter": "/cdk-bootstrap/hnb659fds/version" | ||
} | ||
}, | ||
"dependencies": [ | ||
"integ-distribution-origin-shield.assets" | ||
], | ||
"metadata": { | ||
"/integ-distribution-origin-shield/Dist/Resource": [ | ||
{ | ||
"type": "aws:cdk:logicalId", | ||
"data": "DistB3B78991" | ||
} | ||
], | ||
"/integ-distribution-origin-shield/BootstrapVersion": [ | ||
{ | ||
"type": "aws:cdk:logicalId", | ||
"data": "BootstrapVersion" | ||
} | ||
], | ||
"/integ-distribution-origin-shield/CheckBootstrapVersion": [ | ||
{ | ||
"type": "aws:cdk:logicalId", | ||
"data": "CheckBootstrapVersion" | ||
} | ||
] | ||
}, | ||
"displayName": "integ-distribution-origin-shield" | ||
}, | ||
"DistributionOriginShieldDefaultTestDeployAssertDF7E33F9.assets": { | ||
"type": "cdk:asset-manifest", | ||
"properties": { | ||
"file": "DistributionOriginShieldDefaultTestDeployAssertDF7E33F9.assets.json", | ||
"requiresBootstrapStackVersion": 6, | ||
"bootstrapStackVersionSsmParameter": "/cdk-bootstrap/hnb659fds/version" | ||
} | ||
}, | ||
"DistributionOriginShieldDefaultTestDeployAssertDF7E33F9": { | ||
"type": "aws:cloudformation:stack", | ||
"environment": "aws://unknown-account/unknown-region", | ||
"properties": { | ||
"templateFile": "DistributionOriginShieldDefaultTestDeployAssertDF7E33F9.template.json", | ||
"validateOnSynth": false, | ||
"assumeRoleArn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-deploy-role-${AWS::AccountId}-${AWS::Region}", | ||
"cloudFormationExecutionRoleArn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-cfn-exec-role-${AWS::AccountId}-${AWS::Region}", | ||
"stackTemplateAssetObjectUrl": "s3://cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}/21fbb51d7b23f6a6c262b46a9caee79d744a3ac019fd45422d988b96d44b2a22.json", | ||
"requiresBootstrapStackVersion": 6, | ||
"bootstrapStackVersionSsmParameter": "/cdk-bootstrap/hnb659fds/version", | ||
"additionalDependencies": [ | ||
"DistributionOriginShieldDefaultTestDeployAssertDF7E33F9.assets" | ||
], | ||
"lookupRole": { | ||
"arn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-lookup-role-${AWS::AccountId}-${AWS::Region}", | ||
"requiresBootstrapStackVersion": 8, | ||
"bootstrapStackVersionSsmParameter": "/cdk-bootstrap/hnb659fds/version" | ||
} | ||
}, | ||
"dependencies": [ | ||
"DistributionOriginShieldDefaultTestDeployAssertDF7E33F9.assets" | ||
], | ||
"metadata": { | ||
"/DistributionOriginShield/DefaultTest/DeployAssert/BootstrapVersion": [ | ||
{ | ||
"type": "aws:cdk:logicalId", | ||
"data": "BootstrapVersion" | ||
} | ||
], | ||
"/DistributionOriginShield/DefaultTest/DeployAssert/CheckBootstrapVersion": [ | ||
{ | ||
"type": "aws:cdk:logicalId", | ||
"data": "CheckBootstrapVersion" | ||
} | ||
] | ||
}, | ||
"displayName": "DistributionOriginShield/DefaultTest/DeployAssert" | ||
} | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.