Labs / Cloud / Guarding & joining a VPC

Lab 1 of 2 · Guarding & joining a VPC

Security groups and network ACLs: the cloud's two firewalls

Open a server's security group to one more sender, and see why the network ACL must allow every answer.

Start this lab 4 steps

The idea

A cloud server sits behind two firewalls: a security group around the server and a network ACL at its subnet's edge. Open one to a new server, and find the answer that the other one drops.

The rule names one address
The rule names one address
Any yes is enough
Any yes is enough
The list sees only what crosses the edge
The list sees only what crosses the edge
One conversation, two firewalls
One conversation, two firewalls

Steps

  1. Who may reach the orders

    Priya runs Lumen Books, an online bookshop, in a VPC. Two web servers, web and web2, sit in the public subnet. The orders service, app, sits in the private subnet and answers on port 8080.

    Every server in a cloud has a security group: a firewall the provider wraps around the server's network card. It holds allow rules only. Whatever no rule allows is dropped, so a new group lets nothing in.

    The provider runs the group outside the server, where nothing on the server can turn it off. Here it's iptables, Linux's packet rules, on app itself, with the same rules.

    web2 went live this morning. Ask app for the orders from web, then from web2. Then list app's rules.

    web:~# curl -sS -m 3 http://10.0.1.10:8080/
    web2:~# curl -sS -m 3 http://10.0.1.10:8080/
    app:~# iptables -S
  2. One more sender

    web2 needs the orders too. On AWS, you'd open app's group and add an inbound rule: TCP, port 8080, from 10.0.0.11/32. Here it's one command on app.

    -A adds the rule at the end of the list, after the three rules already there. Does that matter?

    app:~# iptables -v -A INPUT -s 10.0.0.11/32 -p tcp --dport 8080 -j ACCEPT
    web2:~# curl -sS -m 3 http://10.0.1.10:8080/
  3. A list for the whole subnet

    A security group guards one server. A network ACL, or NACL, guards a whole subnet's edge, and it works differently in three ways:

    • its rules are numbered and read in order, and the first one that matches decides;
    • a rule can allow or deny;
    • it remembers nothing, so every packet is judged on its own.

    The private subnet's ACL lives on vpcRouter, the Router that every packet into or out of the subnet crosses. nacl-in is for packets going in, nacl-out for packets leaving.

    jobs, the nightly job server, has a group that lets anything in: someone set it up in a hurry. Ask jobs for its page, on port 9000, from web and from app. Then list both of the ACL's lists.

    web:~# curl -sS -m 3 http://10.0.1.30:9000/
    app:~# curl -sS -m 3 http://10.0.1.30:9000/
    vpcRouter:~# iptables -L nacl-in -n --line-numbers
    vpcRouter:~# iptables -L nacl-out -n --line-numbers
  4. The answer needs a rule too

    A colleague reads nacl-out and frowns. Rule 1 lets the private subnet send to more than 64,000 ports in the public subnet. The shop only talks to app on port 8080, so surely port 8080 is enough?

    Try it: iptables -R nacl-out 1 replaces rule 1 with a narrower one. Then ask for the orders from web while the lab records on vpcRouter's card in the private subnet. Last, put the wide rule back and ask again.

    vpcRouter:~# iptables -R nacl-out 1 -d 10.0.0.0/24 -p tcp --dport 8080 -j ACCEPT
    web:~# curl -sS -m 3 http://10.0.1.10:8080/
    vpcRouter:~# iptables -R nacl-out 1 -d 10.0.0.0/24 -p tcp --dport 1024:65535 -j ACCEPT
    web:~# curl -sS -m 3 http://10.0.1.10:8080/

Run these steps on real machines

Keep reading

Learn it on real machines.

Every lab is a small network of real Linux machines in your browser. Sign in with Google or email to start.

Start this lab