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.
This commit is contained in:
1 parent
5bafd000c8
commit
b6619d30de
6 files changed
+227
-20
No files matched your search
@@ -70,7 +70,9 @@ Operational hardening:
|
||||
- Graceful shutdown on **SIGINT and SIGTERM**; the engine is signalled without
|
||||
blocking on an in-flight request.
|
||||
- Configurable startup and silence-watchdog timeouts.
|
||||
- A warning when binding a non-loopback address (the API has no authentication).
|
||||
- Optional **API key** auth (`Authorization: Bearer <key>` or `x-api-key`) and a
|
||||
**Host allowlist** (`allowed_hosts`, DNS-rebinding protection); `/health` stays
|
||||
open. A warning is logged when binding a non-loopback address with no key set.
|
||||
- Blocking image I/O runs off the async event loop; temp files are cleaned on every
|
||||
exit path; image fetches have a timeout, a size cap and a basic SSRF guard.
|
||||
|
||||
@@ -113,20 +115,20 @@ uses `tracing`; set `RUST_LOG` to control verbosity (default `info`).
|
||||
|
||||
The config is the same JSON the other Strata tools use. Keys acted on here include
|
||||
`exe`, `args`, `cwd`, `tokenizer`, `model_name`, `host`, `port`, `reasoning_effort`,
|
||||
`sampling`, and the optional `startup_timeout_secs` / `silence_timeout_secs`.
|
||||
Everything else (`arch`, `mcp_servers`, `cors_origins`, `allowed_hosts`, …) is
|
||||
preserved untouched and reported as ignored — unknown keys never break startup.
|
||||
`sampling`, `api_key`, `allowed_hosts`, and the optional `startup_timeout_secs` /
|
||||
`silence_timeout_secs`. Everything else (`arch`, `mcp_servers`, `cors_origins`, …)
|
||||
is preserved untouched and reported as ignored — unknown keys never break startup.
|
||||
|
||||
## Status
|
||||
|
||||
Working and tested (76 tests, plus 2 real-file tests run on demand). Text, images
|
||||
Working and tested (80 tests, plus 2 real-file tests run on demand). Text, images
|
||||
and the full client-side tool loop have been validated live against the real
|
||||
Inkling engine.
|
||||
|
||||
Not yet implemented (honest gaps): forced `tool_choice` (`required` / named function
|
||||
returns a clear 400), multi-slot batching, logprobs / structured output, automatic
|
||||
engine restart after a crash, an API key / `allowed_hosts` enforcement, a full
|
||||
SSRF guard against DNS rebinding, and the Anthropic / Responses native endpoints.
|
||||
engine restart after a crash, a full SSRF guard against DNS rebinding, and the
|
||||
Anthropic / Responses native endpoints.
|
||||
|
||||
## License and credits
|
||||
|
||||
|
||||
Reference in new issue
Block a user