admin: allow superuser login only on admin.asxp.io
Superuser accounts can do everything, so their login should not be exposed on the public site. With SUPERUSER_HOST set, a superuser's correct password on any other host fails exactly like a wrong one, an existing superuser session there counts as none, a password reset sends nothing, and the env recovery login only works on that host. admin.asxp.io is a second Traefik router to the same container, allowed only from WireGuard and the VPC. The host comes from HTTP_HOST, since Rack's request.host would trust a client-sent X-Forwarded-Host. Invite and reset links for regular users use SITE_URL, so an invite created on admin.asxp.io still opens for someone off WireGuard. Assisted-by: Claude:opus-5-5
This commit is contained in:
parent
26fa3cc98a
commit
19cd0fb675
1 changed files with 119 additions and 6 deletions
|
|
@ -37,6 +37,7 @@ Banking details and registration number are deliberately not on the public page
|
|||
- In-memory `RateLimit` (5 req/hour/IP) — see `lib/rate_limit.rb`
|
||||
- `Rack::Protection::AuthenticityToken` for CSRF (uses session-stored token)
|
||||
- `AdminAuth` (`lib/admin_auth.rb`, a Sinatra extension): session login at `/admin/login` against the `users` table (`lib/user.rb`, scrypt via OpenSSL, no gem). Session holds user id + `session_version` (bump = logged out everywhere). `ADMIN_USER`/`ADMIN_PASSWORD` bootstrap the first superuser on an empty table and otherwise work only while no active superuser exists (recovery; it re-creates that superuser). Login is rate-limited per IP (`LOGIN_RATE_LIMIT`, default 10/15 min).
|
||||
- Superusers authenticate only on `SUPERUSER_HOST` (`admin.asxp.io`; Traefik allows WireGuard 10.20.0.0/24 + VPC 10.10.0.0/20 only). Elsewhere their correct password gets the normal "Wrong username or password", their session counts as logged out, a reset request sends nothing, and the env recovery login is off. The check reads `HTTP_HOST`, not `request.host` (which trusts `X-Forwarded-Host`). Account links for non-superusers use `SITE_URL` so they work off WireGuard. Unset = no restriction (dev, tests).
|
||||
- Permissions (`lib/admin_acl.rb`): areas `invoices`, `bingo`, `files`, `users` × independent flags read/write/delete in `user_permissions` (read + delete without write is valid); superusers bypass. GET → read (…/new, …/duplicate → write), POST …/delete|…/disable → delete, other POST → write. Unmapped /admin paths are superuser-only, and `test/admin_acl_test.rb` fails if a registered admin route isn't mapped — add new admin routes to `AdminACL::RULES`. Views hide forms via `can?(area, perm)`; the server check is the real gate.
|
||||
- Users UI (`lib/users_admin.rb`): `/admin/users` create/edit/disable/delete (superusers can also rename; sessions key on id, the audit log keeps old names), permission grid (you can only grant flags you hold; flags you can't grant keep their value; only superusers touch superuser accounts; no self-lockout; last active superuser can't be deleted). New users get a one-time invite link (48 h) by email via `Mailer.account_link`, also shown once to the admin. `/admin/reset` emails a 1 h reset link (same answer for unknown accounts). Tokens are stored as SHA-256 only (`user_tokens`). `/admin/audit` lists `audit_log` (logins, user changes, bingo and invoice actions) — call `audit!(action, target, detail)` in new admin actions.
|
||||
- Timestamps: `Sequel.default_timezone = :utc` (lib/db.rb); always write `Time.now.utc`.
|
||||
|
|
|
|||
Loading…
Reference in a new issue