Skip to content

Commit 0731095

Browse files
authored
fix(elasticloadbalancingv2): open, dual-stack-without-public-ipv4 ALB allows IPv6 inbound traffic (#32203)
### Issue # Closes #32197 ### Reason for this change Default generated security group ingress rules for open, dual-stack-without-public-ipv4 ALB does not allow IPv6 traffic. Only a rule for IPv4 ingress traffic is added to the security group rules currently. ### Description of changes Default generated security group ingress rules now have an additional rule that allows IPv6 ingress from anywhere. ### Description of how you validated changes Added a unit test, and updated an existing integration test ### 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 b00de76 commit 0731095

File tree

10 files changed

+65
-12
lines changed

10 files changed

+65
-12
lines changed

packages/@aws-cdk-testing/framework-integ/test/aws-elasticloadbalancingv2/test/integ.alb.dualstack-without-public-ipv4.js.snapshot/AlbDualstackWithoutPublicIpv4DefaultTestDeployAssertFA6F90DD.assets.json

+1-1
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.dualstack-without-public-ipv4.js.snapshot/aws-cdk-elbv2-integ-dualstack-without-public-ipv4.assets.json

+3-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.dualstack-without-public-ipv4.js.snapshot/aws-cdk-elbv2-integ-dualstack-without-public-ipv4.template.json

+7
Original file line numberDiff line numberDiff line change
@@ -530,6 +530,13 @@
530530
"FromPort": 80,
531531
"IpProtocol": "tcp",
532532
"ToPort": 80
533+
},
534+
{
535+
"CidrIpv6": "::/0",
536+
"Description": "Allow from anyone on port 80",
537+
"FromPort": 80,
538+
"IpProtocol": "tcp",
539+
"ToPort": 80
533540
}
534541
],
535542
"VpcId": {

packages/@aws-cdk-testing/framework-integ/test/aws-elasticloadbalancingv2/test/integ.alb.dualstack-without-public-ipv4.js.snapshot/cdk.out

+1-1
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.dualstack-without-public-ipv4.js.snapshot/integ.json

+1-1
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.dualstack-without-public-ipv4.js.snapshot/manifest.json

+2-2
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.dualstack-without-public-ipv4.js.snapshot/tree.json

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

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

+2-1
Original file line numberDiff line numberDiff line change
@@ -298,13 +298,14 @@ const lb = new elbv2.ApplicationLoadBalancer(this, 'LB', {
298298
});
299299
```
300300

301-
By setting `DUAL_STACK_WITHOUT_PUBLIC_IPV4`, you can provision load balancers without public IPv4s
301+
By setting `DUAL_STACK_WITHOUT_PUBLIC_IPV4`, you can provision load balancers without public IPv4s:
302302

303303
```ts
304304
declare const vpc: ec2.Vpc;
305305

306306
const lb = new elbv2.ApplicationLoadBalancer(this, 'LB', {
307307
vpc,
308+
internetFacing: true,
308309
ipAddressType: elbv2.IpAddressType.DUAL_STACK_WITHOUT_PUBLIC_IPV4,
309310
});
310311
```

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

+2-1
Original file line numberDiff line numberDiff line change
@@ -303,7 +303,8 @@ export class ApplicationListener extends BaseListener implements IApplicationLis
303303

304304
if (props.open !== false) {
305305
this.connections.allowDefaultPortFrom(ec2.Peer.anyIpv4(), `Allow from anyone on port ${port}`);
306-
if (this.loadBalancer.ipAddressType === IpAddressType.DUAL_STACK) {
306+
if (this.loadBalancer.ipAddressType === IpAddressType.DUAL_STACK ||
307+
this.loadBalancer.ipAddressType === IpAddressType.DUAL_STACK_WITHOUT_PUBLIC_IPV4) {
307308
this.connections.allowDefaultPortFrom(ec2.Peer.anyIpv6(), `Allow from anyone on port ${port}`);
308309
}
309310
}

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

+37
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,43 @@ describe('tests', () => {
107107
});
108108
});
109109

110+
test('Listener default to open - IPv6 (dual stack without public IPV4)', () => {
111+
// GIVEN
112+
const stack = new cdk.Stack();
113+
const vpc = new ec2.Vpc(stack, 'Stack');
114+
const loadBalancer = new elbv2.ApplicationLoadBalancer(stack, 'LB', {
115+
vpc,
116+
internetFacing: true,
117+
ipAddressType: elbv2.IpAddressType.DUAL_STACK_WITHOUT_PUBLIC_IPV4,
118+
});
119+
120+
// WHEN
121+
loadBalancer.addListener('MyListener', {
122+
port: 80,
123+
defaultTargetGroups: [new elbv2.ApplicationTargetGroup(stack, 'Group', { vpc, port: 80 })],
124+
});
125+
126+
// THEN
127+
Template.fromStack(stack).hasResourceProperties('AWS::EC2::SecurityGroup', {
128+
SecurityGroupIngress: [
129+
{
130+
Description: 'Allow from anyone on port 80',
131+
CidrIp: '0.0.0.0/0',
132+
FromPort: 80,
133+
IpProtocol: 'tcp',
134+
ToPort: 80,
135+
},
136+
{
137+
Description: 'Allow from anyone on port 80',
138+
CidrIpv6: '::/0',
139+
FromPort: 80,
140+
IpProtocol: 'tcp',
141+
ToPort: 80,
142+
},
143+
],
144+
});
145+
});
146+
110147
test('HTTPS listener requires certificate', () => {
111148
// GIVEN
112149
const stack = new cdk.Stack();

0 commit comments

Comments
 (0)