nixpkgs/nixos/modules
Oliver Schmidt e362fe9c6d security/acme: limit concurrent certificate generations
fixes #232505

Implements the new option `security.acme.maxConcurrentRenewals` to limit
the number of certificate generation (or renewal) jobs that can run in
parallel. This avoids overloading the system resources with many
certificates or running into acme registry rate limits and network
timeouts.

Architecture considerations:
- simplicity, lightweight: Concerns have been voiced about making this
  already rather complex module even more convoluted. Additionally,
  locking solutions shall not significantly increase performance and
  footprint of individual job runs.
  To accomodate these concerns, this solution is implemented purely in
  Nix, bash, and using the light-weight `flock` util. To reduce
  complexity, jobs are already assigned their lockfile slot at system
  build time instead of dynamic locking and retrying. This comes at the
  cost of not always maxing out the permitted concurrency at runtime.
- no stale locks: Limiting concurrency via locking mechanism is usually
  approached with semaphores. Unfortunately, both SysV as well as
  POSIX-Semaphores are *not* released when the process currently locking
  them is SIGKILLed. This poses the danger of stale locks staying around
  and certificate renewal being blocked from running altogether.
  `flock` locks though are released when the process holding the file
  descriptor of the lock file is KILLed or terminated.
- lockfile generation: Lock files could either be created at build time
  in the Nix store or at script runtime in a idempotent manner.
  While the latter would be simpler to achieve, we might exceed the number
  of permitted concurrent runs during a system switch: Already running
  jobs are still locked on the existing lock files, while jobs started
  after the system switch will acquire locks on freshly created files,
  not being blocked by the still running services.
  For this reason, locks are generated and managed at runtime in the
  shared state directory `/var/lib/locks/`.

nixos/security/acme: move locks to /run

also, move over permission and directory management to systemd-tmpfiles

nixos/security/acme: fix some linter remarks in my code

there are some remarks left for existing code, not touching that

nixos/security/acme: redesign script locking flow

- get rid of subshell
- provide function for wrapping scripts in a locked environment

nixos/acme: improve visibility of blocking on locks

nixos/acme: add smoke test for concurrency limitation

heavily inspired by m1cr0man

nixos/acme: release notes entry on new concurrency limits

nixos/acme: cleanup, clarifications
2023-09-09 20:13:18 +02:00
..
config nixos/update-users-groups: no need to include extra package 2023-09-03 11:26:37 +02:00
hardware nixos/decklink: init 2023-09-09 19:45:50 +02:00
i18n/input-method uim: remove qt4, fix qt5 2023-09-04 13:54:50 +02:00
image modules/image/repart: Fix stripNixStorePrefix 2023-08-22 13:09:03 +02:00
installer nixos/iso-image: Remove leftover false dichotomy between console/serial 2023-09-06 14:10:09 -04:00
misc nixos/doc: Improve documentation of documentation 2023-08-12 22:28:04 +03:00
profiles nixos/installation-device: allow nix-copy for root/nixos user 2023-08-07 16:48:49 +02:00
programs Merge pull request #253071 from linsui/yazi 2023-09-07 22:57:22 +02:00
security security/acme: limit concurrent certificate generations 2023-09-09 20:13:18 +02:00
services Merge pull request #249964 from ambroisie/woodpecker-improvements 2023-09-09 19:30:34 +02:00
system Merge pull request #254166 from Artturin/fixthingy1 2023-09-09 19:56:02 +03:00
tasks zfs: 'want', don't 'require', systemd-udev-settle 2023-07-28 16:57:12 +10:00
testing Merge pull request #219106 from m-bdf/nixos-testing-increase-device-timeout 2023-06-20 11:48:45 +02:00
virtualisation Merge pull request #253146 from rnhmjoj/pr-anbox 2023-09-05 23:46:54 +02:00
module-list.nix nixos/decklink: init 2023-09-09 19:45:50 +02:00
rename.nix nixos/dhcp(46): remove 2023-07-28 16:35:40 +02:00