-
Notifications
You must be signed in to change notification settings - Fork 4k
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
feat(ec2): imported SecurityGroups don't create egress rules #3386
feat(ec2): imported SecurityGroups don't create egress rules #3386
Conversation
attempt to fix #3355 |
Not 100% opposed, but is adding ingress and egress rules to the securitygroup directly not good enough? |
you can manipulate the security group but for example, you cannot remove it and instead of creating a new security group and adding it or accessing the security group in the array, it would be easier/nicer to either offer this way or have a defaultSecurityGroup obj in connections. having ingress/egress output might affect existing security groups because they might have default all outbound active and adding the egress rule that was generated removes the default all outbound rule (happened to me in production and it wasn't ok, especially when someone might not know that adding any egress rule removes the default all outbound one). ex: const asg = new AutoScalingGroup(this, `AutoScalingGroup`, {...props})
// 1st option: connection one-way
asg.connections.allowFrom(Peer.anyIpv4(), Port.allTraffic(), "bla bla", true)
// 2nd option: default security group
asg.connections.defaultSecurityGroup.addIngressRule(Peer.anyIpv4(), Port.allTraffic(), "bla bla")
// current way:
asg.connections.securityGroups[0].addIngressRule(Peer.anyIpv4(), Port.allTraffic(), "bla bla", true) |
Wait, this shouldn't be happening. There is an "allowAllOutbound" property on a security group that makes it so that adding egress rules becomes a no-op (or at least it should be). Can you confirm that that behavior is broken? |
The issue appears when there is an existing Security group outside aws-cdk and you import it. ex: const existingSg = SecurityGroup.fromSecurityGroupId(this, "demoSG", "sg-1234567");
const asg = new AutoScalingGroup(this, `AutoScalingGroup`, {...props})
asg.connections.allowFrom(existingSg, Port.tcp(22), "ssh from demo instances") this will create ingress/egress rule and the issue is that if "demoSG" has all traffic/all ports to 0.0.0.0/0 (being default security group egress rule), Cloudformation removes it and adds the new egress rule only, which is an issue in an existing infrastructure |
Yep, I got you. I think the proper solution will be to allow specifying that attribute when importing the SG then. |
How would that work? |
I think interface SecurityGroupImportOptions {
/**
* Whether the security group has been created to allow all outbound traffic.
*
* Unless set to `false`, no new outbound rules will be added to the security group.
*
* @default true
* @experimental
*/
allowAllOutbound?: boolean;
}
class SecurityGroup {
public static fromSecurityGroupId(scope: Construct, id: string, securityGroupId: string, options: SecurityGroupImportOptions = {}): ISecurityGroup {
// ...
}
} Marking the property |
@ayazhussein will this satisfy your use case as well? |
Pull Request Checklist
|
Codebuild (Continuous Integration) build failed for current commits. Please check log and resolve before PR is merged. |
1 similar comment
Codebuild (Continuous Integration) build failed for current commits. Please check log and resolve before PR is merged. |
@rix0rrr Hi, I couldn't test because of the build failing
|
Codebuild (Continuous Integration) build failed for current commits. Please check log and resolve before PR is merged. |
yes, it is working great, no more |
Codebuild (Continuous Integration) build failed for current commits. Please check log and resolve before PR is merged. |
Codebuild (Continuous Integration) build failed for current commits. Please check log and resolve before PR is merged. |
Hey @rix0rrr FYI this change is "infrastructure" breaking because it deletes existing |
Also this doesn't cover the case of imported clusters/instances in aws-cdk/packages/@aws-cdk/aws-rds/lib/instance.ts Lines 91 to 103 in 3a0cde0
|
Security Groups are created with
allowAllOutbound: true
by default, and so imported security groups default to that as well. This means that no egress rules will be created for them, because that will undo the default of allowAllOutbound.This can be configured by setting
allowAllOutbound: false
upon importing.