Skip to content

Commit

Permalink
feat(elasticloadbalancingv2): default ALB open-access security group …
Browse files Browse the repository at this point in the history
…rules support DUAL_STACK_WITHOUT_PUBLIC_IPV4
  • Loading branch information
clareliguori committed Nov 19, 2024
1 parent 49b5afd commit bb3258b
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 2 deletions.
3 changes: 2 additions & 1 deletion packages/aws-cdk-lib/aws-elasticloadbalancingv2/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -298,13 +298,14 @@ const lb = new elbv2.ApplicationLoadBalancer(this, 'LB', {
});
```

By setting `DUAL_STACK_WITHOUT_PUBLIC_IPV4`, you can provision load balancers without public IPv4s
By setting `DUAL_STACK_WITHOUT_PUBLIC_IPV4`, you can provision load balancers without public IPv4s:

```ts
declare const vpc: ec2.Vpc;

const lb = new elbv2.ApplicationLoadBalancer(this, 'LB', {
vpc,
internetFacing: true,
ipAddressType: elbv2.IpAddressType.DUAL_STACK_WITHOUT_PUBLIC_IPV4,
});
```
Expand Down
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 bb3258b

Please sign in to comment.