Skip to content

Commit 42d424e

Browse files
authored
fix(elbv2): unable to deploy template with IPv4 load balancer when denyAllIgwTraffic set (#29956)
### Issue # (if applicable) Closes #30247 . ### Reason for this change Integ test for NLB attributes ([integ.nlb-attributes.ts](https://github.com/aws/aws-cdk/blob/4f1c94b27ef7f4ceccea0ff39625c0e8add31c9f/packages/%40aws-cdk-testing/framework-integ/test/aws-elasticloadbalancingv2/test/integ.nlb-attributes.ts)) fails to deploy due to an error. The error occurs when `denyAllIgwTraffic` is explicitly set for load balancers with Ipv4 addressing, the `ipv6.deny_all_igw_traffic` attribute is set. ### Description of changes - Remove the denyAllIgwTraffic setting from integ.nlb-attribute.ts - Instead, set denyAllIgwTraffic in integ.nlb.dualstack.internal.ts. - Raise an error during synthesis if `denyAllIgwTraffic` is set on a load balancer that does not use dual stack addressing. ### Description of how you validated changes - Added new unit tests for different combinations of `denyAllIgwTraffic` and `ipAddressType` - Updated 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 1ba6e87 commit 42d424e

20 files changed

+134
-34
lines changed
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Original file line numberDiff line numberDiff line change
@@ -403,10 +403,6 @@
403403
"Key": "load_balancing.cross_zone.enabled",
404404
"Value": "true"
405405
},
406-
{
407-
"Key": "ipv6.deny_all_igw_traffic",
408-
"Value": "true"
409-
},
410406
{
411407
"Key": "dns_record.client_routing_policy",
412408
"Value": "partial_availability_zone_affinity"
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ new elbv2.NetworkLoadBalancer(stack, 'NLB', {
1515
vpc,
1616
crossZoneEnabled: true,
1717
deletionProtection: false,
18-
denyAllIgwTraffic: true,
1918
clientRoutingPolicy: elbv2.ClientRoutingPolicy.PARTIAL_AVAILABILITY_ZONE_AFFINITY,
2019
});
2120

packages/@aws-cdk-testing/framework-integ/test/aws-elasticloadbalancingv2/test/integ.nlb.dualstack.internal.js.snapshot/NlbDualstackInternalIntegDefaultTestDeployAssertEEBE69CB.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.nlb.dualstack.internal.js.snapshot/aws-cdk-nlb-dualstack-internal.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.nlb.dualstack.internal.js.snapshot/aws-cdk-nlb-dualstack-internal.template.json

+4
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,10 @@
210210
{
211211
"Key": "deletion_protection.enabled",
212212
"Value": "false"
213+
},
214+
{
215+
"Key": "ipv6.deny_all_igw_traffic",
216+
"Value": "true"
213217
}
214218
],
215219
"Scheme": "internal",

packages/@aws-cdk-testing/framework-integ/test/aws-elasticloadbalancingv2/test/integ.nlb.dualstack.internal.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.nlb.dualstack.internal.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.nlb.dualstack.internal.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.nlb.dualstack.internal.js.snapshot/tree.json

+6-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.nlb.dualstack.internal.ts

+1
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ const subnetIpv6CidrBlocks = cdk.Fn.cidr(vpcIpv6CidrBlock, 256, '64');
3131

3232
const lb = new elbv2.NetworkLoadBalancer(stack, 'LB', {
3333
vpc,
34+
denyAllIgwTraffic: true,
3435
ipAddressType: elbv2.IpAddressType.DUAL_STACK,
3536
});
3637

packages/aws-cdk-lib/aws-elasticloadbalancingv2/lib/shared/base-load-balancer.ts

+6-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { Construct } from 'constructs';
2+
import { IpAddressType } from './enums';
23
import { Attributes, ifUndefined, mapTagMapToCxschema, renderAttributes } from './util';
34
import * as ec2 from '../../../aws-ec2';
45
import * as iam from '../../../aws-iam';
@@ -251,7 +252,11 @@ export abstract class BaseLoadBalancer extends Resource {
251252
}
252253

253254
if (baseProps.denyAllIgwTraffic !== undefined) {
254-
this.setAttribute('ipv6.deny_all_igw_traffic', baseProps.denyAllIgwTraffic.toString());
255+
if (additionalProps.ipAddressType === IpAddressType.DUAL_STACK) {
256+
this.setAttribute('ipv6.deny_all_igw_traffic', baseProps.denyAllIgwTraffic.toString());
257+
} else {
258+
throw new Error(`'denyAllIgwTraffic' may only be set on load balancers with ${IpAddressType.DUAL_STACK} addressing.`);
259+
}
255260
}
256261

