Skip to content

Commit 6a77e4f

Browse files
authored
feat(elasticloadbalancingv2): support AdvertiseTrustStoreCaNames for mTLS (#32678)
### Issue # (if applicable) N/A ### Reason for this change [AWS Application Load Balancer introduces Certificate Authority advertisement to simplify client behavior while using Mutual TLS](https://aws.amazon.com/about-aws/whats-new/2024/11/aws-application-load-balancer-certificate-authority-advertisement/?nc1=h_ls) Ref: [MutualAuthenticationAttributes](https://docs.aws.amazon.com/elasticloadbalancing/latest/APIReference/API_MutualAuthenticationAttributes.html) ### Description of changes Added advertiseTrustStoreCaNames property for MutualAuthentication. ### Description of how you validated changes Updated `alb/listener.test.ts` and `integ.alb-mtls.ts`. ### Checklist - [x] My code adheres to the [CONTRIBUTING GUIDE](https://github.com/aws/aws-cdk/blob/main/CONTRIBUTING.md) and [DESIGN GUIDELINES](https://github.com/aws/aws-cdk/blob/main/docs/DESIGN_GUIDELINES.md) ---- *By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
1 parent 4327ed0 commit 6a77e4f

File tree

8 files changed

+88
-20
lines changed

8 files changed

+88
-20
lines changed

packages/@aws-cdk-testing/framework-integ/test/aws-elasticloadbalancingv2/test/integ.alb-mtls.js.snapshot/alb-mtls-test-stack.assets.json

+11-11
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/@aws-cdk-testing/framework-integ/test/aws-elasticloadbalancingv2/test/integ.alb-mtls.js.snapshot/alb-mtls-test-stack.template.json

+4-3
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@
161161
"S3Bucket": {
162162
"Fn::Sub": "cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}"
163163
},
164-
"S3Key": "3322b7049fb0ed2b7cbb644a2ada8d1116ff80c32dca89e6ada846b5de26f961.zip"
164+
"S3Key": "f24ba5e516d9d80b64bc7b0f406eedd12c36b20e7461f3e7719b7ffbdad72410.zip"
165165
},
166166
"Description": "/opt/awscli/aws"
167167
}
@@ -181,7 +181,7 @@
181181
}
182182
],
183183
"SourceObjectKeys": [
184-
"9249e6ca38e4bef8f254ff6bd15067180e1d3efae918968740de5a3d24d6417d.zip"
184+
"45e09a26a1a9e47354cc26b2d2d775f9331c818cc47f9876dfda9d800e5cb6e4.zip"
185185
],
186186
"DestinationBucketName": {
187187
"Ref": "Bucket83908E77"
@@ -975,7 +975,7 @@
975975
"S3Bucket": {
976976
"Fn::Sub": "cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}"
977977
},
978-
"S3Key": "bde7b5c89cb43285f884c94f0b9e17cdb0f5eb5345005114dd60342e0b8a85a1.zip"
978+
"S3Key": "a1acfc2b5f4f6b183fd2bb9863f486bc5edef6a357b355a070d9a0e502df418c.zip"
979979
},
980980
"Timeout": 900,
981981
"MemorySize": 128,
@@ -1111,6 +1111,7 @@
11111111
"Ref": "LB8A12904C"
11121112
},
11131113
"MutualAuthentication": {
1114+
"AdvertiseTrustStoreCaNames": "on",
11141115
"IgnoreClientCertificateExpiry": false,
11151116
"Mode": "verify",
11161117
"TrustStoreArn": {

packages/@aws-cdk-testing/framework-integ/test/aws-elasticloadbalancingv2/test/integ.alb-mtls.js.snapshot/manifest.json

+1-3
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/@aws-cdk-testing/framework-integ/test/aws-elasticloadbalancingv2/test/integ.alb-mtls.js.snapshot/tree.json

+4-3
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/@aws-cdk-testing/framework-integ/test/aws-elasticloadbalancingv2/test/integ.alb-mtls.ts

+1
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,7 @@ class MutualTls extends Stack {
121121
protocol: elbv2.ApplicationProtocol.HTTPS,
122122
certificates: [certificate],
123123
mutualAuthentication: {
124+
advertiseTrustStoreCaNames: true,
124125
ignoreClientCertificateExpiry: false,
125126
mutualAuthenticationMode: elbv2.MutualAuthenticationMode.VERIFY,
126127
trustStore,

packages/aws-cdk-lib/aws-elasticloadbalancingv2/README.md

+1
Original file line numberDiff line numberDiff line change
@@ -987,6 +987,7 @@ lb.addListener('Listener', {
987987
certificates: [certificate],
988988
// mTLS settings
989989
mutualAuthentication: {
990+
advertiseTrustStoreCaNames: true,
990991
ignoreClientCertificateExpiry: false,
991992
mutualAuthenticationMode: elbv2.MutualAuthenticationMode.VERIFY,
992993
trustStore,

packages/aws-cdk-lib/aws-elasticloadbalancingv2/lib/alb/application-listener.ts

+17
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,13 @@ export interface MutualAuthentication {
139139
* @default false
140140
*/
141141
readonly ignoreClientCertificateExpiry?: boolean;
142+
143+
/**
144+
* Indicates whether trust store CA names are advertised
145+
*
146+
* @default false
147+
*/
148+
readonly advertiseTrustStoreCaNames?: boolean;
142149
}
143150

144151
/**
@@ -258,13 +265,19 @@ export class ApplicationListener extends BaseListener implements IApplicationLis
258265

259266
validateMutualAuthentication(scope, props.mutualAuthentication);
260267

268+
let advertiseTrustStoreCaNames: string | undefined;
269+
if (props.mutualAuthentication?.advertiseTrustStoreCaNames !== undefined) {
270+
advertiseTrustStoreCaNames = props.mutualAuthentication.advertiseTrustStoreCaNames ? 'on' : 'off';
271+
}
272+
261273
super(scope, id, {
262274
loadBalancerArn: props.loadBalancer.loadBalancerArn,
263275
certificates: Lazy.any({ produce: () => this.certificateArns.map(certificateArn => ({ certificateArn })) }, { omitEmptyArray: true }),
264276
protocol,
265277
port,
266278
sslPolicy: props.sslPolicy,
267279
mutualAuthentication: props.mutualAuthentication ? {
280+
advertiseTrustStoreCaNames,
268281
ignoreClientCertificateExpiry: props.mutualAuthentication?.ignoreClientCertificateExpiry,
269282
mode: props.mutualAuthentication?.mutualAuthenticationMode,
270283
trustStoreArn: props.mutualAuthentication?.trustStore?.trustStoreArn,
@@ -1075,5 +1088,9 @@ function validateMutualAuthentication(scope: Construct, mutualAuthentication?: M
10751088
if (mutualAuthentication.ignoreClientCertificateExpiry !== undefined) {
10761089
throw new ValidationError(`You cannot set 'ignoreClientCertificateExpiry' when 'mode' is '${MutualAuthenticationMode.OFF}' or '${MutualAuthenticationMode.PASS_THROUGH}'`, scope);
10771090
}
1091+
1092+
if (mutualAuthentication.advertiseTrustStoreCaNames !== undefined) {
1093+
throw new ValidationError(`You cannot set 'advertiseTrustStoreCaNames' when 'mode' is '${MutualAuthenticationMode.OFF}' or '${MutualAuthenticationMode.PASS_THROUGH}'`, scope);
1094+
}
10781095
}
10791096
}

packages/aws-cdk-lib/aws-elasticloadbalancingv2/test/alb/listener.test.ts

+49
Original file line numberDiff line numberDiff line change
@@ -2024,6 +2024,7 @@ describe('tests', () => {
20242024
protocol: elbv2.ApplicationProtocol.HTTPS,
20252025
certificates: [importedCertificate(stack)],
20262026
mutualAuthentication: {
2027+
advertiseTrustStoreCaNames: true,
20272028
ignoreClientCertificateExpiry: true,
20282029
mutualAuthenticationMode: elbv2.MutualAuthenticationMode.VERIFY,
20292030
trustStore,
@@ -2035,13 +2036,39 @@ describe('tests', () => {
20352036
// THEN
20362037
Template.fromStack(stack).hasResourceProperties('AWS::ElasticLoadBalancingV2::Listener', {
20372038
MutualAuthentication: {
2039+
AdvertiseTrustStoreCaNames: 'on',
20382040
IgnoreClientCertificateExpiry: true,
20392041
Mode: 'verify',
20402042
TrustStoreArn: stack.resolve(trustStore.trustStoreArn),
20412043
},
20422044
});
20432045
});
20442046

2047+
test('Mutual Authentication settings when advertiseTrustStoreCaNames is false', () => {
2048+
// GIVEN
2049+
const stack = new cdk.Stack();
2050+
const vpc = new ec2.Vpc(stack, 'Stack');
2051+
const lb = new elbv2.ApplicationLoadBalancer(stack, 'LB', { vpc });
2052+
2053+
// WHEN
2054+
lb.addListener('Listener', {
2055+
protocol: elbv2.ApplicationProtocol.HTTPS,
2056+
certificates: [importedCertificate(stack)],
2057+
mutualAuthentication: {
2058+
advertiseTrustStoreCaNames: false,
2059+
},
2060+
defaultAction: elbv2.ListenerAction.fixedResponse(200,
2061+
{ contentType: 'text/plain', messageBody: 'Success mTLS' }),
2062+
});
2063+
2064+
// THEN
2065+
Template.fromStack(stack).hasResourceProperties('AWS::ElasticLoadBalancingV2::Listener', {
2066+
MutualAuthentication: {
2067+
AdvertiseTrustStoreCaNames: 'off',
2068+
},
2069+
});
2070+
});
2071+
20452072
test.each([elbv2.MutualAuthenticationMode.OFF, elbv2.MutualAuthenticationMode.PASS_THROUGH])('Mutual Authentication settings with all properties when mutualAuthenticationMode is %s', (mutualAuthenticationMode) => {
20462073
// GIVEN
20472074
const stack = new cdk.Stack();
@@ -2086,6 +2113,7 @@ describe('tests', () => {
20862113
// THEN
20872114
Template.fromStack(stack).hasResourceProperties('AWS::ElasticLoadBalancingV2::Listener', {
20882115
MutualAuthentication: {
2116+
AdvertiseTrustStoreCaNames: Match.absent(),
20892117
IgnoreClientCertificateExpiry: Match.absent(),
20902118
Mode: Match.absent(),
20912119
TrustStoreArn: Match.absent(),
@@ -2161,6 +2189,27 @@ describe('tests', () => {
21612189
});
21622190
}).toThrow('You cannot set \'ignoreClientCertificateExpiry\' when \'mode\' is \'off\' or \'passthrough\'');
21632191
});
2192+
2193+
test.each([elbv2.MutualAuthenticationMode.OFF, elbv2.MutualAuthenticationMode.PASS_THROUGH])('Throw an error when mode is %s with advertiseTrustStoreCaNames', (mutualAuthenticationMode) => {
2194+
// GIVEN
2195+
const stack = new cdk.Stack();
2196+
const vpc = new ec2.Vpc(stack, 'Stack');
2197+
const lb = new elbv2.ApplicationLoadBalancer(stack, 'LB', { vpc });
2198+
2199+
// WHEN
2200+
expect(() => {
2201+
lb.addListener('Listener', {
2202+
protocol: elbv2.ApplicationProtocol.HTTPS,
2203+
certificates: [importedCertificate(stack)],
2204+
mutualAuthentication: {
2205+
advertiseTrustStoreCaNames: true,
2206+
mutualAuthenticationMode,
2207+
},
2208+
defaultAction: elbv2.ListenerAction.fixedResponse(200,
2209+
{ contentType: 'text/plain', messageBody: 'Success mTLS' }),
2210+
});
2211+
}).toThrow('You cannot set \'advertiseTrustStoreCaNames\' when \'mode\' is \'off\' or \'passthrough\'');
2212+
});
21642213
});
21652214
});
21662215

0 commit comments

Comments
 (0)