aws / aws/aws-cdk

aws-ec2: `Connections.allowFrom` overwrites the corresponding security group's `allowTo` instead of expanding

Open
#24,806 7 comments 2 reactions 0 assignees View on GitHub
@aws-cdk/aws-ec2 bug effort/medium p2
Dominant language
TypeScript
Stars
12.9k
Forks
4.6k
Avg merge
1d 19h
Merged PRs (30d)
71

Description

### Describe the bug

When establishing connectivity between security groups using an `.connections.allowFrom()` the notes in the CDK docs say `When establishing connectivity between security groups, it will automatically add rules in both security groups`. Instead it _overwrites_ the `allowTo` on the corresponding security group.

### Expected Behavior

I expected that `.connections.allowFrom()` on security group `b` would _add_ an `allowTo` statement on security group `a`

### Current Behavior

The `allowTo` statement on security group `a` that allow outbound traffic to all destinations was deleted and replaced with an `allowTo` statement that _only_ allowed outbound traffic to security group `b`.

### Reproduction Steps

```
const securityGroupA = ec2.SecurityGroup.fromLookupByName(this, 'sg-a', `security-group-a`, securityGroupB.connections.allowFrom(securityGroupA, ec2.Port.allTraffic())
```

### Possible Solution

`allowFrom` on security group `b` should _add_ to the policy on security group `a` instead of overwriting it. Perhaps there needs to be an additional method or a flag in the existing method allowing the engineer to specify the desired behavior.

### Additional Information/Context

_No response_

### CDK CLI Version

2.70

### Framework Version

_No response_

### Node.js Version

14

### OS

linux

### Language

Typescript

### Language Version

_No response_

### Other information

_No response_

Contributor guide

Open the contributing guide

Research direction

Start at the aws-ec2 ISecurityGroup.connections.allowFrom entry point and reproduce the behavior with the provided security-group example. Check how the corresponding allowTo policy is updated; done means existing outbound rules remain while the new rule for security group b is added.

Written by the indexing model from the issue text.

Assessment

Tech stack
aws, typescript
Domain
cloud, networking, security
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
48/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.