Atlas HTTP proxy

How a site name reaches its VM

DNS, OpenResty, a route map, and WG Mesh in one region

The browser knows a name. Atlas must find a VM.

  • A browser asks for erp.par-1.example.com
  • The site runs on a tenant VM, on one Metal host
  • The VM can move to another host
  • Proxy nodes can fail

The proxy connects the name to the VM, even when a node fails.

Three questions, three answers

A browser asks DNS which proxy node to use, then sends HTTPS to that node. The node route map selects the site VM. WG Mesh carries the request to the Metal host that runs the VM. Atlas writes DNS, Central and Atlas write routes, and WG Mesh learns host locations.

A VM move changes no route

  • Each VM has one private IPv6 address in the region: its mesh address
  • A route maps a site name to a mesh address, such as erp → fdaa:1:0:2::b
  • The mesh address stays the same when the VM moves to another host
  • WG Mesh finds the new host

A route changes only when a site moves to another VM.

One node, two programs

One proxy node runs OpenResty and the control daemon. Public clients reach OpenResty, which reads the route maps in shared memory for each request and sends traffic to site VMs. Central and Atlas send route changes to the control daemon. The daemon writes the maps through admin.sock, saves cluster-state.json, and replicates changes with peer nodes.

1 to 5 nodes per region · OpenResty: data plane · control daemon: control plane

Who owns what

Part Owns Does not own
Atlas app Proxy VMs, DNS, health checks, wildcard certificate, passwords, peer membership, Cargo routes Tenant site routes
Central Tenant site and custom-domain routes Proxy nodes
OpenResty Public traffic, from the local maps Map changes
Control daemon Route validation, saved snapshot, replication Request forwarding
WG Mesh Delivery to the VM's current host Site names

Five parts

  1. One request: how a site request reaches its VM
  2. Other names: custom domains and auto-proxy names
  3. Route changes: how the leader copies a change to every node
  4. Failures: health checks, partial writes, and recovery
  5. Operation: add a node, look at a node, find the code
1 · One request

DNS returns a proxy node

The browser asks DNS for erp.par-1.example.com. Route 53 answers with the IPv4 address of one healthy proxy node.

*.par-1.example.com → CNAME proxy.par-1.example.com → one A record per healthy node

1 · One request

OpenResty ends TLS and reads its map

The browser sends HTTPS to the proxy node. OpenResty ends TLS with the wildcard certificate and reads erp in its local site map: fdaa:1:0:2::b.

One wildcard certificate for every site · map lookup in local memory

1 · One request

WG Mesh carries HTTP to the VM

OpenResty sends plain HTTP to port 80 on fdaa:1:0:2::b. WG Mesh carries it to the Metal host that runs the VM.

Plain HTTP to port 80 · WireGuard encrypts it between hosts

1 · One request

How OpenResty finds the site key

The name erp.par-1.example.com. A brace marks erp as the site key and par-1.example.com as the wildcard zone from /var/lib/nginx/region. The site map gives erp → fdaa:1:0:2::b.

Only one label below the zone · a site address of - returns 503

1 · One request

No cluster call on the request path

  • OpenResty reads its own copy of the maps
  • It does not ask the control daemon or other nodes
  • So a node that loses its peers still serves all the routes that it knows

Keep this when you change the data plane. A write outage is not a traffic outage.

2 · Other names

Each kind of name has its own path

Name Example TLS ends at Route from
Site erp.par-1.example.com Proxy, wildcard certificate Site map
Custom domain www.customer.com Site VM, its own certificate Domain map, by SNI
Auto-proxy site-lpc8lqa.par-1.example.com Proxy, wildcard certificate The name itself
Control proxy.par-1.example.com Proxy, wildcard certificate Control daemon, 127.0.0.1:9000

Plain HTTP on port 80 uses the same maps · the site API reserves proxy and proxy-*

2 · Other names

Custom domain: the proxy does not decrypt

The browser sends HTTPS for www.customer.com. OpenResty reads only the SNI name, finds the VM in its SNI map, and sends the unchanged TLS stream to port 443 on the VM with a PROXY protocol v2 header that carries the client address. The VM holds the certificate.

SNI: the name in the TLS hello · PROXY protocol v2: a short header with the client address

2 · Other names

