Course contentsShow
← Security
Lesson 1821 of 3,05237. Cloud Security - Network ArchitectureFree lesson

Security Group Rule Design Best Practices

Principle of least privilege, port ranges, protocol selection, source/destination specifications, and avoiding overly permissive rules.

Security Group Rule Design Best Practices

What you'll learn: How to design security group rules that minimize attack surface while maintaining necessary access.

Core Principle: Least Privilege

Security group rules act like bouncers at your cloud resource's door—they decide who gets in and for what purpose. The principle of least privilege means granting only the minimum permissions required for legitimate traffic. Never open more ports, protocols, or sources than absolutely necessary.

Think of it like giving someone keys to specific rooms in a building, not a master key to everything.

Port Range Specificity

Avoid broad port ranges. Instead of allowing 0-65535, specify exact ports:

  • ✅ Allow TCP port 443 for HTTPS
  • ✅ Allow TCP port 5432 for PostgreSQL
  • ❌ Allow TCP ports 1-10000 "just in case"

Opening wide port ranges creates unnecessary exposure. Even unused ports become potential attack vectors.

Protocol Selection

Choose the specific protocol your application needs:

  • Use TCP for connection-oriented services
  • Use UDP for specific services that require it (like DNS)
  • Use ICMP only when necessary for diagnostics
  • Avoid allowing "All Protocols" unless you have exceptional requirements

Source and Destination Specifications

Be precise about sources:

  • ✅ Specify exact IP addresses or CIDR blocks (10.0.1.5/32)
  • ✅ Reference other security groups for inter-service communication
  • ❌ Use 0.0.0.0/0 (internet-wide access) unless serving public traffic

For internal services, source should be specific security groups or private subnets—never "anywhere."

Avoiding Overly Permissive Rules

Common anti-patterns to avoid:

  • Allowing 0.0.0.0/0 on administrative ports (SSH, RDP)
  • Using description "temporary test rule" that stays forever
  • Opening all ports to your office network instead of specific ranges
  • Allowing unrestricted outbound traffic without justification

Review rules quarterly and remove anything not actively required.

Key Takeaway: Design security group rules with surgical precision—specific ports, protocols, and sources only. Every overly broad rule is an invitation to attackers.