AlgoViz

Load balancer security

medium 26 min

A 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

Our systemTLSVisitorOther trafficLoad balancerhas certificateServer 1HTTPServer 2HTTPServer 3HTTP

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

Our systemTLSVisitorOther trafficLoad balancerchecks allServer 1Server 3 is publicServer 2Server 3 is publicServer 3Server 3 is public

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

    critical

    A new value on every request escapes block lists and limits.

    Wrong
    ip = headers["X-Forwarded-For"]
    Right
    ip = peer if peer not in trusted else rightmost_untrusted(headers)
  • Reading headers before TLS ends

    major

    They are still encrypted. Only the connection's address is known.

    Wrong
    limit(header_ip); terminate_tls()
    Right
    limit(peer); terminate_tls(); limit(client)
  • A broad rule that blocks at once

    major

    Honest text matches too, and customers are refused.

    Wrong
    rule.action = "block"   # day one
    Right
    rule.action = "count"   # then tune, then block
  • Leaving permission to the gate

    critical

    The balancer does not know who owns which invoice.

    Wrong
    return invoices[id]
    Right
    if 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.