Skip to content

Conversation

@badmintoncryer
Copy link
Contributor

@badmintoncryer badmintoncryer commented Nov 30, 2025

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)

  • Added MtlsMode enum with REQUIRED and OPTIONAL values
  • Added ViewerMtlsConfig interface with flat structure:
    • mode: mTLS enforcement mode
    • trustStore: Interface of the CloudFront TrustStore
    • advertiseTrustStoreCaNames: Optional flag to advertise CA names during TLS handshake
    • ignoreCertificateExpiry: Optional flag to accept expiredcertificates
  • Added viewerMtlsConfig property to DistributionProps

Add 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

@github-actions github-actions bot added the p2 label Nov 30, 2025
@aws-cdk-automation aws-cdk-automation requested a review from a team November 30, 2025 01:20
@github-actions github-actions bot added the distinguished-contributor [Pilot] contributed 50+ PRs to the CDK label Nov 30, 2025
@aws-cdk-automation aws-cdk-automation added pr/needs-further-review PR requires additional review from our team specialists due to the scope or complexity of changes. pr/needs-community-review This PR needs a review from a Trusted Community Member or Core Team Member. labels Nov 30, 2025
@aws-cdk-automation aws-cdk-automation removed the pr/needs-further-review PR requires additional review from our team specialists due to the scope or complexity of changes. label Nov 30, 2025
@badmintoncryer
Copy link
Contributor Author

It might be better to avoid using NodejsFunction in integ test.

Copy link
Contributor

@mazyu36 mazyu36 left a 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', {
Copy link
Contributor

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.

Copy link
Contributor Author

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?​​​​​​​​​​​​​​​​

Copy link
Contributor

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.

Copy link
Contributor Author

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.

Copy link
Collaborator

@aws-cdk-automation aws-cdk-automation left a 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)

@github-actions
Copy link
Contributor

github-actions bot commented Dec 5, 2025

TestsPassed ☑️SkippedFailed ❌️
Security Guardian Results52 ran50 passed0 skipped2 failed
TestResult
Security Guardian Results
packages/@aws-cdk-testing/framework-integ/test/aws-cloudfront/test/integ.distribution-mtls.js.snapshot/integ-distribution-mtls.template.json
iam-no-wildcard-actions-inline.guard❌ failure
s3-encryption-enabled.guard❌ failure

@github-actions
Copy link
Contributor

github-actions bot commented Dec 5, 2025

TestsPassed ☑️SkippedFailed ❌️
Security Guardian Results with resolved templates52 ran50 passed0 skipped2 failed
TestResult
Security Guardian Results with resolved templates
packages/@aws-cdk-testing/framework-integ/test/aws-cloudfront/test/integ.distribution-mtls.js.snapshot/integ-distribution-mtls.template.json
iam-no-wildcard-actions-inline.guard❌ failure
s3-encryption-enabled.guard❌ failure

@aws-cdk-automation aws-cdk-automation dismissed their stale review December 5, 2025 13:57

✅ Updated pull request passes all PRLinter validations. Dismissing previous PRLinter review.

@aws-cdk-automation aws-cdk-automation added the pr/needs-further-review PR requires additional review from our team specialists due to the scope or complexity of changes. label Dec 5, 2025
return;
}

if (name.length < 1 || name.length > 64) {
Copy link
Contributor Author

@badmintoncryer badmintoncryer Dec 5, 2025

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.
Copy link
Contributor Author

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;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Copy link
Contributor

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?

@badmintoncryer
Copy link
Contributor Author

@mazyu36 I've added TrustStore L2 construct! Could you please review this PR?

Copy link
Contributor

@mazyu36 mazyu36 left a 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.
Copy link
Contributor

@mazyu36 mazyu36 Dec 7, 2025

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;
Copy link
Contributor

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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

distinguished-contributor [Pilot] contributed 50+ PRs to the CDK p2 pr/needs-community-review This PR needs a review from a Trusted Community Member or Core Team Member. pr/needs-further-review PR requires additional review from our team specialists due to the scope or complexity of changes.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants