Skip to content

HTTPS reverse proxy with automatic certificates: services.edge (#6) - #78

Merged
Cd1s merged 1 commit into
mainfrom
feat/edge-reverse-proxy
Sep 26, 2026
Merged

Cd1s merged 1 commit into
mainfrom
feat/edge-reverse-proxy

Conversation

@Cd1s

@Cd1s Cd1s commented Sep 26, 2026

Copy link
Copy Markdown
Owner

What

services.edge, off by default: an HTTPS reverse proxy with Let's Encrypt certificates obtained over DNS-01 (Cloudflare). It is the built-in replacement for lucky's "443 + SSL" proxy.

  • mr edge serve (OpenRC mr-edge)
    • Runs as user mr-edge with only CAP_NET_BIND_SERVICE; reads only gen/edge.json and its certificates.
    • TLS 1.2+, HTTP/2 and HTTP/1.1. The certificate is chosen by SNI; an unknown name fails the handshake.
    • A Host that differs from the SNI name gets 421. X-Forwarded-* headers come from the connection.
    • WebSocket upgrades pass through.
    • Limits: 512 connections, 10 s handshake and header timeouts.
  • LAN vs WAN is decided by the listener, not by address lists. With open, nftables redirects the WANs' port to an internal listener, and only redirected traffic reaches it. So allow: [lan] cannot be spoofed from outside, and a firewall.open of the same port is refused.
  • mr edge renew: ACME (RFC 8555, standard library only) with DNS-01 through the DDNS Cloudflare client.
    • Waits until the TXT record is visible at the zone's authoritative servers, and always removes the records afterwards.
    • Renews when a third of the lifetime is left. Failed automatic runs back off from 1 h up to 24 h.
    • Optional wildcard certificates per domain.
  • Status and safety
    • mr edge status, API sys.edge, mr status, a certs check in mr doctor, cert events, and a card on the 服务 page.
    • The guard's never_expose also covers routes to the router's own SSH, web UI and DNS ports.
    • Any services.edge change is rated high risk.
  • Docs: docs/modules/sys.md (反向代理, and 从 lucky 迁移).

Not included: port 80 and an HTTP→HTTPS redirect, basic auth per route, and the P3 items (wan_port, ARI, CNAME delegation).

Verification

  • Go tests:
    • SNI routing, HTTP/2, 421, allow lists on both listeners, WebSocket, certificate reload;
    • a full ACME flow against an in-process RFC 8555 server that verifies every JWS;
    • bad-nonce retry, backoff, renewal timing;
    • no secret in state, status or events; no symlink or FIFO is followed in the service user's directory.
  • tools/ci.d/sys-edge.sh:
    • the real process in network namespaces;
    • the WAN side through the rendered nft lines, over IPv4 and IPv6;
    • hairpin traffic from the LAN counts as LAN.
  • Interop with Pebble 2.10.1 (Let's Encrypt's test CA): a new account, a wildcard order with DNS-01, finalize and the chain, then two forced renewals on the same account. All issued.
  • Memory: idle 15 MB RSS (5 MB anonymous); 29 MB after 200 concurrent TLS clients × 20 requests.
  • Binary size: +1.13 MiB, almost all of it Go's HTTP/2 and TLS server code.
  • sh tools/ci.sh: ALL CHECKS PASSED.

Closes #6

https://claude.ai/code/session_01HWeUjo1dmS7gBkCYHrVjCr

…ge (DNS-01)

The built-in replacement for lucky's "443 + SSL" reverse proxy, off by default.

- `mr edge serve` (OpenRC mr-edge, user mr-edge + CAP_NET_BIND_SERVICE, GOMEMLIMIT 24 MiB): TLS 1.2+,
  HTTP/2 and HTTP/1.1, certificate by SNI (unknown names fail the handshake), Host must match SNI
  (421), httputil.ReverseProxy with X-Forwarded-* from the connection, WebSocket, 512 connections,
  10 s handshake / header timeouts. Reads only gen/edge.json and its certificates.
- LAN vs WAN by listener: with `open`, nftables redirects the WANs' port to an internal listener and
  only redirected traffic reaches it, so `allow: [lan]` cannot be spoofed from outside.
- `mr edge renew`: ACME (RFC 8555, stdlib only) with DNS-01 through the DDNS Cloudflare client; waits
  for the TXT at the authoritative servers, always cleans up; renews at a third of the lifetime,
  failed automatic runs back off 1 h to 24 h; wildcard certificates per domain.
- Status: `mr edge status`, API `sys.edge`, `mr status`, a doctor `certs` check, `cert` events, a
  服务 card; the guard's never_expose covers routes to the router's own SSH / web UI / DNS.

Verification: Go tests (routing, allow lists on both listeners, WebSocket, reload, a full ACME flow
against an in-process RFC 8555 server, backoff, no secret in state or events); tools/ci.d/sys-edge.sh
with the real process in network namespaces through the rendered nft lines (IPv4 / IPv6), memory:
idle 15 MB RSS (5 MB anonymous), 29 MB after 200 concurrent TLS clients x 20 requests. Interop with
Pebble 2.10.1 (Let's Encrypt's test CA): account, wildcard order, DNS-01, finalize, chain, two forced
renewals. Binary +1.13 MiB (Go's HTTP/2 + TLS server).

Closes #6

Claude-Session: https://claude.ai/code/session_01HWeUjo1dmS7gBkCYHrVjCr
@Cd1s
Cd1s merged commit f83b780 into main Sep 26, 2026
2 checks passed
@Cd1s
Cd1s deleted the feat/edge-reverse-proxy branch September 26, 2026 02:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

提议:内置 HTTPS 反向代理 + 自动证书(mr-edge,DNS-01)

1 participant