257262
this.loadBalancerCanonicalHostedZoneId = resource.attrCanonicalHostedZoneId;

packages/aws-cdk-lib/aws-elasticloadbalancingv2/test/alb/load-balancer.test.ts

+62-5
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,6 @@ describe('tests', () => {
8484
idleTimeout: cdk.Duration.seconds(1000),
8585
dropInvalidHeaderFields: true,
8686
clientKeepAlive: cdk.Duration.seconds(200),
87-
denyAllIgwTraffic: true,
8887
preserveHostHeader: true,
8988
xAmznTlsVersionAndCipherSuiteHeaders: true,
9089
preserveXffClientPort: true,
@@ -99,10 +98,6 @@ describe('tests', () => {
9998
Key: 'deletion_protection.enabled',
10099
Value: 'true',
101100
},
102-
{
103-
Key: 'ipv6.deny_all_igw_traffic',
104-
Value: 'true',
105-
},
106101
{
107102
Key: 'routing.http2.enabled',
108103
Value: 'false',
@@ -171,6 +166,26 @@ describe('tests', () => {
171166
}).toThrow('\'clientKeepAlive\' must be between 60 and 604800 seconds. Got: 100 milliseconds');
172167
});
173168

169+
test.each([
170+
[false, undefined],
171+
[true, undefined],
172+
[false, elbv2.IpAddressType.IPV4],
173+
[true, elbv2.IpAddressType.IPV4],
174+
])('throw error for denyAllIgwTraffic set to %s for Ipv4 (default) addressing.', (denyAllIgwTraffic, ipAddressType) => {
175+
// GIVEN
176+
const stack = new cdk.Stack();
177+
const vpc = new ec2.Vpc(stack, 'Stack');
178+
179+
// THEN
180+
expect(() => {
181+
new elbv2.ApplicationLoadBalancer(stack, 'LB', {
182+
vpc,
183+
denyAllIgwTraffic: denyAllIgwTraffic,
184+
ipAddressType: ipAddressType,
185+
});
186+
}).toThrow(`'denyAllIgwTraffic' may only be set on load balancers with ${elbv2.IpAddressType.DUAL_STACK} addressing.`);
187+
});
188+
174189
describe('Desync mitigation mode', () => {
175190
test('Defensive', () => {
176191
// GIVEN
@@ -971,6 +986,27 @@ describe('tests', () => {
971986
});
972987
});
973988

989+
test('Can create internet-facing dualstack ApplicationLoadBalancer with denyAllIgwTraffic set to false', () => {
990+
// GIVEN
991+
const stack = new cdk.Stack();
992+
const vpc = new ec2.Vpc(stack, 'Stack');
993+
994+
// WHEN
995+
new elbv2.ApplicationLoadBalancer(stack, 'LB', {
996+
vpc,
997+
denyAllIgwTraffic: false,
998+
internetFacing: true,
999+
ipAddressType: elbv2.IpAddressType.DUAL_STACK,
1000+
});
1001+
1002+
// THEN
1003+
Template.fromStack(stack).hasResourceProperties('AWS::ElasticLoadBalancingV2::LoadBalancer', {
1004+
Scheme: 'internet-facing',
1005+
Type: 'application',
1006+
IpAddressType: 'dualstack',
1007+
});
1008+
});
1009+
9741010
test('Can create internal dualstack ApplicationLoadBalancer', () => {
9751011
// GIVEN
9761012
const stack = new cdk.Stack();
@@ -989,5 +1025,26 @@ describe('tests', () => {
9891025
IpAddressType: 'dualstack',
9901026
});
9911027
});
1028+
1029+
test.each([undefined, false])('Can create internal dualstack ApplicationLoadBalancer with denyAllIgwTraffic set to true', (internetFacing) => {
1030+
// GIVEN
1031+
const stack = new cdk.Stack();
1032+
const vpc = new ec2.Vpc(stack, 'Stack');
1033+
1034+
// WHEN
1035+
new elbv2.ApplicationLoadBalancer(stack, 'LB', {
1036+
vpc,
1037+
denyAllIgwTraffic: true,
1038+
internetFacing: internetFacing,
1039+
ipAddressType: elbv2.IpAddressType.DUAL_STACK,
1040+
});
1041+
1042+
// THEN
1043+
Template.fromStack(stack).hasResourceProperties('AWS::ElasticLoadBalancingV2::LoadBalancer', {
1044+
Scheme: 'internal',
1045+
Type: 'application',
1046+
IpAddressType: 'dualstack',
1047+
});
1048+
});
9921049
});
9931050
});

