Skip to content

fix(elasticloadbalancingv2): add validation on application listeners for certificates on HTTP protocol #34233

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

Merged
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { ListenerCondition } from './conditions';
import { ITrustStore } from './trust-store';
import * as ec2 from '../../../aws-ec2';
import * as cxschema from '../../../cloud-assembly-schema';
import { Duration, FeatureFlags, Lazy, Resource, Token } from '../../../core';
import { Annotations, Duration, FeatureFlags, Lazy, Resource, Token } from '../../../core';
import { ValidationError } from '../../../core/lib/errors';
import { addConstructMetadata, MethodMetadata } from '../../../core/lib/metadata-resource';
import { propertyInjectable } from '../../../core/lib/prop-injectable';
Expand Down Expand Up @@ -293,6 +293,10 @@ export class ApplicationListener extends BaseListener implements IApplicationLis
// Enhanced CDK Analytics Telemetry
addConstructMetadata(this, props);

if (protocol === ApplicationProtocol.HTTP && props.certificates?.length) {
Annotations.of(this).addWarningV2('@aws-cdk/aws-elasticloadbalancingv2:httpListenerWithCertificates', 'Certificates cannot be specified for HTTP listeners. Use HTTPS instead.');
}

this.loadBalancer = props.loadBalancer;
this.protocol = protocol;
this.port = port;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { describeDeprecated, testDeprecated } from '@aws-cdk/cdk-build-tools';
import * as constructs from 'constructs';
import { Match, Template } from '../../../assertions';
import { Annotations, Match, Template } from '../../../assertions';
import * as acm from '../../../aws-certificatemanager';
import { Metric } from '../../../aws-cloudwatch';
import * as ec2 from '../../../aws-ec2';
Expand Down Expand Up @@ -257,6 +257,21 @@ describe('tests', () => {
});
});

test('HTTP listener cannot have a certificate', () => {
// GIVEN
const stack = new cdk.Stack();
const vpc = new ec2.Vpc(stack, 'Stack');
const lb = new elbv2.ApplicationLoadBalancer(stack, 'LB', { vpc });

const listener = lb.addListener('Listener', {
port: 80,
certificates: [elbv2.ListenerCertificate.fromArn('cert1')],
defaultTargetGroups: [new elbv2.ApplicationTargetGroup(stack, 'Group', { vpc, port: 80 })],
});

Annotations.fromStack(stack).hasWarning('/'+listener.node.path, Match.stringLikeRegexp('Certificates cannot be specified for HTTP listeners. Use HTTPS instead.'));
});

test('Can configure targetType on TargetGroups', () => {
// GIVEN
const stack = new cdk.Stack();
Expand Down
Loading