Network Basics in the Cloud

Video + 10 min read · includes a lab

Scanner203.0.113.45
Firewall rules
Software settingsAllow 3306 from anywhere
Database10.0.2.15
Port 3306
Network Basics in the Cloud
0:00 / 5:46 · Network Basics in the Cloud
Chapters and transcript

Network Basics in the Cloud In an office, the network is cables and a physical firewall. In the cloud, the network is software settings. They decide which servers can be reached. Here, someone adds one wrong rule. Now a scanner on the internet can reach the database directly. In this lesson, you will learn how cloud networks work, and how to keep them closed.

Virtual networks Each provider lets you create a private network for your resources. On AWS, it is a Virtual Private Cloud, or VPC. On Azure, it is a Virtual Network, or VNet. On Google Cloud, it is a VPC network. Inside it, you create subnets, smaller ranges of IP addresses, and place servers and databases in them.

Virtual networks Addresses are written in CIDR notation. Ten dot zero dot zero dot zero, slash sixteen, is the whole network, about sixty-five thousand addresses. Ten dot zero dot one dot zero, slash twenty-four, is one subnet of two hundred and fifty-six addresses. And slash thirty-two means exactly one address. The number after the slash says how many bits are fixed. A bigger number means a smaller range.

Firewall rules Providers control traffic with software firewalls. AWS uses security groups and network ACLs, Azure uses network security groups, and Google Cloud uses VPC firewall rules. A rule usually has four parts. The direction, inbound or outbound. The protocol. The port. And the source or destination.

Firewall rules Here is a web server with two inbound rules. Rule one allows port four four three from anyone, so a visitor can open the website. Rule two allows SSH on port twenty-two, but only from the office IP address. When a stranger tries SSH, nothing allows it. In AWS, security groups deny inbound traffic by default, so it is dropped.

Why 0.0.0.0/0 is dangerous Now the most important range. Zero dot zero dot zero dot zero, slash zero, means every IPv4 address. For IPv6, the same idea is written colon colon slash zero. A rule with this source lets anyone on the internet reach that port. That is fine for a website on ports eighty and four four three. It is dangerous for management and database ports.

Why 0.0.0.0/0 is dangerous Learn these ports. Twenty-two is SSH, the Linux remote login. Three three eight nine is RDP, Windows Remote Desktop. Then the databases: three three zero six for MySQL and MariaDB, five four three two for PostgreSQL, one four three three for Microsoft SQL Server, two seven zero one seven for MongoDB, and six three seven nine for Redis. None of these should be open to everyone.

Why 0.0.0.0/0 is dangerous Attackers scan the whole internet every day. This server has SSH open to everyone. Very quickly, it starts receiving password guessing attempts. This database is also open to everyone, and it has a weak password. It can be found and copied. Some older or badly configured databases do not even require a password.

Finding wide-open rules You can search AWS for security groups with rules that mention zero dot zero dot zero dot zero, slash zero. Here are two results. Port four four three on the web server is expected. Port twenty-two open to the world is a finding to fix. Check every result like this.

Public and private subnets Subnets come in two kinds. A public subnet has a route to the internet. Resources in it can have public IP addresses, and can be reached from outside if firewall rules allow. A private subnet has no direct route from the internet. That is where databases and internal servers belong.

Public and private subnets Here is a common, safe design. A visitor reaches the load balancer in a public subnet. It passes the request to app servers in a private subnet. Only the app servers can reach the database. If an attacker tries the database directly from the internet, it is refused. And a NAT gateway lets private servers download updates, without allowing new connections in.

Safer ways to reach servers Administrators still need to log in to servers. Safer options: managed access services, which use your cloud identity and MFA, often with no inbound port open at all. A VPN, so servers only accept SSH or RDP from the VPN range. Or an allow-list of known addresses with slash thirty-two. But changing SSH to another port is not a real fix. Scanners check all ports.

Safer ways to reach servers Here is a managed access service in a cloud console. Examples are AWS Systems Manager Session Manager, Azure Bastion and Google Cloud Identity-Aware Proxy. The admin is already signed in with a cloud identity and MFA. She picks the app server and starts a session. She is connected, and no inbound SSH port is open.

Quick check Quick check. A review finds a PostgreSQL database with port five four three two open to zero dot zero dot zero dot zero, slash zero. Only the app servers need to reach it. What is the best fix? Choose your answer.

Key takeaways Let us put it together. Never allow SSH, RDP or database ports from everywhere. Put databases and internal servers in private subnets. Allow traffic only from the layer that needs it. Use managed access or a VPN for administration. And describe your rules, remove temporary ones, and review them regularly. Now read the lesson below, and try the firewall lab.

In a normal office, the network is made of cables, switches and a physical firewall. In the cloud, the network is made of software settings. These settings decide which servers can talk to each other and which can be reached from the internet. One wrong rule can expose a server to the whole world.

