Proxy authorization (auth modes)
What we wanted
- Allow running the proxy open for local-only workflows.
- Allow enabling request authentication when exposing the proxy more widely (LAN, shared host, etc.).
- Keep behavior predictable for tools that cannot add auth headers by providing a mode that keeps health checks open.
- Apply changes without restart (hot reload).
What we got
The proxy supports proxy.auth_mode with four modes:
off— no auth required.strict— auth required for all routes.all_except_health— auth required for all routes exceptGET /healthz.auto— derived policy: ifproxy.allow_lan_access=truethenall_except_health, otherwiseoff.
Implementation:
- Config enum and serialization:
src-tauri/src/proxy/config.rsProxyAuthModeinsrc-tauri/src/proxy/config.rs
- Policy resolver (“effective mode”):
src-tauri/src/proxy/security.rsProxySecurityConfig::from_proxy_config(...)insrc-tauri/src/proxy/security.rs
- Request middleware enforcement:
src-tauri/src/proxy/middleware/auth.rsauth_middleware(...)validatesAuthorization: Bearer <proxy.api_key>OPTIONSrequests are allowed (CORS preflight)- In
all_except_health,GET /healthzbypasses auth
Hot reload:
- Config save triggers running server updates in
src-tauri/src/commands/mod.rssave_config(...)callsaxum_server.update_security(&config.proxy).await
Client contract
When auth is enabled, clients should send:
Authorization: Bearer <proxy.api_key>
Notes:
- The proxy API key is not forwarded upstream to providers.
- Health may remain open depending on the selected mode.
Validation
- Set
proxy.auth_mode=all_except_healthandproxy.api_keyin the UI (src/pages/ApiProxy.tsx). - Start the proxy.
- Verify:
GET /healthzsucceeds without auth.- Other endpoints (e.g.
POST /v1/messages) return 401 without auth and succeed with the header.