Skip to content
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

feat(elasticloadbalancingv2): support AdvertiseTrustStoreCaNames for mTLS #32678

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@
"S3Bucket": {
"Fn::Sub": "cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}"
},
"S3Key": "3322b7049fb0ed2b7cbb644a2ada8d1116ff80c32dca89e6ada846b5de26f961.zip"
"S3Key": "f24ba5e516d9d80b64bc7b0f406eedd12c36b20e7461f3e7719b7ffbdad72410.zip"
},
"Description": "/opt/awscli/aws"
}
Expand All @@ -181,7 +181,7 @@
}
],
"SourceObjectKeys": [
"9249e6ca38e4bef8f254ff6bd15067180e1d3efae918968740de5a3d24d6417d.zip"
"45e09a26a1a9e47354cc26b2d2d775f9331c818cc47f9876dfda9d800e5cb6e4.zip"
],
"DestinationBucketName": {
"Ref": "Bucket83908E77"
Expand Down Expand Up @@ -975,7 +975,7 @@
"S3Bucket": {
"Fn::Sub": "cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}"
},
"S3Key": "bde7b5c89cb43285f884c94f0b9e17cdb0f5eb5345005114dd60342e0b8a85a1.zip"
"S3Key": "a1acfc2b5f4f6b183fd2bb9863f486bc5edef6a357b355a070d9a0e502df418c.zip"
},
"Timeout": 900,
"MemorySize": 128,
Expand Down Expand Up @@ -1111,6 +1111,7 @@
"Ref": "LB8A12904C"
},
"MutualAuthentication": {
"AdvertiseTrustStoreCaNames": "on",
"IgnoreClientCertificateExpiry": false,
"Mode": "verify",
"TrustStoreArn": {
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ class MutualTls extends Stack {
protocol: elbv2.ApplicationProtocol.HTTPS,
certificates: [certificate],
mutualAuthentication: {
advertiseTrustStoreCaNames: true,
ignoreClientCertificateExpiry: false,
mutualAuthenticationMode: elbv2.MutualAuthenticationMode.VERIFY,
trustStore,
Expand Down
1 change: 1 addition & 0 deletions packages/aws-cdk-lib/aws-elasticloadbalancingv2/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -980,6 +980,7 @@ lb.addListener('Listener', {
certificates: [certificate],
// mTLS settings
mutualAuthentication: {
advertiseTrustStoreCaNames: true,
ignoreClientCertificateExpiry: false,
mutualAuthenticationMode: elbv2.MutualAuthenticationMode.VERIFY,
trustStore,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,13 @@ export interface MutualAuthentication {
* @default false
*/
readonly ignoreClientCertificateExpiry?: boolean;

/**
* Indicates whether trust store CA names are advertised
*
* @default false
*/
readonly advertiseTrustStoreCaNames?: boolean;
}

/**
Expand Down Expand Up @@ -256,13 +263,19 @@ export class ApplicationListener extends BaseListener implements IApplicationLis

validateMutualAuthentication(props.mutualAuthentication);

let advertiseTrustStoreCaNames: string | undefined;
if (props.mutualAuthentication?.advertiseTrustStoreCaNames !== undefined) {
advertiseTrustStoreCaNames = props.mutualAuthentication.advertiseTrustStoreCaNames ? 'on' : 'off';
}

super(scope, id, {
loadBalancerArn: props.loadBalancer.loadBalancerArn,
certificates: Lazy.any({ produce: () => this.certificateArns.map(certificateArn => ({ certificateArn })) }, { omitEmptyArray: true }),
protocol,
port,
sslPolicy: props.sslPolicy,
mutualAuthentication: props.mutualAuthentication ? {
advertiseTrustStoreCaNames,
ignoreClientCertificateExpiry: props.mutualAuthentication?.ignoreClientCertificateExpiry,
mode: props.mutualAuthentication?.mutualAuthenticationMode,
trustStoreArn: props.mutualAuthentication?.trustStore?.trustStoreArn,
Expand Down Expand Up @@ -1065,5 +1078,9 @@ function validateMutualAuthentication(mutualAuthentication?: MutualAuthenticatio
if (mutualAuthentication.ignoreClientCertificateExpiry !== undefined) {
throw new Error(`You cannot set 'ignoreClientCertificateExpiry' when 'mode' is '${MutualAuthenticationMode.OFF}' or '${MutualAuthenticationMode.PASS_THROUGH}'`);
}

if (mutualAuthentication.advertiseTrustStoreCaNames !== undefined) {
throw new Error(`You cannot set 'advertiseTrustStoreCaNames' when 'mode' is '${MutualAuthenticationMode.OFF}' or '${MutualAuthenticationMode.PASS_THROUGH}'`);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -1953,6 +1953,7 @@ describe('tests', () => {
protocol: elbv2.ApplicationProtocol.HTTPS,
certificates: [importedCertificate(stack)],
mutualAuthentication: {
advertiseTrustStoreCaNames: true,
ignoreClientCertificateExpiry: true,
mutualAuthenticationMode: elbv2.MutualAuthenticationMode.VERIFY,
trustStore,
Expand All @@ -1964,13 +1965,39 @@ describe('tests', () => {
// THEN
Template.fromStack(stack).hasResourceProperties('AWS::ElasticLoadBalancingV2::Listener', {
MutualAuthentication: {
AdvertiseTrustStoreCaNames: 'on',
IgnoreClientCertificateExpiry: true,
Mode: 'verify',
TrustStoreArn: stack.resolve(trustStore.trustStoreArn),
},
});
});

test('Mutual Authentication settings when advertiseTrustStoreCaNames is false', () => {
// GIVEN
const stack = new cdk.Stack();
const vpc = new ec2.Vpc(stack, 'Stack');
const lb = new elbv2.ApplicationLoadBalancer(stack, 'LB', { vpc });

// WHEN
lb.addListener('Listener', {
protocol: elbv2.ApplicationProtocol.HTTPS,
certificates: [importedCertificate(stack)],
mutualAuthentication: {
advertiseTrustStoreCaNames: false,
},
defaultAction: elbv2.ListenerAction.fixedResponse(200,
{ contentType: 'text/plain', messageBody: 'Success mTLS' }),
});

// THEN
Template.fromStack(stack).hasResourceProperties('AWS::ElasticLoadBalancingV2::Listener', {
MutualAuthentication: {
AdvertiseTrustStoreCaNames: 'off',
},
});
});

test.each([elbv2.MutualAuthenticationMode.OFF, elbv2.MutualAuthenticationMode.PASS_THROUGH])('Mutual Authentication settings with all properties when mutualAuthenticationMode is %s', (mutualAuthenticationMode) => {
// GIVEN
const stack = new cdk.Stack();
Expand Down Expand Up @@ -2015,6 +2042,7 @@ describe('tests', () => {
// THEN
Template.fromStack(stack).hasResourceProperties('AWS::ElasticLoadBalancingV2::Listener', {
MutualAuthentication: {
AdvertiseTrustStoreCaNames: Match.absent(),
IgnoreClientCertificateExpiry: Match.absent(),
Mode: Match.absent(),
TrustStoreArn: Match.absent(),
Expand Down Expand Up @@ -2092,6 +2120,26 @@ describe('tests', () => {
});
});

test.each([elbv2.MutualAuthenticationMode.OFF, elbv2.MutualAuthenticationMode.PASS_THROUGH])('Throw an error when mode is %s with advertiseTrustStoreCaNames', (mutualAuthenticationMode) => {
// GIVEN
const stack = new cdk.Stack();
const vpc = new ec2.Vpc(stack, 'Stack');
const lb = new elbv2.ApplicationLoadBalancer(stack, 'LB', { vpc });

// WHEN
expect(() => {
lb.addListener('Listener', {
protocol: elbv2.ApplicationProtocol.HTTPS,
certificates: [importedCertificate(stack)],
mutualAuthentication: {
advertiseTrustStoreCaNames: true,
mutualAuthenticationMode,
},
defaultAction: elbv2.ListenerAction.fixedResponse(200,
{ contentType: 'text/plain', messageBody: 'Success mTLS' }),
});
}).toThrow('You cannot set \'advertiseTrustStoreCaNames\' when \'mode\' is \'off\' or \'passthrough\'');
});
});

class ResourceWithLBDependency extends cdk.CfnResource {
Expand Down
Loading