Virtual networks

Each provider lets you create a private network for your resources:

  • AWS: Virtual Private Cloud (VPC)
  • Azure: Virtual Network (VNet)
  • Google Cloud: VPC network

Inside this network you create subnets, which are smaller ranges of IP addresses. You place servers, databases and other resources into subnets. Network addresses are written in CIDR notation, for example:

10.0.0.0/16     -> the whole network (about 65,000 addresses)
10.0.1.0/24     -> one subnet (256 addresses)
203.0.113.10/32 -> exactly one IP address

The number after the slash says how many bits are fixed. A bigger number means a smaller range. /32 means one single IPv4 address.

Security groups and firewall rules

Cloud providers let you control traffic with software firewalls:

  • AWS: security groups attached to servers, plus network ACLs on subnets
  • Azure: network security groups (NSGs)
  • Google Cloud: VPC firewall rules

A rule usually has four parts: direction (inbound or outbound), protocol, port, and source or destination. Here is an example of inbound rules for a web server:

Direction  Protocol  Port  Source           Meaning
Inbound    TCP       443   0.0.0.0/0        Anyone can visit the website (HTTPS)
Inbound    TCP       22    203.0.113.10/32  Only the office IP can use SSH

The first rule is normal for a public website. The second rule is careful: SSH is allowed, but only from one known address.

Security groups in AWS are deny by default for inbound traffic. Nothing gets in unless a rule allows it. The danger comes when people add rules that are too wide.

Why 0.0.0.0/0 is dangerous

The range 0.0.0.0/0 means every IPv4 address. For IPv6, the same idea is written ::/0. A rule with this source lets anyone on the internet reach that port.

That is fine for a public website on ports 80 and 443. It is dangerous for management and database ports, such as:

Port Service
22 SSH (Linux remote login)
3389 RDP (Windows Remote Desktop)
3306 MySQL and MariaDB
5432 PostgreSQL
1433 Microsoft SQL Server
27017 MongoDB
6379 Redis

Attackers run automated scans of the whole internet every day. A server with SSH or RDP open to everyone will start receiving password guessing attempts very quickly. An exposed database may be found and copied, especially if it has a weak password or none at all. Some databases were designed to run on trusted networks only, and older or badly configured installations may not require a password.

You can search AWS for security groups that have rules mentioning 0.0.0.0/0:

aws ec2 describe-security-groups --filters Name=ip-permission.cidr,Values=0.0.0.0/0

Then check each result. Port 443 on a web server is expected. Port 22, 3389 or a database port is a finding to fix.

Public and private subnets

A public subnet has a route to the internet, so resources in it can have public IP addresses and be reached from outside (if firewall rules allow). A private subnet has no direct route from the internet.

A common, safe design for a web application:

Internet
   |
[ Load balancer ]   public subnet, allows 443 from 0.0.0.0/0
   |
[ App servers ]     private subnet, allows traffic only from the load balancer
   |
[ Database ]        private subnet, allows traffic only from the app servers

Each layer only accepts traffic from the layer above it. Even if someone finds the database address, they cannot reach it from the internet.

Servers in a private subnet still need to download updates. A NAT gateway lets them make outbound connections to the internet, while still blocking new inbound connections from outside.

Safer ways to reach servers

Administrators still need to log in to servers. Instead of opening port 22 or 3389 to the world, use one of these options:

  • Managed access services. AWS Systems Manager Session Manager, Azure Bastion and Google Cloud Identity-Aware Proxy (IAP) let you connect to servers through the provider's console, using your cloud identity and MFA. Often no inbound port needs to be open at all.
  • VPN. Staff connect to a VPN first, and the servers only accept SSH or RDP from the VPN's address range.
  • Allow-listing. If a port must be open, allow only specific, known IP addresses with /32, and remove the rule when it is no longer needed.

Changing SSH to a different port number is not a real fix. Scanners check all ports, not only the common ones.

How to defend

  • Never allow SSH, RDP or database ports from 0.0.0.0/0 or ::/0.
  • Put databases and internal servers in private subnets.
  • Allow traffic only from the layer that needs it, such as app servers to the database.
  • Use managed access services or a VPN for administration.
  • Give firewall rules a clear description, and remove temporary rules when the work is done.
  • Review rules regularly, and use the provider's security tools to flag wide-open ports.

HANDS-ON LAB

Firewall Rule Review

Review ChaiCorp's security group rules and decide which ones to keep, change or remove.

Start the lab →

Check your understanding

Answer every question correctly to complete this lesson. If you miss one, try the quiz again.

1. In a firewall rule, what does the source 0.0.0.0/0 mean?

2. Where should a database server normally be placed?

3. A developer needs to manage a cloud server from home. What is safer than opening port 22 to the world?

Locked: answer every quiz question above correctly to complete this lesson.

Spotted a mistake or something unclear? Report a mistake