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

fix(elasticloadbalancingv2): dualstack ALB missing default IPv6 ingress rule #8798

Merged
merged 13 commits into from
Jul 2, 2020
Merged
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import * as ec2 from '@aws-cdk/aws-ec2';
import { Construct, Duration, IResource, Lazy, Resource, Token } from '@aws-cdk/core';
import { BaseListener } from '../shared/base-listener';
import { HealthCheck } from '../shared/base-target-group';
import { ApplicationProtocol, SslPolicy } from '../shared/enums';
import { ApplicationProtocol, IpAddressType, SslPolicy } from '../shared/enums';
import { IListenerCertificate, ListenerCertificate } from '../shared/listener-certificate';
import { determineProtocolAndPort } from '../shared/util';
import { ListenerAction } from './application-listener-action';
Expand Down Expand Up @@ -186,6 +186,10 @@ export class ApplicationListener extends BaseListener implements IApplicationLis
if (props.open !== false) {
this.connections.allowDefaultPortFrom(ec2.Peer.anyIpv4(), `Allow from anyone on port ${port}`);
}

if (props.open !== false && this.loadBalancer.ipAddressType === IpAddressType.DUAL_STACK) {
this.connections.allowDefaultPortFrom(ec2.Peer.anyIpv6(), `Allow from anyone on port ${port}`);
}
BryanPan342 marked this conversation as resolved.
Show resolved Hide resolved
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ export class ApplicationLoadBalancer extends BaseLoadBalancer implements IApplic
}

public readonly connections: ec2.Connections;
public readonly ipAddressType?: IpAddressType;
private readonly securityGroup: ec2.ISecurityGroup;

constructor(scope: Construct, id: string, props: ApplicationLoadBalancerProps) {
Expand All @@ -65,6 +66,7 @@ export class ApplicationLoadBalancer extends BaseLoadBalancer implements IApplic
ipAddressType: props.ipAddressType,
});

this.ipAddressType = props.ipAddressType || IpAddressType.IPV4;
BryanPan342 marked this conversation as resolved.
Show resolved Hide resolved
this.securityGroup = props.securityGroup || new ec2.SecurityGroup(this, 'SecurityGroup', {
vpc: props.vpc,
description: `Automatically created Security Group for ELB ${this.node.uniqueId}`,
Expand Down Expand Up @@ -458,6 +460,11 @@ export interface IApplicationLoadBalancer extends ILoadBalancerV2, ec2.IConnecta
*/
readonly vpc?: ec2.IVpc;

/**
* The IP Address Type for this load balancer
*/
readonly ipAddressType?: IpAddressType;
BryanPan342 marked this conversation as resolved.
Show resolved Hide resolved

/**
* Add a new listener to this load balancer
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ export = {
test.done();
},

'Listener default to open'(test: Test) {
'Listener default to open - IPv4'(test: Test) {
// GIVEN
const stack = new cdk.Stack();
const vpc = new ec2.Vpc(stack, 'Stack');
Expand Down Expand Up @@ -76,6 +76,41 @@ export = {
test.done();
},

'Listener default to open - Dualstack'(test: Test) {
BryanPan342 marked this conversation as resolved.
Show resolved Hide resolved
// GIVEN
const stack = new cdk.Stack();
const vpc = new ec2.Vpc(stack, 'Stack');
const loadBalancer = new elbv2.ApplicationLoadBalancer(stack, 'LB', { vpc, ipAddressType: elbv2.IpAddressType.DUAL_STACK});

// WHEN
loadBalancer.addListener('MyListener', {
port: 80,
defaultTargetGroups: [new elbv2.ApplicationTargetGroup(stack, 'Group', { vpc, port: 80 })],
});

// THEN
expect(stack).to(haveResource('AWS::EC2::SecurityGroup', {
SecurityGroupIngress: [
{
Description: 'Allow from anyone on port 80',
CidrIp: '0.0.0.0/0',
FromPort: 80,
IpProtocol: 'tcp',
ToPort: 80,
},
{
Description: 'Allow from anyone on port 80',
CidrIpv6: '::/0',
FromPort: 80,
IpProtocol: 'tcp',
ToPort: 80,
},
],
}));

test.done();
},

'HTTPS listener requires certificate'(test: Test) {
// GIVEN
const stack = new cdk.Stack();
Expand Down
Loading