Files
chess-endgame-trainer/config/config.exs
T
owenrees 624ddab644 Admin panel, login throttling, and Cloudflare edge hardening (#150)
* Document the remote shell for production user management

* add sitemap to footer links

* remove border under theme selection

* Add admin theme and user management (#144)

Add /admin/themes CRUD and /admin/users list/detail with role and plan editing, guarded by a shared Policy module. Include last-super-admin and self-role protections plus structured id-only admin logs.

Also add admin invitations, confirmation resends and password-reset emails, which work in development through the Swoosh mailbox before SES is configured.

* Rate-limit password logins and emit auth events (#142)

Add a two-bucket login throttle (5 failures per login, 10 per IP in a 15-minute window) and a shared client-address helper for controllers and LiveViews. Blocked attempts skip the database and bcrypt.

Log auth.login.failed and auth.login.throttled warnings with boot-scoped HMAC addresses only, and stop repeated confirmation emails on unconfirmed login attempts.

* Harden the production login edge for Cloudflare

Document the layered login defence: the app throttle is primary, Caddy must pass Cloudflare's CF-Connecting-IP to the app, and Cloudflare edge rate limiting covers request floods.

Update the reference Caddyfile to accept only Cloudflare ranges and reject direct-to-origin traffic, and document the exact Cloudflare dashboard rules.

* Document 10-second Cloudflare rate-limit window

Cloudflare may only offer a 10-second period. Keep the edge rule at 10 login POSTs per 10 seconds per IP and rely on the app's 15-minute login/address throttle for credential guessing.

* Document Cloudflare limits for LiveView registration

Registration submits over the shared LiveView socket, so a Cloudflare rule on POST /users/register will not count account creations. Note the app-level throttle/Turnstile options instead.

* Document current Cloudflare free-plan edge controls

Record the production setup: Cloudflare-only Caddy origins, Bot Fight Mode, and the 10-second login flood rule (10 POSTs per 10 seconds, 10-second block). Clarify that the application's 15-minute throttle remains the real credential lockout.

* Auto-refresh Cloudflare CIDRs for Caddy

Move the origin allowlist into a generated cloudflare-ranges.caddy imported by Caddy. Add an hourly systemd timer and script that fetch Cloudflare's v4/v6 lists, reject malformed responses, validate the candidate Caddyfile, and reload Caddy only when the ranges change. Restore the previous file on validation or reload failure.

* Document Cloudflare CIDR refresher setup and operations

Record the installed paths, permissions, timer checks, manual run, update procedure, and the direct-on-VPS setup fallback when the deploy directory is absent.
2026-11-11 21:27:59 +01:00

139 lines
4.9 KiB
Elixir

# This file is responsible for configuring your application
# and its dependencies with the aid of the Config module.
#
# This configuration file is loaded before any dependency and
# is restricted to this project.
# General application configuration
import Config
# Public-facing branding. Change these values to rename the site without
# touching templates. The OTP app (`:chesstrainer`) and module namespaces are
# identity, not branding, and stay as they are.
config :chesstrainer, :branding,
name: "Inner Square Chess",
wordmark: "INNERSQUARE",
tagline: "Endgame Trainer",
support_email: "support@innersquare.app",
mail_from: "no-reply@innersquare.app"
# Prelaunch gating. Production sets these from PRELAUNCH and
# MAILING_LIST_ENABLED; dev and test use these defaults.
config :chesstrainer, :prelaunch, false
config :chesstrainer, :mailing_list_enabled, true
config :chesstrainer, :scopes,
user: [
default: true,
module: Chesstrainer.Accounts.Scope,
assign_key: :current_scope,
access_path: [:user, :id],
schema_key: :user_id,
schema_type: :binary_id,
schema_table: :users,
test_data_fixture: Chesstrainer.AccountsFixtures,
test_setup_helper: :register_and_log_in_user
]
config :chesstrainer,
ecto_repos: [Chesstrainer.Repo],
generators: [timestamp_type: :utc_datetime]
# Password-login throttle. Failures are counted in fixed windows for each
# client address and each normalised login. The address bucket is deliberately
# wider so one account stays protected from distributed guessing while one
# address cannot spray many accounts.
config :chesstrainer, ChesstrainerWeb.LoginThrottle,
window_ms: :timer.minutes(15),
max_per_login: 5,
max_per_ip: 10,
confirmation_cooldown_ms: :timer.minutes(15)
# Glicko rating system.
#
# `system_constant` is the volatility constraint passed through to the Glicko
# package. `window_days` is the minimum gap before replaying the same
# user/endgame pair may change either rating again. `rd_inflation_c` widens a
# rating deviation by sqrt(c^2 * days) while that side is inactive, capped at
# the Glicko maximum (350).
config :chesstrainer, :ratings,
system_constant: 0.8,
window_days: 7,
rd_inflation_c: 10.0
# Difficulty bands for puzzle sessions. An endgame is "medium" when its rating
# falls within `band_width` of the user's rating, "easy" below that band and
# "hard" above it. Tweak to widen or narrow the served difficulty (e.g. 150 or
# 200).
config :chesstrainer, :puzzles, band_width: 100
# Public codes of the endgames pinned to the landing-page puzzle grid, in
# display order. When empty (or short) the grid is topped up with a date-seeded
# selection from the database, so it stays stable for a given day.
config :chesstrainer, :curated_endgame_codes, []
# Configure the endpoint
config :chesstrainer, ChesstrainerWeb.Endpoint,
url: [host: "localhost"],
adapter: Bandit.PhoenixAdapter,
render_errors: [
formats: [html: ChesstrainerWeb.ErrorHTML, json: ChesstrainerWeb.ErrorJSON],
layout: false
],
pubsub_server: Chesstrainer.PubSub,
live_view: [signing_salt: "u0HD4N5a"]
# Configure LiveView
config :phoenix_live_view,
# the attribute set on all root tags. Used for Phoenix.LiveView.ColocatedCSS.
root_tag_attribute: "phx-r"
# Configure the mailer
#
# By default it uses the "Local" adapter which stores the emails
# locally. You can see the emails in your browser, at "/dev/mailbox".
#
# For production it's recommended to configure a different adapter
# at the `config/runtime.exs`.
config :chesstrainer, Chesstrainer.Mailer, adapter: Swoosh.Adapters.Local
# Configure esbuild (the version is required)
config :esbuild,
version: "0.25.4",
chesstrainer: [
args:
~w(js/app.js js/marketing.js --bundle --target=es2022 --outdir=../priv/static/assets/js --external:/fonts/* --external:/images/* --alias:@=.),
cd: Path.expand("../assets", __DIR__),
env: %{"NODE_PATH" => [Path.expand("../deps", __DIR__), Mix.Project.build_path()]}
]
# Configure tailwind (the version is required)
config :tailwind,
version: "4.3.0",
chesstrainer: [
args: ~w(
--input=assets/css/app.css
--output=priv/static/assets/css/app.css
),
cd: Path.expand("..", __DIR__),
env: %{"NODE_PATH" => [Path.expand("../deps", __DIR__), Mix.Project.build_path()]}
]
# Configure the tablebase cache: maximum entries and the UTC time of the daily
# backup. Both can be overridden with environment variables at runtime.
config :chesstrainer, Chesstrainer.Cache,
max_size: 100_000,
backup_time: {3, 0}
# Configure Elixir's Logger
config :logger, :default_formatter,
format: "$time $metadata[$level] $message\n",
metadata: [:request_id]
# Use Jason for JSON parsing in Phoenix
config :phoenix, :json_library, Jason
# Import environment specific config. This must remain at the bottom
# of this file so it overrides the configuration defined above.
import_config "#{config_env()}.exs"