Learn

Architecture & pattern guides

Read the idea, build it on a Grid, prove it in a challenge. Short, practical guides — illustrated with RodGrid's own nodes — on system design, design patterns, flow modeling, and how to get the most out of the app.

All articles

Network topology: VPCs, NAT, VPN & bastions

Lay out a private network so the internet reaches only the load balancer: public and private subnets, route tables, security groups and network ACLs, outbound calls through NAT with egress filtering, VPN and peering scoped to what is needed, and operator access without an open SSH port.

One line on page one

A group of six clinics runs its patient records on a handful of cloud servers: a web app for doctors and front-desk staff, an API behind it, a PostgreSQL database, and a nightly job that sends lab orders to an outside laboratory. The first penetration test comes back with the line that matters on page one: the database's public address, followed by 5432/tcp open postgresql.

The database had been given a public address during the move to the cloud, two years earlier, so that a developer could load data from home. It was meant to be temporary, and nobody remembered to end it, which is a common way for a temporary exposure to become a breach. Only a password stood between the internet and every patient's record, and the tester's tool had already tried a few thousand.

A stronger password would answer only this one attack. What the clinics need is a network where the database has no address the internet can reach, and where every path that does reach it was drawn on purpose.

A network of your own

A VPC (virtual private cloud) is a logically isolated virtual network you define inside a cloud provider. This design gives it a private IPv4 address range that the internet cannot route to, divided into subnets, smaller ranges that on AWS each sit in one availability zone. Whether a subnet is public or private follows from its route table, the list that says where traffic for each destination goes. On AWS, a public subnet's table sends internet-bound traffic to an internet gateway, and an instance there can have a public address; a private subnet's table has no such route, so nothing on the internet can open a connection straight to its instances, which here have only private addresses.

The clinics' new layout has three tiers:

  • A public subnet holds only the load balancer, which accepts HTTPS from the internet, and the NAT gateway.
  • A private app subnet holds the web app, the API and the lab job.
  • A private data subnet holds PostgreSQL, which now has no public address at all.

Private does not mean unreachable. A private instance is still reachable from anything that has a route to it: the load balancer, the other subnets, every network connected to the VPC. Routes say what can be reached; something else has to say what is allowed.

Rules on each connection

Two layers of rules do that on AWS, and they behave differently enough to matter; other clouds have their own equivalents:

  • A security group is attached to an instance's network interface and lists what may connect, in allow rules only. It is stateful: once a connection is allowed, its replies go back without a rule of their own. A rule can name another group instead of an address, so the database's group allows port 5432 from the API's group, and a new API instance is covered the moment it joins that group.
  • A network ACL is attached to a subnet and holds numbered allow and deny rules, checked in order. It is stateless: every packet is judged on its own, so replies need a rule too, usually for the ephemeral ports clients connect from, and teams keep it as a coarse backstop for the subnet.

For the clinics, the routes take the database off the internet, and its security group takes it out of the web app's reach: a flaw in the web app now gives an attacker the web app's place in the network, and that place no longer includes port 5432. Services still call each other across the private network; proving which service is calling is Service discovery & the mesh, and encrypting those calls is Secrets management & encryption.

Calls that have to leave

The lab job has to reach the laboratory's API over HTTPS, every server needs operating-system updates, and so far a private subnet has no route out. A NAT gateway gives it one: it sits in the public subnet, the private subnets' route tables send internet-bound traffic to it, and it rewrites each outgoing connection to come from its own public address. Replies come back through it; a connection started from the internet finds nothing to reach.

NAT hides the instances; it does not choose where they may go. Say an attacker gets code running on the lab job's server through a vulnerable library: with no egress filtering behind the NAT, that server can exfiltrate data or call out to anything. Egress filtering (security-group rules, an egress firewall or a proxy allow-list) narrows the way out to what the job needs, HTTPS to the laboratory and the update mirrors. Filtering by hostname takes a proxy or a firewall that reads the requested name, since a security group only sees addresses.

The front desks and the billing contractor

Front-desk staff use an admin tool that should never face the internet. A VPN gateway connects the VPC to each clinic's office through an encrypted site-to-site tunnel, usually IPsec, and the billing contractor's own VPC is connected by peering, a private route between two VPCs; peering requires address ranges that do not overlap, and a VPN is far simpler with them. The tempting rule on each link is to allow everything, since the offices are ours and the contractor is trusted. Then a front-desk laptop that opens a malicious attachment is one hop from port 5432, and so is any compromise inside the contractor's network. So each link is scoped to the ports and services it needs: the offices reach the admin tool on 443, the billing VPC one billing endpoint, and neither reaches the data subnet.

A shell without an open door

Engineers still need a shell now and then, to run a migration or look at a stuck job. The classic answer is a bastion host: one hardened machine in the public subnet that accepts SSH only from known addresses, and the only source the private instances accept SSH from. It works, and it concentrates the risk: one bastion host with no MFA and no key rotation is a single target for the whole private network, and whoever holds a departed engineer's old key is one hop from everything. If you run one, require MFA, issue short-lived keys or certificates, and record every session.

The alternative removes the door. With session-manager access, of which AWS Systems Manager Session Manager is one example, an agent on each instance keeps an outbound connection to the provider's management service, and an engineer opens a shell through that service after signing in with their cloud identity. No instance needs an SSH port, so the team closes it and there is none to scan; who may connect is an identity policy, and sessions are logged in one place once logging is turned on. The agent needs its own way out, through the NAT gateway or a private endpoint for that service, so that destination goes on the egress allow-list too.

The second scan

Three months later the testers scan again. The only address that answers belongs to the load balancer, on port 443. The database has no public address to find; from the web app its port is filtered; from the offices it is out of reach; and the one engineer who had to inspect it did so in a recorded session, with no SSH port open anywhere.

The clinics' network, rebuilt

Only the load balancer accepts connections from the internet, and nothing but the API reaches the database.

TipDefault to private. Expose only the load balancer / gateway publicly; operators reach private machines through session-manager access, the bastion or VPN, and services talk to each other over the private network (a service mesh, if you have one). See DNS, proxies & the network edge for the name that points at that load balancer, and Edge protection: WAF, DDoS & defence in depth for what stands in front of it.

One rule per arrow

No Challenge asks for a private network yet, so build the clinics' network on a blank Grid, about ten nodes, with a single rule in mind: every arrow, inside a subnet or across one, carries its port and its source, and a connection you cannot draw that way is not allowed. Held to that, the database ends up with one arrow, from the API, and the lab job's way out has to name the laboratory, because a NAT gateway with no filter behind it lets anything out.

Practice this