nixpkgs/nixos/modules/security
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
..
acme security/acme: limit concurrent certificate generations 2023-09-09 20:13:18 +02:00
apparmor nixos/apparmor: support custom i18n glibc locales 2023-07-12 21:38:31 +02:00
wrappers Revert "nixos/security/wrappers: simplifications and a fix for #98863" 2023-08-24 08:35:11 +02:00
apparmor.nix nixos: fix typos 2022-12-17 19:31:14 -05:00
audit.nix nixos: fix backticks in Markdown descriptions 2023-01-21 18:08:38 +01:00
auditd.nix nixos/*: automatically convert option descriptions 2022-08-31 16:32:53 +02:00
ca.nix nixos/qemu-vm: use CA certificates from host 2023-07-06 21:32:08 +10:00
chromium-suid-sandbox.nix treewide: automatically md-convert option descriptions 2022-07-30 15:16:34 +02:00
dhparams.nix nixos/*: convert options with admonitions to MD 2022-08-31 16:36:16 +02:00
doas.nix doas: refactor config generation 2023-03-17 09:05:08 -07:00
duosec.nix treewide: automatically md-convert option descriptions 2022-07-30 15:16:34 +02:00
google_oslogin.nix treewide: automatically md-convert option descriptions 2022-07-30 15:16:34 +02:00
ipa.nix treewide: stop using types.string 2023-08-08 21:31:21 +08:00
lock-kernel-modules.nix treewide: use optional instead of 'then []' 2023-06-25 09:11:40 -03:00
misc.nix nixos/*: convert varlist-using options to MD 2022-08-31 16:32:53 +02:00
oath.nix treewide: automatically md-convert option descriptions 2022-07-30 15:16:34 +02:00
pam.nix security/pam: add umask option to configure pam_mkhomedir 2023-08-10 20:35:08 -04:00
pam_mount.nix nixos/pam_mount: fix mounts without options (#234026) 2023-05-25 22:45:59 +02:00
pam_usb.nix nixos/*: automatically convert option docs to MD 2022-08-03 22:46:41 +02:00
please.nix nixos/please: init module 2022-10-15 07:05:10 -07:00
polkit.nix Revert "nixos/polkit: guard static gid for polkituser behind state version" 2023-02-25 22:32:16 -05:00
rngd.nix
rtkit.nix treewide: automatically md-convert option descriptions 2022-07-30 15:16:34 +02:00
sudo.nix nixos/sudo: Guard against security.sudo.package = pkgs.sudo-rs; 2023-09-04 22:00:00 +00:00
systemd-confinement.nix nixos/systemd-confinement: remove unused rootName 2023-01-20 22:39:16 +01:00
tpm2.nix nixos/tpm2: fix typo 2023-05-09 18:02:17 +04:00