Cloud Firewalls vs Network Security Groups: How to Secure Workloads
Network security groups and security groups are built-in, stateful packet filters that allow or deny traffic to individual cloud resources by IP, port and protocol. Cloud firewalls such as AWS Network Firewall, Azure Firewall and Google Cloud NGFW are managed network firewalls that inspect traffic for a whole network with features like domain filtering, intrusion prevention and TLS inspection.
Topic: Network Security in Cybersecurity & Ethical Hacking · Explainer
Also covers: Cloud & Container Security, Cloud Computing: AWS, Azure & GCP
Quick answer: Network security groups and security groups are built-in, stateful packet filters that allow or deny traffic to individual cloud resources by IP, port and protocol. Cloud firewalls such as AWS Network Firewall, Azure Firewall and Google Cloud NGFW are managed network firewalls that inspect traffic for a whole network with features like domain filtering, intrusion prevention and TLS inspection. Use security groups or NSGs on every workload as the first layer, and a cloud firewall at network boundaries for central control of internet, inter-network and on-premises traffic.
Key takeaways
- Security groups and NSGs are free, per-resource and stateful; they are the minimum.
- AWS network ACLs are stateless subnet filters; use them sparingly.
- Managed cloud firewalls add inspection and central policy, at extra cost.
- Never allow SSH (22) or RDP (3389) from 0.0.0.0/0.
- Reference other security groups or tags instead of IP lists where possible.
Table of Contents
- What Are the Layers of Cloud Network Filtering?
- How Do Security Groups and NSGs Work?
- What Do Managed Cloud Firewalls Add?
- How Do They Compare Across AWS, Azure and Google Cloud?
- What Does a Three-Tier Design Look Like?
- How Do You Create Rules from the CLI?
- How Do You Find Risky Rules?
- What Are the Best Practices?
- References
What Are the Layers of Cloud Network Filtering?
- Resource level: AWS security groups, Azure NSGs on NICs, Google Cloud firewall rules targeted by tag or service account.
- Subnet level: AWS network ACLs, Azure NSGs on subnets.
- Network boundary: AWS Network Firewall, Azure Firewall, Google Cloud NGFW, or third-party virtual appliances.
- Application layer: web application firewalls in front of HTTP services.
This layering is defence in depth: a mistake in one layer is caught by another.
How Do Security Groups and NSGs Work?
AWS security groups attach to network interfaces. They only contain allow rules, are stateful (return traffic is automatically allowed), and can reference other security groups as sources. Network ACLs apply to subnets, are stateless, support deny rules and are evaluated in number order.
Azure NSGs attach to subnets or NICs. Rules have priorities from 100 to 4096 (lower runs first), support allow and deny, and are stateful. Default rules allow traffic within the virtual network and from the Azure load balancer, and deny other inbound traffic. Application security groups let you group VMs by role. See the Azure NSG overview.
Google Cloud VPC firewall rules apply to the whole VPC network and target instances by network tag or service account. They are stateful with priorities from 0 to 65535. Hierarchical and network firewall policies, part of Cloud NGFW, let organisations enforce rules across projects.
What Do Managed Cloud Firewalls Add?
- Central policy for many networks, often in a hub network.
- Outbound filtering by domain name (FQDN), such as allowing only
*.ubuntu.comfor updates. - Intrusion detection and prevention signatures.
- TLS inspection in premium tiers.
- Logging of allowed and denied flows for investigations.
Examples: AWS Network Firewall, Azure Firewall and Google Cloud NGFW Enterprise.
How Do They Compare Across AWS, Azure and Google Cloud?
| AWS | Azure | Google Cloud | |
|---|---|---|---|
| Per-resource filter | Security group | NSG on NIC | Firewall rule by tag or service account |
| Subnet filter | Network ACL (stateless) | NSG on subnet | Not separate; rules are network-wide |
| Deny rules | No in SGs; yes in NACLs | Yes | Yes |
| Grouping by role | SG references | Application security groups | Tags, service accounts |
| Managed firewall | AWS Network Firewall | Azure Firewall | Cloud NGFW |
| Flow logs | VPC Flow Logs | VNet flow logs | VPC Flow Logs, firewall rules logging |
What Does a Three-Tier Design Look Like?
| Tier | Allow inbound from | Ports |
|---|---|---|
| Load balancer | Internet (0.0.0.0/0) | 443 |
| Web/app servers | Load balancer security group only | 8080 |
| Database | App security group only | 5432 |
| Admin access | Bastion or SSM/Bastion service only | 22 or none |
Because each tier references the previous tier's group rather than IP ranges, scaling out adds servers without changing rules.
How Do You Create Rules from the CLI?
# AWS: allow app tier to reach the database tier on 5432
aws ec2 authorize-security-group-ingress --group-id sg-0db0000000000000 \
--protocol tcp --port 5432 --source-group sg-0app000000000000
# Azure: allow HTTPS from the internet to the web subnet NSG
az network nsg rule create -g rg-prod --nsg-name nsg-web -n allow-https \
--priority 200 --direction Inbound --access Allow --protocol Tcp \
--source-address-prefixes Internet --destination-port-ranges 443
# Google Cloud: allow app-tagged VMs to reach db-tagged VMs on 5432
gcloud compute firewall-rules create allow-app-to-db --network prod-vpc \
--allow tcp:5432 --source-tags app --target-tags db
How Do You Find Risky Rules?
# AWS: security groups with SSH open to the world
aws ec2 describe-security-groups \
--filters Name=ip-permission.from-port,Values=22 Name=ip-permission.cidr,Values=0.0.0.0/0 \
--query "SecurityGroups[].{ID:GroupId,Name:GroupName}"
# Google Cloud: rules open to 0.0.0.0/0
gcloud compute firewall-rules list --filter="sourceRanges:0.0.0.0/0" \
--format="table(name,network,allowed[].map().firewall_rule().list())"
CIS benchmarks for each cloud include checks for unrestricted SSH and RDP. Cloud security posture tools run these continuously.
What Are the Best Practices?
- Deny by default; open only required ports from required sources.
- Use managed access such as AWS Systems Manager Session Manager, Azure Bastion or Google IAP instead of open SSH or RDP.
- Control outbound traffic too, not just inbound.
- Manage rules as code (Terraform, Bicep) with review.
- Enable flow logs and review denied traffic.
Related: what a VPC is and types of firewalls. WebAsha offers cloud security training for AWS and Azure.
References
Frequently Asked Questions
What's Your Reaction?
Like
0
Dislike
0
Love
0
Funny
0
Wow
0
Sad
0
Angry
0