Commit graph

6 commits

Author SHA1 Message Date
Tom Winnerl
d50d5c7287 feat(nginx): serialised configure that tests, rolls back and repairs other hosts
Every write of a host config now goes through one configure() that runs
under a re-entrant lock (lib/nginx-lock.js), so concurrent saves can't test
or rename each other's files:

- the new config is written and checked with nginx -t; when nginx rejects
  this host, the previous file (and .err file) is put back and an
  NginxConfigError with structured details is thrown (scope host/global,
  file, line, humanised message and hint, raw nginx output)
- when another host's file breaks the test, that host is only blamed when it
  fails on its own (lib/nginx-blame.js). It is regenerated from its database
  row first and only moved to .err and marked offline when that fails too.
  A conflict with the change being saved fails the save instead. An error
  that names no file (eg. an unknown variable) is only a conflict when it
  goes away with every other host's config moved aside; otherwise it is the
  host's own error and, when its advanced config uses the variable or path,
  reads "Advanced configuration: ..."
- errors are humanised (lib/nginx-errors.js) and mapped to the advanced
  config of the host where possible (new begin/end markers in the templates)
- the API returns error.details; a middleware redacts details that name a
  host the user can't see
- bulkGenerateConfigs (certificates) and the default site go through the
  same path, a host nginx rejects is taken offline instead of failing all
- nginx -s reload only signals the master, which reads the config later.
  reloadNginx() waits (bounded, 5 s) until the master runs a new generation
  of workers and the old ones are shutting down (lib/nginx-reload.js, from
  /proc) before the lock is released,
  otherwise the next holder's rejected candidate file could be what the
  master reads and the change saved before would never be applied. A reload
  that can't be confirmed is repeated once at the end of the locked section,
  after every rollback. When nginx logs an [emerg] for the reload (eg. a
  listen port in use, which nginx -t doesn't catch) the wait ends as soon
  as nginx gives up on it (for a bind() after its own retries), and after
  a repeated reload that isn't confirmed either, later saves don't repeat
  it until a reload is confirmed again, so they don't each wait 10 s
- reconcile() regenerates missing / moved-aside configs and retries hosts
  whose upstream didn't resolve yet; the startup commit runs it from
  backend/index.js (NPM_RECONCILE_ON_START)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-11 13:47:08 +01:00
José M. Requena Plens
1ffe3609f4
Invalidate tokens issued before a password change
Tokens are stateless JWTs, so changing a password left every session that
the old one had opened working until its own expiry, up to a day later.
That is the case the password change is meant to close: an administrator
resetting a compromised account did not evict whoever was already in it.

The auth row already records when the password last changed, so no
migration is needed: `Access.init()` reads it alongside the user it
already loads and refuses a token whose `iat` is older. Both sides are
compared as whole seconds, which is all `iat` carries, so a token minted
in the same second as the change is kept. Postgres stores that column to
the microsecond, which is why the comparison is not done in milliseconds.

It is reported as 401 rather than the usual 403 because that is what the
frontend clears the session on, so the browser holding the dead token
lands on the login page instead of a page full of errors, and `can()`
lets that one error through unwrapped for the same reason.

Only the password does this. A user row changing (a rename, an avatar,
permissions) does not, and a user with no password auth row, which is
what a login through an external provider looks like, is not affected.
2026-09-06 19:48:02 +02:00
Jamie Curnow
fb2708d81d
Fix cypress tests following user wizard changes 2025-10-02 08:12:09 +10:00
Jamie Curnow
330993f028
Convert backend to ESM
- About 5 years overdue
- Remove eslint, use bomejs instead
2025-10-02 08:10:18 +10:00
Jamie Curnow
db23c9a52f
Refactor certbot plugins install
- Added a script to install every single plugin, used in development and debugging
- Improved certbot plugin install commands
- Adjusted some version for plugins to install properly
- It's noted that some plugins require deps that do not match other plugins,
  however these use cases should be extremely rare
2024-01-18 12:26:55 +10:00
jc21
bb0f4bfa62
v2.1.0 (#293)
* Fix wrapping when too many hosts are shown (#207)

* Update npm packages, fixes CVE-2019-10757

* Revert some breaking packages

* Major overhaul

- Docker buildx support in CI
- Cypress API Testing in CI
- Restructured folder layout (insert clean face meme)
- Added Swagger documentation and validate API against that (to be completed)
- Use common base image for all supported archs, which includes updated nginx with ipv6 support
- Updated certbot and changes required for it
- Large amount of Hosts names will wrap in UI
- Updated packages for frontend
- Version bump 2.1.0

* Updated documentation

* Fix JWT expire time going crazy. Now set to 1day

* Backend JS formatting rules

* Remove v1 importer, I doubt anyone is using v1 anymore

* Added backend formatting rules and enforce them
in Jenkins builds

* Fix CI, doesn't need a tty

* Thanks bcrypt. Why can't you just be normal.

* Cleanup after syntax check

Co-authored-by: Marcelo Castagna <margaale@users.noreply.github.com>
2020-02-19 15:55:06 +11:00