Custom domain edge cases

  • A TLS connection with no SNI: OpenResty drops it
  • An unknown custom domain: a placeholder certificate and an error page
  • An HTTP-01 challenge for a custom domain goes to the VM on port 80
  • A domain in the wildcard zone is refused by the domains API (409)

HTTP and stream workers keep separate maps · the SNI bridge keeps them the same

2 · Other names

Why auto-proxy names exist

  • A new VM needs a URL before anyone saves a site route
  • The name carries the tenant and VM numbers
  • OpenResty calculates the mesh address from the name
  • No cluster write, no stored route
2 · Other names

The name is the address

The name site-lpc8lqa.par-1.example.com has the prefix site-, the base-36 label lpc8lqa, and the zone. The label decodes to 47244640258, which is 11 shifted left by 32 bits, or tenant 2. OpenResty puts the numbers into the mesh address fdaa:1:0:2::b: the region prefix from config, tenant 2, and VM 11.

2 · Other names

Auto-proxy rules

  • Only configured prefixes, such as site- or *-vm-
  • A canonical lowercase label: at most 19 digits, no leading zero, at most 96 bits
  • The control daemon reserves these names, so a site route cannot hide one
  • The name gives identity, not location. WG Mesh still finds the host.

A route is not access. Tenant and guest firewall rules still apply.

3 · Route changes

Route changes

Where the map comes from

3 · Route changes

Any node accepts, the follower forwards

Central sends PATCH /v1/sites/erp to proxy-001, a follower. The follower forwards the change to proxy-002, the leader.

One elected leader orders changes · forward timeout: 1500 ms

3 · Route changes

The leader applies, then sends to all peers

The leader applies the change, moves the generation from 41 to 42, and sends the change to proxy-003, proxy-004, and proxy-005 at the same time.

The generation counts changes · peer request timeout: 200 ms

3 · Route changes

Enough acknowledgements, then success

proxy-003 and proxy-004 acknowledge. With the leader that is 3 of 5, so the leader returns 200 with the new generation through the follower. proxy-005 is late and catches up later.

The late node installs the leader's snapshot on a later heartbeat

3 · Route changes

How many is enough

Nodes Acknowledgements for a write Nodes that can be down
1 1 0
2 2 0
3 3 0
4 3 1
5 3 2

The count includes the leader · 3 nodes elect with 2 votes, but a write needs all 3

3 · Route changes

Leader election

  • The leader sends a heartbeat every 100 ms
  • A follower that hears nothing for 300 to 450 ms (random) starts an election
  • A candidate needs a majority of votes
  • Each voter compares the candidate's term and generation with its own

A leader that sees a higher term becomes a follower

3 · Route changes

Send a route change

curl -X PATCH \
  -H "Authorization: Bearer $TOKEN" \
  -H 'Content-Type: application/json' \
  -d '{"address":"fdaa:1:0:2::c"}' \
  https://proxy.par-1.example.com/v1/sites/erp
  • $TOKEN is the regional proxy password or a signed JWT
  • A JWT scope claim selects the maps, such as site:*. A constraints claim can limit the names.
  • Success returns X-Atlas-Proxy-Generation

API reference: GET /docs on each node

4 · Failures

Serving and changing need different things

Situation Live traffic Route changes
A node stops Other nodes serve. Route 53 stops returning it. A new leader if needed. Writes need enough nodes.
A node loses its peers It serves the routes in its local map. It cannot confirm a write alone.
A node returns It loads its saved map, then gets a newer snapshot. It takes part after it catches up.

Serving needs one healthy node · changing needs a leader and enough acknowledgements

4 · Failures

Route 53 checks each node

Route 53 health checkers send HTTPS GET /healthz to each proxy node every 30 seconds. Each node answers 204.

Atlas creates one health check per node · proxy.<zone> has one multivalue A record per node

4 · Failures

A node stops answering

proxy-002 stops answering. The checkers get no answer twice, which takes about 60 seconds.

Unhealthy after 2 failed checks in a row

4 · Failures

Route 53 stops returning it

Route 53 marks proxy-002 unhealthy and stops returning 203.0.113.12 in the answer for proxy.par-1.example.com. Resolvers can keep the old answer for up to 120 seconds.

New clients go to healthy nodes · cached answers can last up to 120 s more

4 · Failures

Happy Eyeballs: try the next address

