Commit Graph
2 Commits
Author SHA1 Message Date
adm b6619d30de Add optional API key auth and allowed_hosts enforcement
- AuthConfig (api_key, allowed_hosts) read from the shared config; router_with_auth
  applies an axum middleware before any handler.
- Host not in allowlist -> 403 host_not_allowed; missing/wrong key -> 401
  invalid_api_key (accepts Authorization: Bearer <key> or x-api-key); /health open.
- router() stays the open default: backward compatible (no key, wildcard hosts).
- The non-loopback bind warning now fires only when no api_key is configured.
- README updated (auth is a feature, no longer a gap).

4 new tests; 80 green + 2 real-file ignored; clippy clean; cargo fmt applied.
2026-11-24 18:48:05 +01:00
adm 5bafd000c8 Respond to code review: sampling defaults, abort race, hardening + README
Bug fixes (from review/README.md):
- Apply config sampling defaults field-by-field, so an absent temperature no
  longer means greedy; expose top_k/min_p/repetition_penalty on ChatRequest;
  top_k=0 is "disabled" (-> 64), not greedy.
- Fix cross-request abort race: Engine::request_stop() sets the cancel flag only;
  the owning generate loop does STOP+drain itself, instead of a spawned abort()
  that could hit a later request holding the lock.
- Initialize tracing-subscriber (RUST_LOG, default info); events were dropped.
- TempFilesGuard removes materialized images on every exit path (error/panic/drop);
  build_prompt runs in spawn_blocking off the async worker; ureq image fetch gets a
  15s timeout, a 32MB cap and a basic SSRF guard (literal loopback/private hosts).
- Non-blocking shutdown (STOP+QUIT without taking the request lock first) and a
  bounded drain_to_done that marks the engine dead on timeout.

Operational hardening:
- Graceful shutdown on SIGTERM as well as SIGINT.
- Warn when binding a non-loopback address (no auth, allowed_hosts not enforced).
- Configurable startup/silence timeouts (optional config keys, default 600s).

Docs:
- Add README.md (English): what strata-ctl is, why Rust for stable server use,
  architecture, usage, honest status, and credits to Strata / Niko1221.

76 tests green + 2 real-file ignored; clippy clean; cargo fmt applied.
Deferred (heavy): automatic engine restart after a crash.
2026-11-24 18:42:56 +01:00