Everything You Need to Know About Security Groups

Everything You Need to Know About Security Groups

In the cloud, security is not just an option — it’s a necessity. Whether you’re deploying an application or managing infrastructure, Security Groups act as your first line of defense against unauthorized access. But what exactly are Security Groups, and how can you configure them effectively? This blog will take you through everything you need to know with a step-by-step guide to setting up Security Groups.


What Are Security Groups?

A Security Group is a virtual firewall in cloud environments (such as AWS, Azure, or GCP) that controls inbound and outbound traffic to cloud instances. It defines which traffic is allowed and which is denied, based on rules set by the user.

Unlike traditional firewalls, Security Groups:

  • Operate at the instance level, not the network level.

  • Are stateful, meaning if inbound traffic is allowed, the response outbound traffic is automatically allowed.

  • Can be associated with multiple instances, making security management more efficient.


Why Security Groups Are Critical for Cloud Security

Security Groups protect cloud instances by:

  • Blocking unauthorized access – Only specific IPs, ports, and protocols can reach your instances.

  • Preventing malicious attacks – Restricts access to known sources, reducing attack surfaces.

  • Ensuring compliance – Helps enforce security best practices like least privilege access.

  • Simplifying security management – Easy to modify and apply to multiple instances.


Security Group Rules: Inbound & Outbound

Each Security Group consists of rules that determine the allowed traffic.

Inbound Rules (Incoming Traffic)

  • Define which ports, protocols, and sources are allowed to access the instance.

  • Example: Allow SSH (Port 22) access only from your IP (203.0.113.0/32).

Outbound Rules (Outgoing Traffic)

  • Define which traffic is allowed to leave the instance.

  • By default, most cloud providers allow all outbound traffic, but you can restrict it for security.

RuleProtocolPortSource/DestinationPurpose
SSHTCP22My IP (203.0.113.0/32)Secure remote access
HTTPTCP800.0.0.0/0 (Everyone)Public web access
HTTPSTCP4430.0.0.0/0 (Everyone)Secure web access
DatabaseTCP3306 (MySQL)App Server IP onlyRestrict DB access

Step-by-Step Guide: Creating and Configuring Security Groups

Let’s walk through setting up a Security Group in AWS. The process is similar for Azure Network Security Groups (NSGs) and GCP firewall rules.

Step 1: Log in to AWS Management Console

  • Go to EC2 Dashboard.

  • Click on "Security Groups" under "Network & Security."

Step 2: Create a New Security Group

  • Click Create Security Group.

  • Enter:

    • Name: MyWebServerSG

    • Description: Security Group for web server

    • VPC: Select your existing VPC

Step 3: Configure Inbound Rules

  • Click "Inbound rules" → "Add Rule".

  • Add the following rules:

    1. Allow SSH

      • Type: SSH

      • Protocol: TCP

      • Port Range: 22

      • Source: Your IP (203.0.113.0/32)

    2. Allow HTTP (Web Traffic)

      • Type: HTTP

      • Protocol: TCP

      • Port Range: 80

      • Source: Anywhere (0.0.0.0/0)

    3. Allow HTTPS (Secure Web Traffic)

      • Type: HTTPS

      • Protocol: TCP

      • Port Range: 443

      • Source: Anywhere (0.0.0.0/0)

Step 4: Configure Outbound Rules

  • By default, all outbound traffic is allowed.

  • If needed, restrict traffic to specific destinations (e.g., database access).

Step 5: Attach the Security Group to an EC2 Instance

  • Go to EC2 Dashboard → Instances.

  • Select your instance.

  • Click Actions → Networking → Change Security Groups.

  • Select your newly created Security Group and click Assign.

Step 6: Verify the Security Group

  • Try SSH access using:

      ssh -i my-key.pem ec2-user@your-instance-ip
    
  • Open the instance’s public IP in a browser to check HTTP/HTTPS access.


Best Practices for Security Groups

  • Follow the Principle of Least Privilege – Only allow the minimum required access.

  • Avoid 0.0.0.0/0 for SSH & RDP – Always restrict remote access to your own IP.

  • Use Different Security Groups for Different Applications – Separate database, web servers, and admin access.

  • Regularly Audit and Review Rules – Remove unused or overly permissive rules.

  • Monitor Logs and Alerts – Use AWS CloudTrail, GuardDuty, or Azure Monitor for tracking changes.


My Final Thoughts

Security Groups are the backbone of cloud security. Configuring them correctly ensures that your applications and data remain protected from unwanted access. Whether you are launching a web server, a database, or an internal app, understanding and managing Security Groups effectively is a must for every DevOps Engineer.