This is one of the shipped proof surfaces for the repo's secure-systems thesis, alongside the encrypted sensitive-data and bounded sync slice.
This project uses axum-login for authentication and tower-sessions for session storage. Think of it as:
axum-login: auth orchestration (login/logout, current user, session auth hash).tower-sessions: session middleware (cookies, persistence, expiry).
- A request hits the router.
tower-sessionsreads or creates a session based on the session cookie.axum-loginuses the session to resolve the current user.- Handlers read
AuthSessionand decide what to do.
- Auth backend:
crates/http/src/auth.rs- Implements
axum_login::AuthnBackend. - Bridges to
app::auth::Service.
- Implements
- Session middleware:
crates/http/src/router/layers.rs- Builds
SessionManagerLayer(secure cookie, SameSite, expiry). - Wraps the router with
AuthManagerLayerBuilder.
- Builds
- Auth use-case:
crates/app/src/auth.rs- Validates credentials and fetches user data.
- Password hashing:
crates/infra/src/auth.rs- Argon2 hashing and verification.
- Persistence:
crates/infra/src/auth.rs+crates/infra/migrations/003_credentials.*.sql
We use tower-sessions-sqlx-store with Postgres:
- Store:
tower_sessions_sqlx_store::PostgresStore - Schema + table:
crates/infra/migrations/004_sessions.*.sql - Cleanup task: in
src/main.rs- Interval configured by
SESSION_CLEANUP_INTERVAL_SECS(default 3600).
- Interval configured by
Session cookies are configured in crates/http/src/router/layers.rs:
- Name:
eran.sid - HttpOnly:
true - SameSite:
Lax - Secure:
truein non-debug builds - Expiry:
OnInactivity(7 days) - Signed/encrypted using
SESSION_SECRET
POST /loginaccepts email + password.axum-logincallsapp::auth::Service::authenticate.app::authusesinfra::auth::AuthRepositoryandArgon2Hasher.- On success,
AuthSession::loginstores the user id and session auth hash.
POST /registervalidates input (domain constructors).app::user::Servicehashes password and writesusers+credentials.- The handler reuses the login flow to create a session.
axum-logindoes not store sessions itself; it depends ontower-sessions.tower-sessionsdoes not know how to authenticate users; it only stores session data.- Together they provide secure, persistent authentication.
The live proof surfaces show:
- Current auth/session status.
- Request metadata and tracing logs.
- SQL statements + timings from infra repositories.
These are wired through partial endpoints in crates/http/src/handlers.rs and trace capture in crates/http/src/trace_log.rs, and they let reviewers inspect the session/auth foundation directly beside the encrypted-record and sync proof now shipped in the repo.