-
Notifications
You must be signed in to change notification settings - Fork 4.3k
feat(cloudfront): mutual TLS #36245
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
base: main
Are you sure you want to change the base?
feat(cloudfront): mutual TLS #36245
Conversation
...framework-integ/test/aws-cloudfront/test/integ.distribution-mtls.assets/mtls-test-handler.ts
Fixed
Show fixed
Hide fixed
...4059581719d059fbdfc854912e8a27be60d7784f4bf89aae78071ca0219ecb40.assets/mtls-test-handler.js
Fixed
Show fixed
Hide fixed
...8fa19fb03891638e9070c4bee8ad539f11932b9cd7f884f6570b5622df2fc78c.assets/mtls-test-handler.js
Fixed
Show fixed
Hide fixed
|
It might be better to avoid using NodejsFunction in integ test. |
mazyu36
left a comment
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.
Thanks for the contribution. Before reviewing, let me confirm the implementation direction.
| }); | ||
|
|
||
| // Create TrustStore using L1 construct (CfnTrustStore) | ||
| const trustStore = new cloudfront.CfnTrustStore(this, 'TrustStore', { |
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.
Is there any reason why the trust store is not implemented as an L2 construct?
I don't think creating L2 constructs is mandatory, so if you have a reason, please let me know.
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.
Of course, I’m planning to implement it! My initial thought was to merge this PR first, then implement the L2 for truststore while deprecating truststoreId.
However, I’m starting to think it might not be ideal to implement an argument that will soon become obsolete. So it might be better to either implement the L2 first, or include it in this PR.
That said, including the L2 implementation might make this PR a bit too large. What are your thoughts on this?
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.
Thank you.
In my opinion, if you are going to deprecate the property after implementing L2, it would be better to implement L2 from the beginning. I don't think the trust store itself will be a very complex construct.
If you're not going to deprecate it, I think the current policy is fine.
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.
Sure! I'll add TruestStore L2 construct in this PR. Please wait for a while.
…ruct and simplify S3 bucket reference
…d update validation
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.
(This review is outdated)
|
||||||||||||||||||||
|
||||||||||||||||||||
✅ Updated pull request passes all PRLinter validations. Dismissing previous PRLinter review.
| return; | ||
| } | ||
|
|
||
| if (name.length < 1 || name.length > 64) { |
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.
Names with 65 or more characters were rejected as an error.
Resource handler returned message: "Invalid request provided: AWS::CloudFront::TrustStore: The request contains an invalid TrustStore name. (Service: CloudFront, Status Code: 400, Request ID: 5c270f44-3775-440c-a4af-41e02ee0d3d2) (SDK Attempt Count: 1)" (RequestToken: fc166deb-1f5c-5130-4875-684a71de8efb, HandlerErrorCode: InvalidRequest)
Names with only 1 character result in an error in the Management Console, but could be created via CloudFormation.
Therefore, I have implemented validation for 1-64 characters.
| } | ||
|
|
||
| // Validate viewerProtocolPolicy - mTLS requires HTTPS. | ||
| // When viewerProtocolPolicy is not specified, it defaults to ALLOW_ALL which is not compatible with mTLS. |
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.
ViewerProtocolPolicy.ALLOW_ALL with mTLS configuration causes deployment error.
Resource handler returned message: "Invalid request provided: AWS::CloudFront::Distribution: The parameter ViewerMutualAuthentication cannot be enabled when cache behaviors allow HTTP. (Service: CloudFront, Status Code: 400, Request ID: 936f22cb-4e79-4671-8dd3-49145f995dd2) (SDK Attempt Count: 1)" (RequestToken: a45f9420-c513-9105-637b-0aa3c531a1b8, HandlerErrorCode: InvalidRequest)
| // Validate viewerProtocolPolicy - mTLS requires HTTPS. | ||
| // When viewerProtocolPolicy is not specified, it defaults to ALLOW_ALL which is not compatible with mTLS. | ||
| const validPolicies = [ViewerProtocolPolicy.HTTPS_ONLY, ViewerProtocolPolicy.REDIRECT_TO_HTTPS]; | ||
| const defaultPolicy = props.defaultBehavior.viewerProtocolPolicy ?? ViewerProtocolPolicy.ALLOW_ALL; |
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.
Default behavior of viewerProtocolPolicy is ALLOW_ALL.
https://github.com/aws/aws-cdk/blob/main/packages/aws-cdk-lib/aws-cloudfront/lib/distribution.ts#L1149
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.
I understand that even if the default value ALLOW_ALL is set, it will result in an error with the next validation.
It might be a matter of preference, but the behavior where an error occurs after the default value is supplemented could be confusing.
Would it be acceptable to raise an error if it is not specified?
|
@mazyu36 I've added TrustStore L2 construct! Could you please review this PR? |
mazyu36
left a comment
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.
Thanks. Great work!
I've added two minor comments.
| }); | ||
| ``` | ||
|
|
||
| See [Configuring mutual TLS authentication](https://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/private-content-mutual-tls.html) in the CloudFront User Guide. |
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.
I can't access the link. It may have been changed.
Is this the link you were referring to?
https://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/mtls-authentication.html
| // Validate viewerProtocolPolicy - mTLS requires HTTPS. | ||
| // When viewerProtocolPolicy is not specified, it defaults to ALLOW_ALL which is not compatible with mTLS. | ||
| const validPolicies = [ViewerProtocolPolicy.HTTPS_ONLY, ViewerProtocolPolicy.REDIRECT_TO_HTTPS]; | ||
| const defaultPolicy = props.defaultBehavior.viewerProtocolPolicy ?? ViewerProtocolPolicy.ALLOW_ALL; |
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.
I understand that even if the default value ALLOW_ALL is set, it will result in an error with the next validation.
It might be a matter of preference, but the behavior where an error occurs after the default value is supplemented could be confusing.
Would it be acceptable to raise an error if it is not specified?
Issue # (if applicable)
None
Reason for this change
AWS cloudfront now supports for mTLS authentication.
https://aws.amazon.com/jp/about-aws/whats-new/2025/11/amazon-cloudfront-mutual-tls-authentication/
Description of changes
L2 Construct Implementation
(distribution.ts)
MtlsModeenum withREQUIREDandOPTIONALvaluesViewerMtlsConfiginterface with flat structure:mode: mTLS enforcement modetrustStore: Interface of the CloudFront TrustStoreadvertiseTrustStoreCaNames: Optional flag to advertise CA names during TLS handshakeignoreCertificateExpiry: Optional flag to accept expiredcertificatesviewerMtlsConfigproperty toDistributionPropsAdd truststore L2 construct.
Describe any new or updated permissions being added
None
Description of how you validated changes
added both unit and integ tests
Checklist
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license