Skip to content

nixos/crowdsec: add hub.updateOnStart for hermetic deploys (closes #520206) - #521985

Closed
SMC17 wants to merge 1 commit into
NixOS:masterfrom
SMC17:crowdsec-hub-update-on-start
Closed

SMC17 wants to merge 1 commit into
NixOS:masterfrom
SMC17:crowdsec-hub-update-on-start

Conversation

@SMC17

@SMC17 SMC17 commented May 19, 2026

Copy link
Copy Markdown

Description of changes

Adds services.crowdsec.hub.updateOnStart, a new boolean option
(default true, preserves existing behaviour) that controls whether
cscli hub update runs as part of the crowdsec.service
ExecStartPre.

Closes #520206.

Motivation

When cscli hub update runs unconditionally inside the
ExecStartPre script (which uses set -euo pipefail), any
network-unavailable condition at service-start time aborts the
script and fails the service. The failure combines badly with the
DynamicUser + StateDirectory semantics of the
crowdsec-firewall-bouncer-register service, which migrates
/var/lib/crowdsec → /var/lib/private/crowdsec under the dynamic
user. After that migration, subsequent script runs get EACCES on
/var/lib/crowdsec and the service is permanently stuck without
manual filesystem cleanup. See #520206 for the full cascade.

This blocks pkgs.testers.nixosTest-based integration testing of
the services.crowdsec module (test VMs have no network by
default) and affects air-gapped / DNS-strict / pre-network-online
deployments in production.

Approach

Minimal-diff fix that exposes operator choice rather than
heuristic auto-detection:

  1. Add services.crowdsec.hub.updateOnStart (default true).
    When true, behaviour is identical to the pre-patch module.
    When false, the cscli hub update line is omitted from the
    ExecStartPre script entirely.

  2. The existing services.crowdsec.autoUpdateService option
    (periodic timer-based updates) is unaffected and continues to
    work alongside this — operators can choose any combination:

updateOnStart autoUpdateService Result
true (default) true Startup + daily updates (current behaviour)
true false Startup only
false true Daily only (correct for hermetic / late-network deployments)
false false Manual cscli hub update only

What I did NOT change

  • The error semantics of the script itself — set -euo pipefail
    stays. A failed cscli hub update still aborts service start
    when updateOnStart = true. The fix is opt-out of the call, not
    silently swallowing errors when it runs.
  • The crowdsec-firewall-bouncer-register DynamicUser +
    StateDirectory migration — that's the secondary half of the
    cascade and deserves its own change. This PR addresses the
    proximate trigger so testing can land first.
  • services.crowdsec.autoUpdateService semantics.

Things done

  • Built on platform(s): I did not run a NixOS build for this
    PR. The change is module-config-shaped (new option, conditional
    inclusion of an existing list element); a nixos-rebuild dry-build against a config that sets the new option to false
    would be the expected pre-merge verification on the reviewer
    side, plus an actual pkgs.testers.nixosTest re-run with
    services.crowdsec.hub.updateOnStart = false to confirm the
    test now passes where it previously failed.
  • For NixOS module changes: a pkgs.testers.nixosTest exists
    for services.crowdsec, but it currently hits the bug
    documented in nixos/crowdsec: ExecStartPre hub update fails in hermetic VMs, cascades to permanent EACCES via bouncer-register StateDirectory #520206 and times out. Adding a passing test that
    sets updateOnStart = false would be the natural follow-up
    commit if maintainers want it included in this PR.
  • Tested basic functionality of the module: the proposed
    conditional matches the existing lib.optionals pattern used
    elsewhere in the same scriptArray (e.g. for
    cfg.hub.collections, cfg.hub.scenarios).
  • Considered backward compatibility: default true preserves
    pre-patch behaviour exactly.

Verification of the issue is current

The bug location at nixos/modules/services/security/crowdsec.nix
lines 553–557 (the scriptArray definition) was verified against
the current main HEAD of NixOS/nixpkgs at PR-prep time.


Issue-reference: closes #520206.

@nixpkgs-ci
nixpkgs-ci Bot requested review from 06kellyjac, M0ustach3 and TornaxO7 May 19, 2026 16:13
@nixpkgs-ci nixpkgs-ci Bot added 10.rebuild-linux: 1-10 This PR causes between 1 and 10 packages to rebuild on Linux. 10.rebuild-darwin: 0 This PR does not cause any packages to rebuild on Darwin. 12.first-time contribution This PR is the author's first one; please be gentle! 6.topic: nixos Issues or PRs affecting NixOS modules, or package usability issues specific to NixOS 8.has: module (update) This PR changes an existing module in `nixos/` labels May 19, 2026
@SMC17 SMC17 closed this Jul 15, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

6.topic: nixos Issues or PRs affecting NixOS modules, or package usability issues specific to NixOS 8.has: module (update) This PR changes an existing module in `nixos/` 10.rebuild-darwin: 0 This PR does not cause any packages to rebuild on Darwin. 10.rebuild-linux: 1-10 This PR causes between 1 and 10 packages to rebuild on Linux. 12.first-time contribution This PR is the author's first one; please be gentle!

Projects

None yet

Development

Successfully merging this pull request may close these issues.

nixos/crowdsec: ExecStartPre hub update fails in hermetic VMs, cascades to permanent EACCES via bouncer-register StateDirectory

1 participant