Skip to content
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

outbound networks methods dont' work with imported security groups #4361

Closed
gidimariastorm opened this issue Oct 3, 2019 · 2 comments
Closed
Assignees
Labels
@aws-cdk/aws-ec2 Related to Amazon Elastic Compute Cloud guidance Question that needs advice or information. language/python Related to Python bindings

Comments

@gidimariastorm
Copy link

gidimariastorm commented Oct 3, 2019

I'm trying to upload the rules in outbound for two existing secgroup:

as_sg = ec2.SecurityGroup.from_security_group_id(self,'ASSG',security_group_id='sg-eacf0093')
fe_sg = ec2.SecurityGroup.from_security_group_id(self, 'FESG', security_group_id='sg-f4cf008d')

now the inbound method works correctly such as:
allow_from_any_ipv4 or allow_from

as_sg = ec2.SecurityGroup.from_security_group_id(self,'ASSG',security_group_id='sg-eacf0093')
fe_sg = ec2.SecurityGroup.from_security_group_id(self, 'FESG', security_group_id='sg-f4cf008d')
fe_sg.connections.allow_from_any_ipv4(ec2.Port.tcp(443))
> > Stack ad-ro-mi-prod-alb-autoscaling
> Security Group Changes
> ┌───┬─────────────┬─────┬──────────┬─────────────────┐
> │   │ Group       │ Dir │ Protocol │ Peer            │
> ├───┼─────────────┼─────┼──────────┼─────────────────┤
> │ + │ sg-f4cf008d │ In  │ TCP 443  │ Everyone (IPv4) │
> └───┴─────────────┴─────┴──────────┴─────────────────┘
> (NOTE: There may be security-related changes not in this list. See https://github.com/aws/aws-cdk/issues/1299)
> 
> Resources
> [+] AWS::EC2::SecurityGroupIngress FESG/from 0.0.0.0_0:443 FESGfrom0000044359AEBFA7 

or also this it works:

fe_sg.connections.allow_from(as_sg.connections, ec2.Port.tcp(444))
> 
> > Security Group Changes
> ┌───┬─────────────┬─────┬──────────┬─────────────┐
> │   │ Group       │ Dir │ Protocol │ Peer        │
> ├───┼─────────────┼─────┼──────────┼─────────────┤
> │ + │ sg-f4cf008d │ In  │ TCP 444  │ sg-eacf0093 │
> └───┴─────────────┴─────┴──────────┴─────────────┘
> (NOTE: There may be security-related changes not in this list. See https://github.com/aws/aws-cdk/issues/1299)
> 
> Resources
> [+] AWS::EC2::SecurityGroupIngress FESG/from adromiprodalbautoscalingASSG2B6F69BD:444
> 

even the add_ingress_rule works

However If I use the outbound methods it doesn't work.

fe_sg.connections.allow_to(as_sg.connections, ec2.Port.tcp(444))

> Security Group Changes
> ┌───┬─────────────┬─────┬──────────┬─────────────┐
> │   │ Group       │ Dir │ Protocol │ Peer        │
> ├───┼─────────────┼─────┼──────────┼─────────────┤
> │ + │ sg-eacf0093 │ In  │ TCP 444  │ sg-f4cf008d │
> └───┴─────────────┴─────┴──────────┴─────────────┘
> (NOTE: There may be security-related changes not in this list. See https://github.com/aws/aws-cdk/issues/1299)
> 

it updates only the Ingress rules. this behavior is not present with security groups created with the CDK.

I'm also used the add_egress_rule without success

ingress example:

fe_sg.add_ingress_rule(ec2.Peer().prefix_list('sg-eacf0093'), ec2.Port.tcp(443),remote_rule=True)
> Security Group Changes
> ┌───┬─────────────┬─────┬──────────┬─────────────┐
> │   │ Group       │ Dir │ Protocol │ Peer        │
> ├───┼─────────────┼─────┼──────────┼─────────────┤
> │ + │ sg-f4cf008d │ In  │ TCP 443  │ sg-eacf0093 │
> └───┴─────────────┴─────┴──────────┴─────────────┘
> (NOTE: There may be security-related changes not in this list. See https://github.com/aws/aws-cdk/issues/1299)
> 
> Resources
> [+] AWS::EC2::SecurityGroupIngress FESG/from sg-eacf0093:443 FESGfromsgeacf00934433CF0B05C 

egress:

fe_sg.add_egress_rule(ec2.Peer().prefix_list('sg-eacf0093'), ec2.Port.tcp(443),remote_rule=True)
> Stack name-stack
> There were no differences

the issue is also present if I try to update the outbound rules of an existing secgroup for a sec group created in the CDK.

Reproduction Steps

import an existing security group.
try to update its egress rules

Error Log

Environment

  • CLI Version : cdk 1.10.1
  • Framework Version:
  • OS : macOS
  • Language : python 3.7

Other


This is 🐛 Bug Report

@gidimariastorm gidimariastorm added bug This issue is a bug. needs-triage This issue or PR still needs to be triaged. labels Oct 3, 2019
@gidimariastorm gidimariastorm changed the title outbound networks methods dont' work with imported securygroup Imported outbound networks methods dont' work with imported security groups Oct 3, 2019
@NGL321 NGL321 added language/python Related to Python bindings @aws-cdk/aws-ec2 Related to Amazon Elastic Compute Cloud needs-reproduction This issue needs reproduction. and removed needs-triage This issue or PR still needs to be triaged. labels Oct 3, 2019
@rix0rrr rix0rrr removed the needs-reproduction This issue needs reproduction. label Oct 4, 2019
@rix0rrr
Copy link
Contributor

rix0rrr commented Oct 4, 2019

True. It assumes that imported security groups will have been created with allowAllOutbound, since that is the default.

If that is not the case, you will have to mention this explicitly upon importing:

as_sg = ec2.SecurityGroup.from_security_group_id(self,'ASSG',security_group_id='sg-eacf0093', allow_all_outbound=False)

See https://docs.aws.amazon.com/cdk/api/latest/python/aws_cdk.aws_ec2/SecurityGroup.html#aws_cdk.aws_ec2.SecurityGroup.from_security_group_id

@rix0rrr rix0rrr closed this as completed Oct 4, 2019
@rix0rrr rix0rrr added guidance Question that needs advice or information. and removed bug This issue is a bug. labels Oct 4, 2019
@gidimariastorm
Copy link
Author

thanks :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
@aws-cdk/aws-ec2 Related to Amazon Elastic Compute Cloud guidance Question that needs advice or information. language/python Related to Python bindings
Projects
None yet
Development

No branches or pull requests

3 participants