Load balancer security
medium 26 minA load balancer is the front gate of a system.
See it run
Watch what the gate can read, what it refuses, and what must be stopped further out.
Operations
TLS termination
TLS ends at the balancer, which forwards plain HTTP.
Step 1 of 3
TLS arrives
The visitor opens TLS to the balancer, which shows the certificate.
Step 1: TLS arrives
def on_connect(conn): tls = server_side(conn, certificate, min="1.2") request = read_http(tls) check(request) forward_http(request)- Can inspect
- Yes
- Inside traffic
- Plain HTTP
Name the cost: inside traffic can be read by anyone on that network.
In the real world
The same load balancer security doing real jobs. Pick one and step through it.
A server with a public address lets traffic skip every check.
Step 1 of 2
Two ways in
The balancer checks its traffic, but Server 3 is also public.
Step 1: Two ways in
Common mistakes
The bugs interviewers watch for, with the fix beside each.
Believing a header from outside
criticalA new value on every request escapes block lists and limits.
Wrongip = headers["X-Forwarded-For"]Rightip = peer if peer not in trusted else rightmost_untrusted(headers)Reading headers before TLS ends
majorThey are still encrypted. Only the connection's address is known.
Wronglimit(header_ip); terminate_tls()Rightlimit(peer); terminate_tls(); limit(client)A broad rule that blocks at once
majorHonest text matches too, and customers are refused.
Wrongrule.action = "block" # day oneRightrule.action = "count" # then tune, then blockLeaving permission to the gate
criticalThe balancer does not know who owns which invoice.
Wrongreturn invoices[id]Rightif invoices[id].owner != user: return 404return invoices[id]
Interview tips
How to explain it
- First gate, not the only lock.
- Castle: moat, gate, guard, list, sign.
Order of checks
- Address and connection.
- End TLS.
- Limit, firewall, clean headers, forward.
Choose where TLS ends
- Terminate: simplest.
- Pass through: no reading.
- Re-encrypt: inspect and protect inside.
Prepare for floods
- Upstream filtering.
- Hide the origin.
- Know what to switch off.