Using Security Groups and Network ACLs to Control Traffic
- A security group protects the instances in it.
- A network ACL protects associated subnets and all the resources in the subnets.
As shown in Figure 1, security groups A and B protect the network security of ECSs. Network ACLs A and B add an additional layer of defense to ECSs in subnets 1 and 2.
- Security group: Allowing Traffic from Given IP Addresses or a Security Group
- Security group: Allowing Traffic from a Virtual IP Address
- Security group: Allowing Communications Between Instances in Two VPCs Connected by a VPC Peering Connection
- Network ACL: Controlling External Access to Instances in a Subnet
- Network ACL: Controlling Communications Between Instances in Different Subnets
Allowing Traffic from Given IP Addresses or a Security Group
- Add inbound rule A01 to Sg-A to allow traffic from IP addresses in 172.16.0.0/24 to access SSH port 22 on the ECSs in Sg-A for remotely logging in to these ECSs.
- Add inbound rule B01 to Sg-B to allow the ECSs in Sg-A to access SSH port 22 on the ECSs in Sg-B for remotely logging in to the ECSs in Subnet-B.
Allowing Traffic from a Virtual IP Address
- Add inbound rule A01 to Sg-A to allow the ECSs in Sg-B to access the ECSs in Sg-A using private IP addresses.
- Add inbound rule B01 to Sg-B to allow traffic from virtual IP address 192.168.0.21 to the ECSs in Sg-B using any protocol over any port. You can also set the source to the CIDR block of Subnet-A (192.168.0.0/24).
Do not add rules like rule B02. This rule allows the ECSs in Sg-A to access the ECSs in Sg-B using private IP addresses but not virtual IP address 192.168.0.21.
Allowing Communications Between Instances in Two VPCs Connected by a VPC Peering Connection
- Rule A01 with Source to Sg-B to allow ECSs in Sg-B to access ECSs in Sg-A.
- Rule B01 with Source to Sg-A to allow ECSs in Sg-A to access ECSs in Sg-B.
Controlling External Access to Instances in a Subnet
A network ACL controls traffic in and out of a subnet. If both security group and network ACL rules are configured, traffic matches network ACL rules first and then security group rules.
- Network ACL rules:
- Inbound rule: Custom rule A01 allows the whitelisted instance to remotely log in to the instances in Subnet-A over SSH. The default rule denies any other traffic to the subnet.
- Outbound rule: Network ACLs are stateful. The responses to inbound requests are allowed to leave the subnet. This means you do not need to additionally add outbound rules to allow such response traffic. The default rule denies any other outbound traffic.
- Security group rules:
- Inbound rule: Rule A01 allows the whitelisted instance to remotely log in to instances in Subnet-A over SSH. Rule A02 allows instances in the security group to communicate with each other. Other traffic is denied to access the instances in security group Sg-A.
- Outbound rule: Rule A03 allows instances in Sg-A to access external resources.
Controlling Communications Between Instances in Different Subnets
- Connect ECS-02 to ECS-03.
- Isolate ECS-01 from ECS-03.
- Add inbound and outbound rules to Sg-A to ensure that the ECSs in this security group can communicate with each other.
The subnet has not been associated with a network ACL, so after the security group rules are added, both ECS-01 and ECS-02 can communicate with ECS-03.
- Associate Subnet-X01 and Subnet-X02 with Fw-A.
If there is only the default rule in Fw-A, instances in the same subnet can communicate with each other, while instances in different subnets are isolated from each other. In this case, ECS-01 and ECS-02 can communicate with each other, while ECS-01 and ECS-03 as well as ECS-02 and ECS-03 are isolated from each other.
- Add custom rules to Fw-A to allow ECS-02 to communicate with ECS-03.
- Add custom rule A01 to allow ECS-03 to access Subnet-X01.
- Add custom rule A02 to allow ECS-02 to access Subnet-X02.
- Add custom rule A03 to allow traffic destined for ECS-03 to leave Subnet-X01.
- Add custom rule A04 to allow traffic destined for ECS-02 to leave Subnet-X02.
Feedback
Was this page helpful?
Provide feedbackThank you very much for your feedback. We will continue working to improve the documentation.