Skip to main content

Understanding Firewalls in Operating Systems and Cloud Environments

· 6 min read
Rahul Kumar
Senior Data Engineer @ AON

Firewalls are essential components of modern network security, serving as a protective barrier between trusted and untrusted networks. Whether on-premises or in the cloud, firewalls monitor and control traffic to enforce security policies. This blog explores the role of firewalls in operating systems (OS) and cloud environments, highlighting their similarities, differences, and best practices for cloud usage.


What Is a Firewall?

A firewall is a security device or software designed to monitor and control incoming and outgoing network traffic. Firewalls enforce policies based on pre-configured rules to prevent unauthorized access and protect systems from malicious traffic.


Firewalls in Operating Systems

Firewalls integrated with operating systems operate at the host level, safeguarding individual devices. These are often referred to as host-based firewalls.

Key Features

  1. Location:

    • Positioned within the OS networking stack, filtering traffic before it reaches applications or leaves the system.
  2. Types:

    • Packet Filtering Firewalls: Inspect packets at the network layer based on IP, port, and protocol.
    • Stateful Firewalls: Monitor connection states and allow only legitimate traffic.
  3. Examples:

    • Windows Firewall: Built into Windows OS, offering GUI and command-line control.
    • iptables/nftables: Commonly used in Linux for detailed traffic filtering.
    • pf: Used in macOS and BSD systems.

Configuration Example: Linux iptables

# Allow SSH traffic
iptables -A INPUT -p tcp --dport 22 -j ACCEPT

# Drop all other incoming traffic
iptables -A INPUT -j DROP

Firewalls in Cloud Environments

Cloud firewalls operate at a broader scale, managing traffic across multiple virtual resources like virtual machines (VMs), containers, and managed services. These are often categorized as network firewalls or perimeter firewalls.

Key Features

  1. Location:

    • Positioned within the cloud provider's network infrastructure, controlling traffic at the virtual network or subnet level.
  2. Types:

    • Network Security Groups (NSGs): Define inbound and outbound traffic rules for specific cloud resources.
    • Perimeter Firewalls: Apply rules for traffic entering or leaving a Virtual Private Cloud (VPC) or Virtual Network (VNet).
    • Web Application Firewalls (WAFs): Protect web applications from common vulnerabilities like SQL injection and XSS.
  3. Examples by Cloud Provider:

    • AWS:
      • Security Groups: Host-based firewall rules.
      • Network ACLs: Subnet-level traffic filtering.
      • AWS WAF: Web application security.
    • Azure:
      • NSGs: Control VM and subnet traffic.
      • Azure Firewall: Centralized, managed firewall service.
    • GCP:
      • VPC Firewall Rules: Apply to resources within a VPC.
      • Cloud Armor: WAF for HTTP(S) applications.

Cloud Firewall Capabilities

  • Centralized Management:

    • Cloud firewalls allow centralized rule creation and enforcement across multiple resources.
  • Scalability:

    • Automatically adapts to changes in infrastructure, such as autoscaling.
  • Threat Intelligence:

    • Integrates with threat detection systems for proactive security (e.g., AWS Shield, Azure Threat Protection).
  • Logging and Monitoring:

    • Provides centralized logs for compliance and forensic analysis.

Cloud Firewall Configuration Examples

1. AWS Security Groups

Security Groups act as virtual firewalls for EC2 instances. Example configuration:

# Allow HTTP (80) and HTTPS (443) inbound traffic
Inbound Rules:
- Type: HTTP Protocol: TCP Port: 80 Source: 0.0.0.0/0
- Type: HTTPS Protocol: TCP Port: 443 Source: 0.0.0.0/0

# Allow all outbound traffic
Outbound Rules:
- Type: All Traffic Protocol: All Port Range: All Destination: 0.0.0.0/0

2. Azure NSGs

NSGs filter traffic at the subnet or VM level. Example configuration:

Rule Name: Allow-SSH
Priority: 100
Source: Any
Source Port: Any
Destination: VirtualNetwork
Destination Port: 22
Protocol: TCP
Action: Allow

Additional Azure NSG Example: Restricting RDP Access

Rule Name: Restrict-RDP
Priority: 200
Source: Any
Source Port: Any
Destination: VirtualNetwork
Destination Port: 3389
Protocol: TCP
Action: Deny

Azure Firewall: Application Rule Collection Example

Azure Firewall enables defining application-specific rules for outbound traffic:

Rule Name: Allow-Web
Priority: 100
Action: Allow
Target FQDNs: *.microsoft.com, *.azure.com
Protocols: HTTP, HTTPS

Azure Firewall: Network Rule Collection Example

Rule Name: Allow-DNS
Priority: 100
Action: Allow
Source IP: 10.0.0.0/16
Destination IP: 8.8.8.8
Protocol: UDP
Destination Port: 53

3. GCP VPC Firewall Rules

GCP VPC Firewall Rules control access at the VPC level. Example rule:

# Allow SSH traffic to all instances in a VPC
Direction: Ingress
Action: Allow
Protocol: TCP
Port: 22
Source IP: 0.0.0.0/0

Benefits of Cloud Firewalls

  1. Granular Control:

    • Define specific rules for individual instances, subnets, or entire virtual networks.
  2. Integrated Security:

    • Seamlessly integrates with cloud-native services like IAM and monitoring tools.
  3. High Availability:

    • Managed firewalls ensure availability and redundancy without manual configuration.
  4. Cost Efficiency:

    • Pay-as-you-go pricing eliminates the need for expensive hardware firewalls.

Deployment Strategies for Cloud Firewalls

1. Start with Least Privilege

  • Allow only necessary traffic and deny everything else.
  • Example: Default deny-all rule in AWS Security Groups.

2. Use Layered Security

  • Combine host-based firewalls (OS-level) with cloud firewalls for a defense-in-depth approach.

3. Automate Rule Management

  • Use Infrastructure as Code (IaC) tools like Terraform to define and deploy firewall rules.

Example Terraform for AWS Security Group:

resource "aws_security_group" "example" {
name = "example-sg"
description = "Example security group"

ingress {
from_port = 80
to_port = 80
protocol = "tcp"
cidr_blocks = ["0.0.0.0/0"]
}

egress {
from_port = 0
to_port = 0
protocol = "-1"
cidr_blocks = ["0.0.0.0/0"]
}
}

OS Firewalls vs. Cloud Firewalls

FeatureOS FirewallsCloud Firewalls
ScopeProtect individual devices.Manage traffic across resources.
ManagementConfigured per device.Centrally managed.
ScalabilityLimited to local resources.Dynamic and scalable.
IntegrationWorks with the local system.Integrates with cloud services.
CostNo additional cost.Pay-as-you-go pricing.

Conclusion

Firewalls play a vital role in securing both on-premises and cloud environments. While OS firewalls protect individual devices, cloud firewalls offer broader, scalable solutions for managing network traffic across complex infrastructures. Combining both ensures a robust, layered security approach, safeguarding resources from evolving threats.

By leveraging the advanced capabilities of cloud firewalls in AWS, Azure, and GCP, organizations can enhance security while maintaining flexibility and cost-efficiency. Whether deploying a simple application or managing a multi-cloud infrastructure, a well-configured firewall strategy is essential for operational success.