1. Introduction
AWS Security Groups function as virtual firewalls within a Virtual Private Cloud (VPC) at the instance level. They serve as an important layer of defence, managing network traffic flow to and from your EC2 instances.
2. Key Characteristics
- Security groups are stateless. Inbound rules simply restrict incoming traffic and do not automatically permit corresponding outbound traffic. For example, if you allow inbound SSH traffic (port 22), you must specifically allow outward traffic on port 22 to support interactive sessions.
- Instance-level: Security Groups are linked to specific EC2 instances. An instance can have numerous security groups connected, allowing for more flexible and layered security configurations.
- Rule-Based: Security Groups operate according to rules that specify:
- Protocol: (such as TCP, UDP, or ICMP)
- Port Range (e.g., 22 for SSH, 80 for HTTP).
- Source/Destination: (for example, IP addresses, IP ranges, security groups, or 0.0.0.0/0 for all sources and destinations).
3. Common Use Cases
- Restricting SSH Access: To prevent unauthorised access, allow SSH communication from only particular IP addresses or security groups.
- Enabling Web Server Access: Allow HTTP and HTTPS traffic from the internet via ports 80 and 443.
- Internal Communication: Enable communication between instances inside a certain VPC or subnet.
- Database Access: Limit database access by only permitting traffic from authorised applications or services.
4. Best Practices
- Apply the principle of least privilege by granting only the essential permissions. Avoid too liberal rules, which may expose your instances to needless danger.
- Apply Security Group Ingress Rules only occasionally. Carefully assess each inbound rule and only allow necessary traffic.
- Use Security Group Egress Rules: Create outbound rules to manage traffic leaving your instances, particularly for services that connect externally.
- Review and Update: Review your security group rules regularly and update them as appropriate to reflect changes in your application's requirements and security posture.
- Avoid Default Security Groups: The default security group frequently grants extensive permissions. Create specific security groups for each instance and avoid using the default wherever possible.
5. Common Misconfigurations
- Overly Permissive Rules: Allowing unnecessary traffic from 0.0.0.0/0 (all sources) might greatly broaden the attack vector.
- incorrect Port Numbers: Typos or erroneous port numbers might result in unauthorised access or denial of service.
- Missing Outbound Rules: Failing to create outbound rules for apps that require outgoing connections can cause problems.
Top comments (0)