Description
Resources that omit a security group can inherit the VPC default group. Its initial inbound rule allows traffic from group members. Its outbound rules allow all IPv4 destinations and, in IPv6-enabled VPCs, all IPv6 destinations.
Potential impact
Adding SSH access to this shared group affects existing and future members. Where network paths exist, new inbound rules can expose management ports and broad egress lets workloads initiate more outbound connections.
Remediation
Create a dedicated group for the workload’s required sources, destinations and ports. Specify outbound rules when creating it, since omission allows all outbound traffic. Attach the group and verify required traffic. Remove the old association and retest. Once dependencies are accounted for, remove unnecessary rules from the default group. The group itself cannot be deleted.
Examples
Supply the existing default group ID for the first example. The second needs the VPC ID and approved SSH source and destination CIDRs.
Before
Parameters:
DefaultSecurityGroupId:
Type: AWS::EC2::SecurityGroup::Id
Resources:
SharedSSHIngress:
Type: AWS::EC2::SecurityGroupIngress
Properties:
GroupId: !Ref DefaultSecurityGroupId
IpProtocol: tcp
FromPort: 22
ToPort: 22
CidrIp: 0.0.0.0/0
SharedSSHEgress:
Type: AWS::EC2::SecurityGroupEgress
Properties:
GroupId: !Ref DefaultSecurityGroupId
IpProtocol: tcp
FromPort: 22
ToPort: 22
CidrIp: 0.0.0.0/0
The first template allows TCP 22 to and from all IPv4 addresses on the specified default group.
After
Parameters:
VpcId:
Type: AWS::EC2::VPC::Id
AdminCidr:
Type: String
SSHDestinationCidr:
Type: String
Resources:
DedicatedSecurityGroup:
Type: AWS::EC2::SecurityGroup
Properties:
GroupDescription: Restricted SSH connectivity
VpcId: !Ref VpcId
SecurityGroupIngress:
- IpProtocol: tcp
FromPort: 22
ToPort: 22
CidrIp: !Ref AdminCidr
SecurityGroupEgress:
- IpProtocol: tcp
FromPort: 22
ToPort: 22
CidrIp: !Ref SSHDestinationCidr
The second creates a dedicated group, without attaching it to a workload. Its outbound rule permits new SSH connections to SSHDestinationCidr. Replies to an allowed inbound connection require no reverse rule.