packages/aws-cdk-lib/aws-elasticloadbalancingv2/test/nlb/load-balancer.test.ts

+44-6
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,6 @@ describe('tests', () => {
8080
new elbv2.NetworkLoadBalancer(stack, 'LB', {
8181
vpc,
8282
crossZoneEnabled: true,
83-
denyAllIgwTraffic: true,
8483
clientRoutingPolicy: elbv2.ClientRoutingPolicy.PARTIAL_AVAILABILITY_ZONE_AFFINITY,
8584
});
8685

@@ -91,10 +90,6 @@ describe('tests', () => {
9190
Key: 'load_balancing.cross_zone.enabled',
9291
Value: 'true',
9392
},
94-
{
95-
Key: 'ipv6.deny_all_igw_traffic',
96-
Value: 'true',
97-
},
9893
{
9994
Key: 'dns_record.client_routing_policy',
10095
Value: 'partial_availability_zone_affinity',
@@ -488,6 +483,26 @@ describe('tests', () => {
488483
}).toThrow('Load balancer name: "my load balancer" must contain only alphanumeric characters or hyphens.');
489484
});
490485

486+
test.each([
487+
[false, undefined],
488+
[true, undefined],
489+
[false, elbv2.IpAddressType.IPV4],
490+
[true, elbv2.IpAddressType.IPV4],
491+
])('throw error for denyAllIgwTraffic set to %s for Ipv4 (default) addressing.', (denyAllIgwTraffic, ipAddressType) => {
492+
// GIVEN
493+
const stack = new cdk.Stack();
494+
const vpc = new ec2.Vpc(stack, 'Stack');
495+
496+
// THEN
497+
expect(() => {
498+
new elbv2.NetworkLoadBalancer(stack, 'NLB', {
499+
vpc,
500+
denyAllIgwTraffic: denyAllIgwTraffic,
501+
ipAddressType: ipAddressType,
502+
});
503+
}).toThrow(`'denyAllIgwTraffic' may only be set on load balancers with ${elbv2.IpAddressType.DUAL_STACK} addressing.`);
504+
});
505+
491506
test('imported network load balancer with no vpc specified throws error when calling addTargets', () => {
492507
// GIVEN
493508
const stack = new cdk.Stack();
@@ -1074,14 +1089,37 @@ describe('tests', () => {
10741089
});
10751090
});
10761091

1077-
test('Can create internal dualstack NetworkLoadBalancer', () => {
1092+
test('Can create internet-facing dualstack NetworkLoadBalancer with denyAllIgwTraffic set to false', () => {
1093+
// GIVEN
1094+
const stack = new cdk.Stack();
1095+
const vpc = new ec2.Vpc(stack, 'Stack');
1096+
1097+
// WHEN
1098+
new elbv2.NetworkLoadBalancer(stack, 'LB', {
1099+
vpc,
1100+
denyAllIgwTraffic: false,
1101+
internetFacing: true,
1102+
ipAddressType: elbv2.IpAddressType.DUAL_STACK,
1103+
});
1104+
1105+
// THEN
1106+
Template.fromStack(stack).hasResourceProperties('AWS::ElasticLoadBalancingV2::LoadBalancer', {
1107+
Scheme: 'internet-facing',
1108+
Type: 'network',
1109+
IpAddressType: 'dualstack',
1110+
});
1111+
});
1112+
1113+
test.each([undefined, false])('Can create internal dualstack NetworkLoadBalancer with denyAllIgwTraffic set to true', (internetFacing) => {
10781114
// GIVEN
10791115
const stack = new cdk.Stack();
10801116
const vpc = new ec2.Vpc(stack, 'Stack');
10811117

10821118
// WHEN
10831119
new elbv2.NetworkLoadBalancer(stack, 'LB', {
10841120
vpc,
1121+
denyAllIgwTraffic: true,
1122+
internetFacing: internetFacing,
10851123
ipAddressType: elbv2.IpAddressType.DUAL_STACK,
10861124
});
10871125

0 commit comments

Comments
 (0)