-
Notifications
You must be signed in to change notification settings - Fork 3.9k
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
(ElasticLoadBalancingV2): Security group missing when specifying Connections rules #31644
Comments
Per Connections, it allows manage the allowed network connections for constructs with Security Groups. This class makes it easy to allow network connections to and from security groups, and between security groups individually. When used by itself, one needs to specify at least one security group per example: // The code below shows an example of how to instantiate this type.
// The values are placeholders you should change.
import { aws_ec2 as ec2 } from 'aws-cdk-lib';
declare const peer: ec2.IPeer;
declare const port: ec2.Port;
declare const securityGroup: ec2.SecurityGroup;
const connections = new ec2.Connections(/* all optional props */ {
defaultPort: port,
peer: peer,
securityGroups: [securityGroup],
}); When used as convenience as property Essentially, you could create a NLB without defining security groups using code below: const vpc = ec2.Vpc.fromLookup(this, 'DefaultVpc', { isDefault: true });
new elbv2.NetworkLoadBalancer(this, 'TestNLB', {
vpc
}); So to use EC2 Connections, you need to specify at least one security group to act on via Connections convenience class. I'm unsure if this issue is a regression, since per commit history, Thanks, |
If true, that only appears to be true for NLB? For example, this code to create an instance DOES create a security group automatically: instance.Connections.AllowFromAnyIpv4(Port.HTTPS); I've also tested similar Client VPN Endpoints, ECS Services, even an ALB instead of NLB. All created a security group without a SecurityGroup being constructed in our CDK code. |
The reason an
while in NLB if you leave aws-cdk/packages/aws-cdk-lib/aws-elasticloadbalancingv2/lib/nlb/network-load-balancer.ts Line 260 in 3c92012
|
@pahud Thanks for the follow up explanation. |
Yes, thanks for tracking that @pahud . I'll try explicitly adding an (empty?) security group in the meantime, but hopefully finding that should help resolve the bug faster. |
Comments on closed issues and PRs are hard for our team to see. |
1 similar comment
Comments on closed issues and PRs are hard for our team to see. |
Describe the bug
A network load balancer with its connectivity specified using Connections does not get a security group specified in the synthesized yml.
Regression Issue
Last Known Working CDK Version
Unknown - I assume it worked on some point since the behavior was explicitly added in #28494.
Expected Behavior
Expected a security group to be defined and applied to the NLB allowing the specified traffic.
Current Behavior
The load balancer gets created, but without a security group.
Reproduction Steps
Possible Solution
No response
Additional Information/Context
As per the sample code, two ways to create a load balancer. If a SecurityGroup is explicitly specified, the resulting network load balanacer has a security group created for it and it is fine.
If instead the Connections property is used to define the allowed connectivity, this appears to be completely omitted from the resulting YML.
In our case, we initially had a stack defined using explicit security groups, but are attempting to convert to using the Connections property as that appears to be the recommended best practice. Attempting to deploy our stack with these changes fails on the NLB resource with the error:
Resource handler returned message: "1 validation error detected: Value null at 'securityGroups' failed to satisfy constraint: Member must not be null (Service: ElasticLoadBalancingV2, Status Code: 400, Request ID: 4582c208-2aa9-44e3-b606-21a00ef2f0a4)" (RequestToken: 67f14885-5b87-0c95-7e53-5687c9b9cf5c, HandlerErrorCode: InvalidRequest)
We then tracked down that this was occurring because Connections did not create a security group, which meant this deploy was attempting to remove the only existing SG for the NLB, which is apparently not allowed.
CDK CLI Version
2.160.0 (build 7a8ae02)
Framework Version
No response
Node.js Version
20.17.0
OS
Windows 11
Language
.NET
Language Version
.NET 6.0
Other information
YML for the sample code when using Connections:
The text was updated successfully, but these errors were encountered: