Expand description
Configuration. Env-first so EdgeGuard drops into any PaaS that injects $PORT
with zero edits; an optional TOML file layers richer policy on top.
Structs§
- Access
Cfg - IP allow/deny lists, matched against the resolved client IP (the same IP rate limiting keys
on — so behind a trusted proxy, set
server.trust_forwarded_forfor this to see the real client). Both lists accept plain IPs (203.0.113.7,::1) and CIDR ranges (10.0.0.0/8,2001:db8::/32).denywins overallow; a non-emptyallowmeans “only these may connect”. Both empty (the default) = allow all. Compiled into acrate::access::AccessPolicy; an unparseable entry fails at startup/reload. - AcmeCfg
- Automatic certificate management (ACME / Let’s Encrypt) via the HTTP-01 challenge. The
obtained certificate is written to
TlsCfg::cert_path/key_pathand served by the TLS listener. Issuance runs at startup only when no certificate exists atcert_path; there is no automatic renewal yet (see docs/ROADMAP.md) — delete the cert/key files and restart to re-issue. - Alerts
Cfg - Outbound alerting (
[alerts]). Whenenabledwith awebhook_url, EdgeGuard POSTs a Slack-compatible alert ({ "text": … }) when a hard-budget’s consumed ratio (used/limit) crossesbudget_consumed_threshold— cost-regression alerting entirely in your own VPC (no SaaS alerting plane to depend on). Fire-and-forget and edge-triggered (one alert per crossing into the alert zone, not one per request). Off by default. A first cut on budget breaches; latency-percentile / error-rate / eval-drift rules follow. - AuthCfg
- Budget
Cfg - One hard budget (
[[llm.budgets]]): a ceiling oflimit(inunit) overwindow, keyed byscope. Enforced fail-closed before the request reaches the upstream. - Config
- Control
Plane Cfg - Managed-mode settings: when
enabled, the edge pulls its policy from a remote control plane (and hot-reloads it), reports metric deltas, and forwards CSP reports. The policy the control plane pushes is the policy subset (auth/ratelimit/validation/headers/waf) — the edge keeps its own localserver/tls. The edge token is a secret, so preferEDGEGUARD_CP_EDGE_TOKEN. - CorsCfg
- Cross-Origin Resource Sharing policy. A drop-in front door commonly sits in front of an app
whose browser frontend is served from a different origin (a separate static host, a
preview URL,
localhost:5173in dev); without CORS thosefetchcalls are blocked by the browser. Whenenabled, EdgeGuard answers preflightOPTIONSrequests itself (before auth — preflights carry no credentials) and adds the matchingAccess-Control-*headers to actual responses. Off by default: opening cross-origin access is a deliberate choice. Compiled into acrate::cors::CorsPolicy. - DlpCfg
- Edge-DLP settings (
[llm.dlp]). Whenmodeis notoff, request and/or response bodies are scanned for PII and secrets; themodedecides what happens on a finding (report / block / redact). Seecrate::dlp. - Headers
Cfg - JwtCfg
- JWT bearer-token verification. Either a symmetric
secret(HS*) or an asymmetric key (RS*/ES*/PS*) supplied as a staticpublic_key_pemor fetched fromjwks_url. - KeyEntry
Cfg - One vault entry (
[[llm.keys]]): a client-facing virtual key mapped to a real provider key and an optional model egress allowlist. The provider key is injected into the upstreamAuthorizationand is never sent back to the client; the client only ever holds the virtual key. - LlmCfg
- LLM token-metering settings (
[llm]). Whenenabled, the proxy parses OpenAI-compatible request/response bodies to count tokens (from the upstream’susageobject) and, for any model listed in[llm.models], the cost. Metering is observe-only: it never blocks or alters traffic. An unmapped model still has its tokens counted (cost is simply omitted). - LogCfg
[log]— what the access log records.- LogShip
Cfg [log.ship]— stream the access log off the box to a collector.- Model
Price - One model’s price, in USD per 1,000,000 tokens (input and output billed separately, matching
provider pricing). Compiled to integer micro-dollars at load (see
crate::llm). - NerCfg
- ML NER settings (
[llm.dlp.ner]). Off by default. Whenenabled, the proxy must be built with--features ner; otherwise startup fails with a clear error rather than running regex-only while the operator believes ML coverage is active. The model is an ONNX token-classification (BIO) NER network run through the pure-Rust [edgeguard_ner] crate. - PerKey
Rate Limit - Per-principal rate limit (keyed by API-key id / JWT subject).
- Rate
Limit Cfg - Route
Rate Limit - A per-route rate-limit override (matched by path prefix).
- Server
Cfg - Telemetry
Cfg - OTLP span emission (
[llm.telemetry]). Whenenabled, the gateway emits one OpenInference/OTLP span per metered LLM request toendpoint(an OTLP/HTTP/v1/tracesreceiver — e.g. evald), carrying the model, per-tier tokens, computed cost, and server-side TTFT/TPOT/latency already attached. Because the proxy sits in the request path, this needs no client SDK and is immune to the import-order / per-framework instrumentor drift that plagues in-process instrumentation. Emission is fire-and-forget — it never blocks or fails the client response. Off by default. - TlsCfg
- TLS termination. When
enabled, EdgeGuard serves HTTPS on the public port using a certificate either loaded fromcert_path/key_pathor obtained automatically via ACME.self_signed_daysandredirect_statusneed non-zero defaults (a zero-day certificate and a0status are both nonsense), soDefaultis written out rather than derived. - Tracing
Cfg [tracing]— one OpenTelemetry SERVER span per proxied request.- Upstream
Route - A per-path-prefix upstream override (a
[[upstreams]]entry). Requests whose path starts withpathare forwarded totargetinstead of the defaultserver.upstream; the longest matching prefix wins. This is deliberately a static prefix map for the common “static frontend +/apibackend” shape — not a gateway: no service discovery, load balancing, health-based routing, or request rewriting (the path is forwarded unchanged). For those, put EdgeGuard behind a real gateway/mesh. - Validation
Cfg - WafCfg
- WAF-lite input inspection (Phase 4 / v2). Screens a request for common attack signatures
before it is forwarded, using built-in heuristic rulesets (SQLi/XSS/path-traversal) plus
any operator-defined deny patterns. Disabled by default — these are heuristics, so the
intended rollout is
report(log + count matches without blocking) until the operator is confident, thenblock(return403). Compiled into acrate::waf::WafEngine. - WafRule
- A single operator-defined WAF deny pattern (a
[[waf.rules]]entry).
Functions§
- parse_
duration - Parse a timeout like “30s”, “500ms”, “2m”, or a bare number of seconds (“45”). “0” yields a zero duration, which callers treat as “disabled”.
- parse_
rate - Parse a rate like “60/min” into (count, period).
- parse_
size - Parse a human size like “2MiB”, “512KB”, “1048576” into bytes.