10.0 KiB · text History da3a685

recourse

A small axum web application scaffold with:

  • axum web stack with minijinja templates (embedded at build time, hot-reloaded from templates/ in dev)
  • sea-orm + Postgres with a migration crate (auto-migrates on boot)
  • Auth: Argon2 password hashing, cookie sessions, invite-only registration, email verification (mail through mail-prism), optional “Sign in with NEIAM” (OIDC), and bearer API tokens for scripts/mobile
  • Tailwind + DaisyUI front-end with a theme switcher (just assets to build)
  • Prometheus metrics at /metrics, health check at /healthz
  • A Dockerfile (assets → cargo → debian-slim) and compose.yml (Postgres + web)

Quick start

just deps          # npm install (frontend deps)
just assets        # build CSS + JS + webfonts
just db-up         # start Postgres via podman compose; a fresh DB is migrated and gets demo content
just migrate       # apply migrations
just admin alice alice@example.com   # first (staff) account; prints its password
just serve         # run the web service on :3000

Sign in with the printed password. Further members join through invites (just invite, or the Invites page), or are created the same way.

Seed and demo data

  • just seed (manage seed) creates what any forum can keep: a category tree up to three levels deep (Development › Backend › Databases, Hobbies › Games › Board Games, …) with distinct colors, a members-only category (“Members Lounge”, any signed-in account) and a min-trust one (“Regulars’ Corner”, trust level 3+), the default reaction types if missing, and a few tags.
  • just seed-demo (manage seed --demo) adds development data: verified accounts demo-admin (staff, Leader), demo-leader, demo-regular, demo-member, demo-basic and demo-new (one per trust level), all with the password recourse-demo, and topics spread over the last six weeks with replies, an edited post, a soft-deleted post, reactions, bookmarks, tags and a pinned announcement.

Both are idempotent: rows are matched by slug / key / username / topic title and only missing ones are created, so re-running changes nothing and never overwrites edits. just db-up runs seed --demo only when the database has no users yet.

Production never gets demo content. Demo accounts share a published password, so nothing automatic runs --demo: not the image, not compose, not AUTO_MIGRATE. manage seed --demo also refuses to run when PUBLIC_URL is https unless given --allow-public. Plain manage seed is safe in production (it only adds missing categories/reactions/tags); run it by hand if you want the starter categories.

Staff

Staff (category/reaction admin, moderation) is only ever granted on purpose: manage user create … --staff, or manage user set-staff <name> for an existing account. Registering — even as the very first account — never makes anyone staff.

Configuration (environment)

Var Default Meaning
APP_NAME recourse Display name in templates
DATABASE_URL postgres://recourse_user:recourse_password@localhost:5439/recourse Postgres connection
BIND_ADDRESS 0.0.0.0:3000 Listen address
SESSION_DURATION_HOURS 24 Cookie session lifetime
REGISTRATION_TOKEN_DURATION_DAYS 7 Default invite validity
AUTO_MIGRATE true Run migrations on boot
REGISTRATION_ENABLED false Allow /register without an invite link (token still required)
PUBLIC_URL http://localhost:<BIND port> Public origin: base of email-verification links, the default OIDC redirect URI and the API-token curl example. https:// also marks the session cookie Secure
MIN_TRUST_TO_CREATE_TAG 3 Trust level needed to mint new tags
MAIL_PRISM_URL / MAIL_PRISM_API_KEY (unset) Send mail through mail-prism. Unset (or blank): mail is only logged
MAIL_FROM_ADDRESS (the key’s application address) Must equal the mail-prism application address if set
MAIL_FROM_NAME APP_NAME From display name
EMAIL_VERIFICATION_TTL_HOURS 48 Lifetime of a verification link
REQUIRE_EMAIL_VERIFICATION true Unverified accounts can read but not post/reply/react/bookmark/tag
OIDC_ENABLED, OIDC_LOGIN_MODE, OIDC_* off “Sign in with NEIAM”; see below and the neiam-auth README
OIDC_PASSWORD_LOGIN true false hides and refuses password login (implied by OIDC_LOGIN_MODE=sso_strict)

Visual mode

