A private network, one front door

Course 3 · Today your app leaves the open internet

Today

When What Where
0:00Recap: what's wrong with your M1 deployLecture
0:10VPC, CIDR, subnets, routes, IGW, NATLecture
0:45Security groups vs NACLs, the chain, endpoints, connecting networksLecture
1:10Load balancers, what Floci emulates vs what AWS routesLecture
1:35M2: VPC, subnets, doorsProject
2:00M2: SG chain, new ALB, app and DB move inProject
3:00Intruder test, break drillProject
3:25Tear down v1, check M2, commitProject

Recap

Last session, everything was public

The database, the API on port 8080, SSH. Only a password stood between the internet and our data.

A VPC is your own gated neighborhood

A private network in one Region, across all its AZs. Nothing gets in unless you open a way in.

10.0.0.0/16

Puff's range. The first 16 bits are fixed, the last 16 are yours: 65,536 addresses.

Counting addresses

Size Addresses Where you meet it
/1665,536Puff's VPC, the largest AWS allows
/204,096Each of Puff's four subnets
/24256, 251 usableA classic subnet, AWS keeps 5
/2816, 11 usableThe smallest VPC

Private IPs cost nothing, so Puff's /20 subnets are far bigger than it needs.

Ranges that will collide one day

  • Home routers192.168.0.0/24 or 192.168.1.0/24
  • DockerThe default bridge on 172.17.0.0/16
  • CompaniesA lot of corporate networks somewhere in 10.0.0.0/8
  • AWSRefuses to connect overlapping VPCs. Fixing it later means rebuilding the network
Weeks

At Alan, networks that may need to talk get non-overlapping ranges, decided before the network exists. Changing one later takes weeks.

There's no "public" checkbox

A subnet is public when its route table sends 0.0.0.0/0 to an Internet Gateway. Private when it doesn't.

Two route tables, one difference

Destination Public Private
10.0.0.0/16locallocal
0.0.0.0/0igw-... Internet Gatewaynat-... NAT gateway
S3 prefix list pl-...vpce-... endpointvpce-... endpoint

Don't trust a subnet's name. Open its route table and look where 0.0.0.0/0 goes.

Game time

Subnet builder

Open it on the course page

The two doors

Internet Gateway

Two ways, either side can start. One per VPC, free

NAT gateway

A one-way exit in a public subnet. Private servers go out, nothing comes in

The private API still needs Docker, python:3.12-slim and OS updates. A way out that isn't a way in.

Three trips through Puff's network

  • A visitorInternet Gateway, then the ALB, then the API, then the database
  • A downloadAPI, then NAT gateway, then Internet Gateway, then Docker Hub, and the reply comes back
  • A strangerStopped. The API has no public IP, and its subnet has no way in
$32 a month

A NAT gateway doing nothing, in us-east-1. Plus $0.045 per GB. It keeps charging while you sleep.

Skip the NAT, give the API a public IP and a strict security group. Less safe?

What happens the day someone edits that rule by mistake?

Two firewalls

Security group Network ACL
Applies toOne server's network cardA whole subnet
MemoryRemembers, replies go out by themselvesNone, replies need their own rule
RulesAllow onlyAllow and deny
Reads rulesAll at once, any match lets you inIn number order, first match wins
When you use itEvery dayRarely, to block one IP range

Security groups do 95% of the work. Leave NACLs at their default.

Puff's chain, read it from the bottom

Security group Inbound Source
alb-sgTCP 800.0.0.0/0
app-sgTCP 80alb-sg (on Floci: 172.17.0.0/16)
db-sgTCP 5432app-sg

The best rules don't mention IPs. A stranger can only reach port 80 on the ALB.

Your private app reaches the internet but not your database, same VPC. Where do you look?

Three places, in order.

Game time

The bouncer

Open it on the course page

In a data center

In AWS In a data center
A slice of networkSubnetVLAN on physical switches
The firewallSecurity groupA firewall appliance
The public partPublic subnetThe DMZ
The front doorLoad balancerA hardware box, F5 is the classic
Two sites talkPeering, VPNA leased line or MPLS
Changing a ruleAn API callA ticket to the network team

Same ideas turned into software: SDN. The network becomes an API, and you just built one.

$22 for nothing

500 GB of backups to S3 through the NAT, every month. Add the S3 gateway endpoint and that line drops to zero.

A private path to AWS

Gateway endpoint

S3 and DynamoDB only. A line in the route table, free

Interface endpoint

Most other services. A network card in your subnet, billed per hour and per GB

Four ways to link networks, small to big

  • VPC peeringTwo VPCs, free to set up. It doesn't chain: A to B, B to C, A still can't reach C
  • Transit GatewayA hub every VPC and VPN connects to once, like a roundabout
  • Site-to-Site VPNAn encrypted tunnel over the internet to an office. Up in an hour
  • Direct ConnectA private physical cable from a data center into AWS. Takes weeks

Which one, when

Situation Use Why
Two or three VPCs need to talkVPC peeringSimple and free
Ten VPCs across accounts, plus an officeTransit GatewayOne connection per network, one place for routing
Office needs AWS this weekSite-to-Site VPNFast, encrypted, cheap
Terabytes a day, steady speedDirect Connect, VPN as backupPredictable speed, cheaper at volume

None of them works with overlapping ranges. The IP plan keeps all four open.

45

Peering connections for ten VPCs that all talk. A Transit Gateway does it with ten attachments.

An analytics VPC needs your database, and an office needs both. What do you pick?

And which choice from today could make it impossible?

Game time

Connect the networks

Open it on the course page

The load balancer, the only public door

  • ListenersThe port it accepts, like HTTP 80
  • Target groupsThe instances it forwards to, with a health check
  • RulesThey connect the two

ALB or NLB

ALB NLB
UnderstandsWeb traffic, HTTP and HTTPS, layer 7Raw connections, TCP, UDP, TLS, layer 4
Routes byPath, host, header, query stringPort only
AddressA DNS name, IPs behind it changeOne fixed IP per AZ
Pick it forWeb apps and APIs, your appNon-web protocols, fixed IPs to allowlist

Anything that speaks HTTP, start with an ALB.

Game time

Packet trip

Open it on the course page

Hands-on

Project M2: a private network with one front door

✅ ./checks/check.sh M2 all PASS, ./checks/intruder.sh says the app is BLOCKED

Steps on the course page

Game time

Today's quiz

Open it on the course page

The ALB lives in two AZs, your app in one container. What's the weak point?

Everything from today is on the course page.