[10] feat: auth flows and keyring-backed credential storage #37

Merged
OpenCode merged 1 commit from feature/10_auth_secrets into main 2026-10-16 13:28:06 +00:00
Owner

Closes #10

Summary

Auth layer for Open WebUI instances: username/password sign-in → JWT, manual API-key registration as equal path, session restore with typed re-login handling, and libsecret-backed credential storage.

Implementation

Core (crates/core/src/auth.rs):

  • SignInRequest/SignInResponse + SessionUserInfo models (serde defaults, unknown fields ignored)
  • SecretStore trait — Core stays headless; InMemoryStoreHandle for tests
  • sign_in(): POST /api/v1/auths/signin, 400 → AuthError::InvalidCredentials, 429 → Http with body preserved
  • register_api_key(): trims input, rejects empty keys, expires_at None (valid until server says 401)
  • restore_session(): classifies stored secret by "sk-" prefix (JWT vs API key), fetches identity via GET /api/v1/auths/
    • 200 → session enriched; 403 tolerated (API keys can't read /auths/); 401 → session returned WITH credentials = defined re-login path, no crash
  • fetch_identity() for identity display after login
  • Manual Debug impls on AuthSession — tokens never leak into logs

UI (crates/ui/src/secrets.rs):

  • KeyringStore implementing SecretStore via libsecret 0.9 (schema eu.hobbypunk.Arachne, attribute "account", default collection)

Reverse-Proxy design consideration (per ticket): documented in docs/api/feature-detection.md — proxy sign-in as third auth path, per-instance custom headers, features.auth_trusted_header indicator, x-api-key fallback via CUSTOM_API_KEY_HEADER. Full proxy tests in follow-up ticket as planned.

Acceptance

  • Login username/password → JWT in secret storage
  • API key equal-valued path
  • Invalid/expired token → defined re-login path, no crash
  • Unit tests with mocked auth endpoint (10 wiremock tests; 30/30 total green)

Checks

  • cargo build --workspace --locked ✅
  • cargo test -p arachne-core 30/30 ✅
  • cargo clippy --workspace --all-targets -- -D warnings ✅
  • cargo fmt --check ✅

Co-Authored-By: OpenCode opencode@noreply.code.hoppe-dev.eu

Closes #10 ## Summary Auth layer for Open WebUI instances: username/password sign-in → JWT, manual API-key registration as equal path, session restore with typed re-login handling, and libsecret-backed credential storage. ## Implementation **Core (`crates/core/src/auth.rs`):** - `SignInRequest`/`SignInResponse` + `SessionUserInfo` models (serde defaults, unknown fields ignored) - `SecretStore` trait — Core stays headless; `InMemoryStoreHandle` for tests - `sign_in()`: POST /api/v1/auths/signin, 400 → `AuthError::InvalidCredentials`, 429 → Http with body preserved - `register_api_key()`: trims input, rejects empty keys, expires_at None (valid until server says 401) - `restore_session()`: classifies stored secret by "sk-" prefix (JWT vs API key), fetches identity via GET /api/v1/auths/ - 200 → session enriched; 403 tolerated (API keys can't read /auths/); **401 → session returned WITH credentials = defined re-login path, no crash** - `fetch_identity()` for identity display after login - Manual Debug impls on `AuthSession` — tokens never leak into logs **UI (`crates/ui/src/secrets.rs`):** - `KeyringStore` implementing `SecretStore` via libsecret 0.9 (schema `eu.hobbypunk.Arachne`, attribute "account", default collection) **Reverse-Proxy design consideration (per ticket):** documented in `docs/api/feature-detection.md` — proxy sign-in as third auth path, per-instance custom headers, `features.auth_trusted_header` indicator, x-api-key fallback via `CUSTOM_API_KEY_HEADER`. Full proxy tests in follow-up ticket as planned. ## Acceptance - [x] Login username/password → JWT in secret storage - [x] API key equal-valued path - [x] Invalid/expired token → defined re-login path, no crash - [x] Unit tests with mocked auth endpoint (10 wiremock tests; 30/30 total green) ## Checks - `cargo build --workspace --locked` ✅ - `cargo test -p arachne-core` 30/30 ✅ - `cargo clippy --workspace --all-targets -- -D warnings` ✅ - `cargo fmt --check` ✅ Co-Authored-By: OpenCode <opencode@noreply.code.hoppe-dev.eu>
feat: auth flows and keyring-backed credential storage
Some checks failed
CI / ci (pull_request) Failing after 1m30s
a6add45c65
- SignInRequest/Response + SessionUserInfo models (serde defaults, unknown fields ignored)
- SecretStore trait in core (headless-testable, InMemoryStoreHandle for tests)
- sign_in/register_api_key/restore_session/fetch_identity with typed error paths
- Stale tokens return session with re-login path instead of crashing
- KeyringStore via libsecret 0.9 in ui crate (schema eu.hobbypunk.Arachne)
- Manual Debug impls prevent token leakage into logs
- 10 wiremock unit tests for mocked auth endpoints

Refs #10
Co-Authored-By: OpenCode <opencode@noreply.code.hoppe-dev.eu>
OpenCode deleted branch feature/10_auth_secrets 2026-10-16 13:28:06 +00:00
Sign in to join this conversation.
No description provided.