pingora-edge: a small edge proxy in Rust

· 2 min read

  • Rust
  • Pingora
  • Open source
Long-exposure light trails on a highway at night
Photo by Cris Ovalle on Unsplash

I just published a project I enjoyed building: pingora-edge, a small edge proxy written in Rust. It sits at the front, takes HTTPS traffic for many hostnames and sends each request where it belongs.

It is built on Pingora, the Rust proxy framework from Cloudflare, with BoringSSL for TLS. It runs in production. It's not perfect, but it holds up, and a few ideas in it are worth sharing.

What it does

  • Acts as a reverse proxy, serves static files or redirects, chosen per route.
  • Gets free certificates through ACME (Let's Encrypt or ZeroSSL) and renews them.
  • Adds rate limits, a penalty box, a circuit breaker and Prometheus metrics.

Three ideas I like

Stop bad traffic before TLS. A TLS handshake costs real CPU. So a small Tokio listener reads each ClientHello first and drops junk, floods and repeat offenders before any TLS state exists. Real visitors go straight through.

Certificates on demand. Hostnames listed in a text file get a certificate the first time someone visits. A visitor waits at most 800 ms for it, then gets a temporary certificate while the real one finishes. Names that are not on the list never trigger an order.

Reload all or nothing. A new config is checked first, then applied as a whole or not at all, so a request never sees half of the old config and half of the new one. A --check command lets you test a file before you ship it.

Try it

The docs have a short guide for each part, and a local playground that needs no domain and no certificate authority:

git clone https://github.com/itzngga/pingora-edge
cd pingora-edge
cargo build --release

Then follow the getting started guide. The abuse defence page explains the layers in the order a connection meets them.

Honest limits

  • HTTP-01 only, so no wildcard certificates.
  • One upstream per route, and no load balancing across several backends.
  • Built for Linux first, and the code has not been audited.

So review it before you put it in front of your own site. If you try it or spot a bug, open an issue. I would love to hear what you think.