Every category and the home page have a List / Visual switch. The choice sticks: on the account when signed in (users.preferred_view, like the topic sort), in a recourse_view cookie when not; ?view=list|focus in any URL overrides it.

  • /c/{slug}?view=focus&sort=… — the category fills the page. The categories beside it are squares on a rail (the current one has the accent border; on small screens the rail is a horizontal strip), and .. goes up a level, or to the visual home from a top-level category. The category’s own topics are tiles: title, poster and top-replier avatars, replies, views, last activity, tags, reactions, and new / N unread for signed-in users. Each subcategory is a column of compact topic squares with a “Focus on …” link. Categories the viewer may not see never appear, on the rail or anywhere else.
  • &topic=<id> opens the reader over the focus view: the topic’s posts and a filmstrip of the category’s topics in the current sort. ← / → (or k / j) step through them, Escape or a click outside closes it, and every step is a URL, so the back button works. Opening a topic in the reader counts a view and marks it read, exactly as the topic page does.
  • /?view=focus — the home page as a grid of top-level category tiles, each with its subcategories and latest topics.

Modelled on pin_flip’s board focus mode and shared pages, and on cartosnap’s shared-trip stepping; see src/handlers/focus.rs.

Email verification

New accounts (registration through an invite) start unverified: they can read everything but can’t post, reply, react, bookmark or create tags until they follow the link mailed to them. A banner says so, with a “Resend link” button (also on the profile; at most one link per 10 minutes). Links are single-use, expire after EMAIL_VERIFICATION_TTL_HOURS, and a new one replaces the previous one; only a SHA-256 of each token is stored. Accounts that existed before verification was added were marked verified by the migration; accounts made with manage user create start verified, as do accounts signing in through an OIDC provider with OIDC_TRUST_EMAIL=true that vouches for the address.

Mail goes through mail-prism when MAIL_PRISM_URL and MAIL_PRISM_API_KEY are set. The templates live in this repo under mail_prism/ and the webservice pushes them to mail-prism on startup (PUT /api/v1/templates); each verification mail carries an idempotency_key per token, so a retry never sends twice. The client crate is vendored in crates/mail-prism-client (the mail-prism repo is private; see its VENDORED.md).

Without mail-prism (development) the app runs normally and writes each message, link included, to its log at INFO (outbound mail (log transport …)). manage user verify-email <name> skips the link; manage user resend-verification <name> prints a fresh one; manage email test <to> checks the mail-prism setup.

Sign in with NEIAM

neiam-auth v0.4.0 (git dependency, pinned to the tag, sea-orm feature for sea-orm 1.1), wired as in the neiam-htmx template. Off by default: until OIDC_ENABLED=true there is no button and /auth/oidc/* returns 404 (except /auth/oidc/health). The oidc_identities migration always runs.

OIDC_ENABLED=true
OIDC_LOGIN_MODE=mixed                   # local | mixed (default) | sso | sso_strict
OIDC_ISSUER=https://auth.neiam.org
OIDC_CLIENT_ID=recourse
OIDC_CLIENT_SECRET=...                  # or OIDC_CLIENT_SECRET_FILE
OIDC_REDIRECT_URI=https://<host>/auth/oidc/neiam/callback   # default: ${PUBLIC_URL}/auth/oidc/neiam/callback
OIDC_SCOPES="openid profile email groups"
OIDC_GROUPS_CLAIM=groups
OIDC_TRUST_EMAIL=true                   # LDAP mail is admin-set
OIDC_LABEL="Sign in with NEIAM"
OIDC_LOGOUT_URL=https://auth.neiam.org/logout
# OIDC_PROVISION=invite_only            # default; `auto` creates accounts on first login
# OIDC_PROVISION_GROUPS=forum           # invite_only, but members of these groups get an account

Linking (src/auth/oidc.rs): an existing (iss, sub) link; “Link NEIAM account” on the profile; a single active account with the same verified email (with OIDC_TRUST_EMAIL); or a new, passwordless account — only through an invite (/register?token=… shows “Sign up with NEIAM”; in sso_strict the invite link goes straight there) or PROVISION=auto / PROVISION_GROUPS, keeping registration invite-only by default. A taken username or email is never taken over, and accounts created this way are never staff. In sso_strict, password login and local registration are refused.

Binaries

  • recourse — the web service
  • manage — admin CLI:
    • manage user create <name> --email E [--staff] [--password-stdin] — no invite needed; without --password-stdin a strong password is generated and printed once
    • manage user list | set-staff <name> [--revoke] | set-trust <name> <0-4> | activate <name> | deactivate <name> | delete <name> --yes
    • manage user verify-email <name> | resend-verification <name>
    • manage invite create [--email E] [--days N] | list | show <token>
    • manage email test <to> — send a test message through mail-prism (or report it isn’t configured)
    • manage seed [--demo [--allow-public]] — baseline categories/reactions/tags; --demo adds demo users and content
    • Justfile shortcuts: just manage …, just admin <name> <email>, just invite [days], just staff <name>, just trust <name> <level>, just seed, just seed-demo