The browser has a cached answer with .11, .12, and .13. It sends a TCP SYN to proxy-002 at 203.0.113.12, which is down. After 250 ms with no reply, it sends a TCP SYN to proxy-001 at 203.0.113.11 and connects. This does not help when a node accepts TCP and then fails.

Happy Eyeballs (RFC 8305): start the next address when one stalls

4 · Failures

The node comes back

proxy-002 answers 204 on 2 checks again. Route 53 puts 203.0.113.12 back in the answer.

Healthy after 2 good checks in a row

4 · Failures

What /healthz checks

Check Catches
The control daemon has loaded its state A daemon that is still starting
OpenResty answers on its admin socket OpenResty is down
OpenResty holds the routes of the saved snapshot OpenResty restarted with empty maps
Not checked: the leader A node without a write quorum keeps its traffic
  • Through OpenResty on port 443: it also tests TLS and the certificate
  • All nodes unhealthy: Route 53 returns all records
4 · Failures

A change reaches 2 of 3 nodes

A 3-node region with proxy-003 down. Central sends a route change to proxy-001, the leader. The leader and proxy-002 apply generation 42. proxy-003 does not answer.

3 nodes need 3 acknowledgements · proxy-003 is down

4 · Failures

The leader returns 503 and keeps the change

proxy-002 acknowledges, but 2 of 3 is not enough. The leader returns 503. The leader and proxy-002 keep generation 42 and do not roll back.

No rollback · a 503 does not prove that the route stayed the same

4 · Failures

Send the same change again

proxy-003 comes back. A leader heartbeat makes it install the newest snapshot. Central sends the same change again, and the leader returns 200 after 3 of 3 acknowledgements.

Every change is safe to repeat · replace: full map · update: one key · delete: absent is fine

4 · Failures

A node that starts

  1. Load /var/lib/nginx/cluster-state.json and apply it to OpenResty
  2. Ask each configured peer for its status
  3. Download the snapshot of the peer with the highest generation, if it is newer
  4. /readyz returns 204 after the node syncs and knows a leader

Atlas never sends route state to a node · the peers do

5 · Operation

Atlas adds a node in six steps

  1. Publish proxy-NNN DNS for the VM's public IPv4 address
  2. Install the proxy package over root SSH
  3. Send configuration, then update the membership of Active peers
  4. Wait for /readyz
  5. Create the /healthz check, then publish regional DNS
  6. Mark the Proxy Server Active, then update Active nodes again

A failed step sets the Failure field, such as control-readiness · fix the cause, then Re-provision

5 · Operation

DNS names and health routes

Name Record TTL
proxy-NNN.<zone> A record for one node: peers and health checks 3600 s
proxy.<zone> Multivalue A: one record for each healthy node 120 s
*.<zone> CNAME to proxy.<zone> 3600 s
Route Checks Used by
/healthz The node can serve traffic Route 53, all the time
/readyz Synced, knows a leader, OpenResty ready Atlas, before DNS publication

/readyz gates DNS publication · /healthz keeps the node in DNS after that

5 · Operation

Look at a node

sudo systemctl status openresty.service atlas-proxy-control.service
journalctl -u atlas-proxy-control.service -f

curl -H "Authorization: Bearer $TOKEN" \
  https://proxy-002.par-1.example.com/v1/cluster/status
  • cluster/status gives the node ID, role, leader, term, generation, and readiness
  • It needs a token with the * scope, or the proxy password

Do not edit the files in /var/lib/nginx while the services run

5 · Operation

Where the code lives

Path Holds
services/http-proxy/nginx/lua/http/router.lua Site request routing
services/http-proxy/nginx/lua/http/auto_proxy.lua Auto-proxy name decoding
services/http-proxy/nginx/lua/stream/sni_router.lua Custom-domain TLS pass-through
services/http-proxy/control/proxy_control/cluster.py Election, replication, recovery
services/http-proxy/control/proxy_control/main.py Control API routes
services/http-proxy/control/proxy_control/auth.py Passwords and tokens
atlas/service/core/proxy/provisioning.py Node setup, readiness, DNS, health checks
atlas/atlas/core/dns_providers/route53.py Route 53 records and health checks

Tests: services/http-proxy/control/tests and services/http-proxy/tests

Read more

HTTP proxy overview · OpenResty paths · High availability

Control daemon · Provisioning · Route 53 multivalue answers · RFC 8305 · WG Mesh deck

frappe/atlas · all names and addresses are examples