Skip to content

feat(cloudfront-origins): add mutual TLS (mTLS) authentication support for custom origins#37316

Open
kawaaaas wants to merge 4 commits intoaws:mainfrom
kawaaaas:feature/add-mtls-support-for-cloudfront-origins
Open

feat(cloudfront-origins): add mutual TLS (mTLS) authentication support for custom origins#37316
kawaaaas wants to merge 4 commits intoaws:mainfrom
kawaaaas:feature/add-mtls-support-for-cloudfront-origins

Conversation

@kawaaaas
Copy link
Copy Markdown

Issue # (if applicable)

N/A

Reason for this change

CloudFront now supports mutual TLS (mTLS) authentication between CloudFront and custom origins via the OriginMtlsConfig property on CustomOriginConfig. This allows CloudFront to present a client certificate from ACM when connecting to the origin, enabling two-way TLS authentication.

Currently, the CDK L1 construct (CfnDistribution) already supports OriginMtlsConfig through the latest CloudFormation resource spec update, but there is no L2 support for configuring mTLS on origin classes.

Description of changes

The L1 construct (CfnDistribution) already supports OriginMtlsConfig with ClientCertificateArn inside CustomOriginConfig through the CloudFormation resource spec. This PR adds L2 support for it.

  • Added OriginMtlsConfig interface to aws-cloudfront (origin.ts) with a clientCertificate property accepting ICertificateRef.
  • Added originMtlsConfig property to the following origin classes that use CustomOriginConfig:
    • HttpOrigin
    • RestApiOrigin
    • FunctionUrlOrigin (both standard and OAC variant via FunctionUrlOriginWithOAC)

These origins each independently render originMtlsConfig in their _renderCustomOriginConfig() method. While this introduces some duplication, it follows the same pattern used by ipAddressType and other origin-specific properties, preserving backward compatibility and keeping each origin class self-contained.

Note on clientCertificate.certificateRef.certificateId
The implementation uses clientCertificate.certificateRef.certificateId to obtain the certificate ARN. This works because CertificateBase (which backs ICertificateRef) returns the full ARN from certificateId. This is consistent with how other CDK constructs resolve certificate references.

Origins NOT covered (by design):

  • S3BucketOrigin / S3Origin — uses S3OriginConfig, not CustomOriginConfig
  • VpcOrigin — uses VpcOriginConfig, not CustomOriginConfig
  • S3StaticWebsiteOrigin — inherits HttpOriginProps via HttpOrigin, so originMtlsConfig is exposed at the type level. However, S3 website endpoints only support HTTP, so HTTP_ONLY is forced and the validation added in this PR will reject the combination at construction time.

Describe any new or updated permissions being added

None

Description of how you validated changes

Unit tests:

  • HttpOrigin: verifies originMtlsConfig is rendered with the correct clientCertificateArn
  • RestApiOrigin: verifies originMtlsConfig is rendered with the correct clientCertificateArn
  • FunctionUrlOrigin: verifies both standard and OAC variants render originMtlsConfig correctly

Integration tests:

  • Added integ.http-origin-mtls.ts, integ.rest-api-origin-mtls.ts, and integ.function-url-origin-mtls.ts
  • These integration tests require a manually imported ACM client certificate with EKU TLS Web Client Authentication (OID 1.3.6.1.5.5.7.3.2). Standard ACM-issued certificates will be rejected by CloudFront.
  • The certificate ARN must be provided via CDK_INTEG_ACM_CERT_ARN or ACM_CERT_ARN environment variable.

To reviewers: I was unable to run the integration tests myself as they require a real ACM client certificate. I would appreciate it if a reviewer could validate them. Also, if there is a more appropriate way to structure integration tests that depend on pre-existing resources (e.g., using a fixture or a different pattern), I'm happy to adjust.

Checklist


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

@aws-cdk-automation aws-cdk-automation requested a review from a team March 23, 2026 03:41
@github-actions github-actions bot added the p2 label Mar 23, 2026
@github-actions github-actions bot added the beginning-contributor [Pilot] contributed between 0-2 PRs to the CDK label Mar 23, 2026
@kawaaaas kawaaaas changed the title Feature/add mtls support for cloudfront origins feat(cloudfront-origins): add mutual TLS (mTLS) authentication support for custom origins Mar 23, 2026
Copy link
Copy Markdown
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.

The pull request linter fails with the following errors:

❌ Features must contain a change to an integration test file and the resulting snapshot.

If you believe this pull request should receive an exemption, please comment and provide a justification. A comment requesting an exemption should contain the text Exemption Request. Additionally, if clarification is needed, add Clarification Request to a comment.

✅ A exemption request has been requested. Please wait for a maintainer's review.

@kawaaaas
Copy link
Copy Markdown
Author

Exemption Request

Integration test files (integ.http-origin-mtls.ts, integ.rest-api-origin-mtls.ts, integ.function-url-origin-mtls.ts) are included in this PR, but snapshots are not provided because these tests require a manually imported ACM client certificate with Extended Key Usage set to "TLS Web Client Authentication" (OID 1.3.6.1.5.5.7.3.2). Standard ACM-issued certificates do not have this EKU and will be rejected by CloudFront.

As noted in the contributing guide, I am unable to run the cdk-integ tool for a real deployment and am requesting that a maintainer run the integration tests and generate the snapshots.

@aws-cdk-automation aws-cdk-automation added the pr-linter/exemption-requested The contributor has requested an exemption to the PR Linter feedback. label Mar 23, 2026
@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 Mar 23, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

beginning-contributor [Pilot] contributed between 0-2 PRs to the CDK p2 pr/needs-further-review PR requires additional review from our team specialists due to the scope or complexity of changes. pr-linter/exemption-requested The contributor has requested an exemption to the PR Linter feedback.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants