# Under the hood

How the site front on your own hosts passes HTTPS through by SNI, routes HTTP by host, jumps SSH to a machine and wakes a suspended one, what we chose it over, and what is not measured yet.

On a site of your own hosts, every instance with a public hostname is reached through one front
per site: a platform-owned VM running `front-rs`, a small Rust program we wrote. It never
terminates TLS. It reads the server name from the first TLS record, splices the connection to the
machine that owns that name, and otherwise does only what a proxy must: route plain HTTP by host,
relay SSH to port 22 of a machine you may reach, and hold a connection while a suspended machine
wakes. Every decision comes from a document the control plane renders; the front itself knows
nothing.

## What runs where

```text
internet ─▶ host public IP :80 / :443 / :2222
              │ forwarded by the host's network
              ▼
        front VM (one per site) running front-rs
          :443  ClientHello SNI, splice TCP   ─▶ machine :443
          :80   Host route, "waking up" page  ─▶ machine :80
          :2222 SSH jump, direct-tcpip to :22 ─▶ machine :22
          a NIC in every organization's site network
          ▲ document every 2 s · stats every 10 s · wake
        control plane: routes, machines, keys, hold times
```

The front pulls its document with an ETag every 2 s, keeps the last good copy on disk, does not
listen until it has one, and treats an unknown field as an error, not a guess. A route matches an
exact host first, then `*.name`. On 443 it reads at most one TLS record for the SNI and then copies
bytes both ways, so each machine keeps and renews its own certificate and the front holds no key.
On 80 it reads the request head (16 KiB at most) for `Host`. Every 10 s it reports per-machine
connection counts, and an open connection counts as use, so a machine with traffic is never
suspended as idle.

The machine's state decides what a connection gets: running is relayed; pending or rebooting is
held; stopped or suspended with an idle policy triggers a wake and is held, 60 s for TLS, 30 s for
HTTP, 120 s for SSH. The TLS hold was raised from 30 s after a 32 GiB machine took 25 to 29 s to
wake. The same front fronts the platform's function hosts and pool hosts on the site, which never
sleep, take no SSH and terminate TLS themselves.

The SSH jump is `ssh -J jump@<site front>:2222 user@<machine>`. The front's SSH server (russh)
allows one thing: a `direct-tcpip` channel to port 22 of a machine the presenting key may reach,
meaning an IAM user allowed `ec2:StartSession` on it, or the machine's launch key. There is no
shell; organization isolation is exactly that check. A failed authentication is delayed 1 s, an
idle session closes after an hour, and the host key is generated once and kept.

## What we built, and what we did not

The front is 1,584 lines of Rust on tokio, russh and reqwest. The plan left HAProxy or a small
proxy of our own open; what decided it was our existing edge. `lb-proxy-rs`, the load balancer's
proxy, always terminates TLS (it accepts before reading the SNI), its TCP listeners have one pool
each and no SNI peek, and it has no SSH. Adding SNI passthrough, an SSH server, wake holds and
per-route counters, about 1,300 lines, would have widened a strict contract that every load
balancer fleet must accept. So the front is a separate binary on the fleet's machinery: the same
provisioning of a site node joined to each organization's site network, the same node tokens, the
ETag document pull with a last-good copy, a binary shipped with a checksum, stats posted back. No
written evaluation of HAProxy, Caddy, Traefik or sshd for this role exists; the recorded reason is
the contract, not a shortcoming of those tools.

Around it: one front VM per site through the host's own network forward, rather than a port per
machine or a bought address block; SSH through a jump with your IAM keys, so real `ssh`, `scp`,
port forwarding and editors' remote modes work, instead of a terminal relayed through the control
plane; a machine with a public hostname is a plain instance plus a name and an idle policy, not a
new service; idle is counted from the host (no connection through the front, low guest CPU and
network) without an agent in the guest; suspend is a stateful stop, with a cold stop as fallback.

## Benchmarks

**How to rerun these.** The `curl` and `ssh` lines below repeat the wake and jump rows. The
stateful stop / start and idle-suspend rows were observed by hand; there is no script.

There is no throughput, latency-overhead or connection-count benchmark of the front yet. What was
measured, on 2026-11-18 in our test installation on our own hosts (the front on one host, a machine
on another), is the behaviour it exists for (raw output not kept):

| What                                                           | Measured                                                                                                                                  |
| -------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------- |
| Cold wake of a suspended machine over HTTPS, through the front | 29 s, inside the 30 s hold of the time                                                                                                    |
| Stateful stop / start, 32 GiB machine, about 5 GiB used        | 16.9 s / 22.6 s; tmux, containers and process uptime survived                                                                             |
| Wake of a 32 GiB machine, as recorded when the hold was set    | 25–29 s, the basis of the 60 s TLS hold                                                                                                   |
| Idle suspend with a 30 min policy                              | suspended 31 min after last use                                                                                                           |
| SSH through the jump                                           | `ssh`, `scp`, `-L`, `-D`, three multiplexed sessions, 50 MB streamed; an unknown key refused at the jump, a known key refused off port 22 |

```sh
time curl -s -o /dev/null -w '%{http_code}\n' https://<public hostname>/
ssh -J jump@<site front>:2222 user@<public hostname>
```

Run the `curl` against a machine that has suspended to time a wake from the client's side. The
wake numbers include the guest's own resume, not only the front's hold.

## Known limits

- One front per site is one point of failure per site.
- A TLS client cannot be shown a waking page: port 443 holds up to 60 s, then closes, and the
  client retries. Port 80 gets the page.
- Anyone who knows an exact hostname can wake its machine by connecting; wakes are rate-limited
  per machine.
- A stateful-stopped machine resumes only on the host it stopped on, which needs disk for the
  saved memory (the root disk's state size is memory plus 1 GiB).
- Isolation between two organizations' keys is covered by the front's tests, not yet by a run with
  a real second organization.

## Related

- [Instances on your own hosts](own-hosts.md)
- [What runs on your machines](what-runs-on-your-machines.md)
- [Instance lifecycle](instance-lifecycle.md)
- [Under the hood: Apps and pooled hosting](/docs/deploy/guide/under-the-hood)
