rahuliyer.net

Security in AWS

Security Groups

Default rules of default security group:

Inbound

Source Protocol Port Range Description
The security group ID (sg-xxxxxxxx) All All Allow inbound traffic from network interfaces (and their associated instances that are assigned to the same security group)

Outbound

Destination Protocol Port Range Description
0.0.0.0/0 All All Allow all outbound IPv4 traffic.
::/0 All All Allow all outbound IPv^ traffic. This rule is added by default if you create a VPC with an IPv6 CIDR block or if you associate an IPv6 CIDR block with your existing VPC.

An example security group rules:

Inbound

Source Protocol Port range Description
0.0.0.0/0 TCP 80 Allow inbound HTTP access from all IPv4 addresses
::/0 TCP 80 Allow inbound HTTP access from all IPv6 addresses
0.0.0.0/0 TCP 443 Allow inbound HTTPS access from all IPv4 addresses
::/0 TCP 443 Allow inbound HTTPS access from all IPv6 addresses
Your network’s public IPv4 address range TCP 22 Allow inbound SSH access to Linux instances from IPv4 IP addresses in your network (over the internet gateway)
Your network’s public IPv4 address range TCP 3389 Allow inbound RDP access to Windows instances from IPv4 IP addresses in your network (over the internet gateway)

Outbound

Destination Protocol Port range Description
The ID of the security group for your Microsoft SQL Server database servers TCP 1433 Allow outbound Microsoft SQL Server access to instances in the specified security group
The ID of the security group for your MySQL database servers TCP 3306 Allow outbound MySQL access to instances in the specified security group

VPC Peers and Security groups

If your VPC has a VPC peering connection with another VPC, a security group rule can reference another security group in the peer VPC. This allows instances that are associated with the referenced security group and those that are associated with the referencing security group to communicate with each other.

If the owner of the peer VPC deletes the referenced security group, or if you or the owner of the peer VPC deletes the VPC peering connection, the security group rule is marked as stale. You can delete stale security group rules as you would any other security group rule.

Network Access Control Lists (NACLs)

Network ACL basics

The following are the basic things that you need to know about network ACLs:

You can add or remove rules from the default network ACL, or create additional network ACLs for your VPC. When you add or remove rules from a network ACL, the changes are automatically applied to the subnets that it’s associated with.

The following are the parts of a network ACL rule:

Default network ACL

The default network ACL is configured to allow all traffic to flow in and out of the subnets with which it is associated. Each network ACL also includes a rule whose rule number is an asterisk. This rule ensures that if a packet doesn’t match any of the other numbered rules, it’s denied. You can’t modify or remove this rule.

The following is an example default network ACL for a VPC that supports IPv4 only.

Inbound

Rule # Type Protocol Port range Source Allow/Deny
100 All IPv4 traffic All All 0.0.0.0/0 ALLOW
* All IPv4 traffic All All 0.0.0.0/0 DENY

Outbound

Rule # Type Protocol Port range Source Allow/Deny
100 All IPv4 traffic All All 0.0.0.0/0 ALLOW
* All IPv4 traffic All All 0.0.0.0/0 DENY

In practice, to cover the different types of clients that might initiate traffic to public-facing instances in your VPC, you can open ephemeral ports 1024-65535. However, you can also add rules to the ACL to deny traffic on any malicious ports within that range. Ensure that you place the deny rules earlier in the table than the allow rules that open the wide range of ephemeral ports.

If the maximum transmission unit (MTU) between hosts in your subnets is different, you must add the following network ACL rule, both inbound and outbound. This ensures that Path MTU Discovery can function correctly and prevent packet loss. Select Custom ICMP Rule for the type and Destination Unreachable, fragmentation required, and DF flag set for the port range (type 3, code 4). If you use traceroute, also add the following rule: select Custom ICMP Rule for the type and Time Exceeded, TTL expired transit for the port range (type 11, code 0). For more information, see Network maximum transmission unit (MTU) for your EC2 instance in the Amazon EC2 User Guide for Linux Instances.