Skip to content

Commit

Permalink
feat(elasticloadbalancingv2): support DUAL_STACK_WITHOUT_PUBLIC_IPV4 …
Browse files Browse the repository at this point in the history
…for ALB open-access security group rules
  • Loading branch information
clareliguori committed Nov 19, 2024
1 parent 49b5afd commit bcc65a8
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -303,7 +303,8 @@ export class ApplicationListener extends BaseListener implements IApplicationLis

if (props.open !== false) {
this.connections.allowDefaultPortFrom(ec2.Peer.anyIpv4(), `Allow from anyone on port ${port}`);
if (this.loadBalancer.ipAddressType === IpAddressType.DUAL_STACK) {
if (this.loadBalancer.ipAddressType === IpAddressType.DUAL_STACK ||
this.loadBalancer.ipAddressType === IpAddressType.DUAL_STACK_WITHOUT_PUBLIC_IPV4) {
this.connections.allowDefaultPortFrom(ec2.Peer.anyIpv6(), `Allow from anyone on port ${port}`);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,43 @@ describe('tests', () => {
});
});

test('Listener default to open - IPv6 (dual stack without public IPV4)', () => {
// GIVEN
const stack = new cdk.Stack();
const vpc = new ec2.Vpc(stack, 'Stack');
const loadBalancer = new elbv2.ApplicationLoadBalancer(stack, 'LB', {
vpc,
internetFacing: true,
ipAddressType: elbv2.IpAddressType.DUAL_STACK_WITHOUT_PUBLIC_IPV4,
});

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

// THEN
Template.fromStack(stack).hasResourceProperties('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('HTTPS listener requires certificate', () => {
// GIVEN
const stack = new cdk.Stack();
Expand Down

0 comments on commit bcc65a8

Please sign in to comment.