feat(edge): reputation ladder policy - rung table + rung-3 slow budget (NCFG#1991) #2996

Merged
hermes merged 1 commit from kb/NCFG-1991-reputation-ladder-policy into main 2026-11-27 19:53:11 -06:00
Collaborator

Card nix-config#1991, decomposed from #1984. Builds on the merged scorer from #2949 (that PR is the propose-only daemon; this is the policy it proposes into).

What this adds

fleet.crowdsec.enforcement.reputation (hosts/common/optional/crowdsec.nix) - the ladder as one table (rungs[] = score threshold, action, duration, enabled), plus one LAPI profile generated per enabled ban rung.

  • Each ban rung gets its own derived scenario <scenario>/rung-<n> (fleet/request-shape-reputation/rung-4|5|6). One scenario name can carry only one duration, so a ladder written as scenarios would flatten 15m/1h/6h into whichever profile matched first. Derived names also make the rung legible in cscli decisions list.
  • Installed today: rungs 0 (pass), 2 (challenge), 4 (15m), 5 (1h), 6 (6h).
  • Declared and disabled: 7 (24h) and 8 (7d) - #1984 requires an explicit owner ruling before a 24h+ ban; 9 (review) - never automatic; 3 (slow) - neither half of it exists yet (see below).
  • banRungs and scenarios are read-only derived options so the ladder is inspectable from nix eval without reading the file.
  • The option description states the duplication plainly: these thresholds and BANDS in packages/reputation-ladder/reputation_ladder.py are the same numbers written twice, and they agree as shipped.

fleet.edgeLimits.slowRung (hosts/common/global/edge-limits.nix) - rung 3's budget: 250ms-1500ms added latency on 35% of matching requests, rendered into blockFor next to the rate limit, exposed as directive so the exact Caddyfile line is readable from eval.

It ships enable = false, on evidence. The pinned caddy 2.11.4 build carries no delay handler - caddy list-modules | grep http.handlers on /nix/store/r2sqdbgkfp2vmnmg4kx0vv1pi9qgbwh8-caddy-2.11.4: acme_server, authentication, copy_response, copy_response_headers, encode, error, file_server, headers, intercept, invoke, log_append, map, metrics, push, request_body, reverse_proxy, rewrite, static_response, subroute, templates, tracing, vars. No delay/delay_random. Turning the option on without that module in services.caddy.package fails caddy validate at deploy, so the budget is declared with its single consumer and the gap is written on the option.

Also documented on that option, because it is the trap: the budget is uniform. Caddy cannot see a caller's reputation score, so a per-source rung 3 needs a bouncer that answers "is this IP slowed" (crowdsec's caddy bouncer is not installed) or a per-request lookup. Enabling this does not make the ladder reach Caddy.

hosts/vpn/default.nix - enforcement.reputation.enable = true on the LAPI. A rung ban is written by a profile and profiles are the LAPI's; the module renders the list on every host but only the LAPI's engine turns an alert into a decision. The table itself is not restated there.

Safety

The chain that keeps a reputation ban off our own infrastructure is the existing postoverflow whitelist (fleet/whitelist-own-infrastructure -> mesh, loopback, fleet.publicAddresses), which sets remediation false before any profile is consulted. An eval assertion refuses reputation.enable unless 11.0.0.0/24 is still in whitelistCidrs, so the guarantee cannot be edited away silently.

Nothing can fire today: the scorer is dry-run and posts no alerts. What this installs is the profile set.

Eval evidence (base 5c18dd0f, owner hermes)

$ nix eval --json .#nixosConfigurations.public.config.fleet.edgeLimits.slowRung
{"directive":"","enable":false,"maxDelay":"1500ms","minDelay":"250ms","probability":0.35}

$ nix eval --json .#nixosConfigurations.public.config.fleet.crowdsec.enforcement.reputation.scenarios
{"4":"fleet/request-shape-reputation/rung-4","5":"fleet/request-shape-reputation/rung-5","6":"fleet/request-shape-reputation/rung-6"}

$ nix eval --json .#nixosConfigurations.public.config.fleet.crowdsec.enforcement.reputation.banRungs
[{"action":"ban","duration":"15m","enabled":true,"minScore":4,"rung":4,"scenario":"fleet/request-shape-reputation/rung-4"},
 {"action":"ban","duration":"1h","enabled":true,"minScore":6,"rung":5,...},
 {"action":"ban","duration":"6h","enabled":true,"minScore":10,"rung":6,...}]

$ nix eval --json .#nixosConfigurations.vpn.config.fleet.crowdsec.enforcement.reputation.enable
true

$ nix eval --raw .#nixosConfigurations.public.config.system.build.toplevel.drvPath
/nix/store/3ckiivwyljda7sf6n3gv973iabmh12nb-nixos-system-public-26.11.20260909.7b66dac.drv
$ nix eval --raw .#nixosConfigurations.vpn.config.system.build.toplevel.drvPath
/nix/store/avypw4zb3kpmw49023iwh5xz3zsxz2sz-nixos-system-vpn-26.11.20260909.7b66dac.drv

Toplevel drvPath forces every assertion on both hosts; the five new ones evaluate true on public and vpn.

Live verification (after deploy)

  1. ssh vpn cscli profiles list -> fleet_reputation_rung_4/5/6 present with 15m/1h/6h; no rung_7/rung_8.
  2. The card's decision round-trip, run against the LAPI with a documentation TEST-NET address so no real source is touched:
    • cscli decisions add --ip 192.0.2.199 --duration 1m --scenario fleet/request-shape-reputation -> appears in cscli decisions list -o json with that scenario; cscli decisions delete --ip 192.0.2.199 removes it.
    • 11.0.0.1 must never hold a decision (whitelist + assertion above).

Out of scope, stated

  • Wiring the scorer to POST alerts (--enforce still refuses) - the remaining half of enforcement, and it needs a machine credential decision from the owner.
  • A delay module in the caddy build, and a per-source slow mechanism.
  • The rung-2 challenge layer, already landed in #2979.
Card **nix-config#1991**, decomposed from #1984. Builds on the merged scorer from #2949 (that PR is the propose-only daemon; this is the policy it proposes into). ## What this adds **`fleet.crowdsec.enforcement.reputation`** (`hosts/common/optional/crowdsec.nix`) - the ladder as one table (`rungs[]` = score threshold, action, duration, `enabled`), plus one LAPI profile generated per **enabled** ban rung. - Each ban rung gets its own derived scenario `<scenario>/rung-<n>` (`fleet/request-shape-reputation/rung-4|5|6`). One scenario name can carry only one duration, so a ladder written as scenarios would flatten 15m/1h/6h into whichever profile matched first. Derived names also make the rung legible in `cscli decisions list`. - Installed today: rungs 0 (pass), 2 (challenge), 4 (15m), 5 (1h), 6 (6h). - Declared and **disabled**: 7 (24h) and 8 (7d) - #1984 requires an explicit owner ruling before a 24h+ ban; 9 (review) - never automatic; 3 (slow) - neither half of it exists yet (see below). - `banRungs` and `scenarios` are read-only derived options so the ladder is inspectable from `nix eval` without reading the file. - The option description states the duplication plainly: these thresholds and `BANDS` in `packages/reputation-ladder/reputation_ladder.py` are the same numbers written twice, and they agree as shipped. **`fleet.edgeLimits.slowRung`** (`hosts/common/global/edge-limits.nix`) - rung 3's budget: 250ms-1500ms added latency on 35% of matching requests, rendered into `blockFor` next to the rate limit, exposed as `directive` so the exact Caddyfile line is readable from eval. **It ships `enable = false`, on evidence.** The pinned caddy 2.11.4 build carries no delay handler - `caddy list-modules | grep http.handlers` on `/nix/store/r2sqdbgkfp2vmnmg4kx0vv1pi9qgbwh8-caddy-2.11.4`: `acme_server, authentication, copy_response, copy_response_headers, encode, error, file_server, headers, intercept, invoke, log_append, map, metrics, push, request_body, reverse_proxy, rewrite, static_response, subroute, templates, tracing, vars`. No `delay`/`delay_random`. Turning the option on without that module in `services.caddy.package` fails `caddy validate` at deploy, so the budget is declared with its single consumer and the gap is written on the option. Also documented on that option, because it is the trap: the budget is **uniform**. Caddy cannot see a caller's reputation score, so a per-source rung 3 needs a bouncer that answers "is this IP slowed" (crowdsec's caddy bouncer is not installed) or a per-request lookup. Enabling this does not make the ladder reach Caddy. **`hosts/vpn/default.nix`** - `enforcement.reputation.enable = true` on the LAPI. A rung ban is written by a profile and profiles are the LAPI's; the module renders the list on every host but only the LAPI's engine turns an alert into a decision. The table itself is not restated there. ## Safety The chain that keeps a reputation ban off our own infrastructure is the existing postoverflow whitelist (`fleet/whitelist-own-infrastructure` -> mesh, loopback, `fleet.publicAddresses`), which sets remediation false before any profile is consulted. An eval assertion refuses `reputation.enable` unless `11.0.0.0/24` is still in `whitelistCidrs`, so the guarantee cannot be edited away silently. Nothing can fire today: the scorer is dry-run and posts no alerts. What this installs is the profile set. ## Eval evidence (base `5c18dd0f`, owner `hermes`) ``` $ nix eval --json .#nixosConfigurations.public.config.fleet.edgeLimits.slowRung {"directive":"","enable":false,"maxDelay":"1500ms","minDelay":"250ms","probability":0.35} $ nix eval --json .#nixosConfigurations.public.config.fleet.crowdsec.enforcement.reputation.scenarios {"4":"fleet/request-shape-reputation/rung-4","5":"fleet/request-shape-reputation/rung-5","6":"fleet/request-shape-reputation/rung-6"} $ nix eval --json .#nixosConfigurations.public.config.fleet.crowdsec.enforcement.reputation.banRungs [{"action":"ban","duration":"15m","enabled":true,"minScore":4,"rung":4,"scenario":"fleet/request-shape-reputation/rung-4"}, {"action":"ban","duration":"1h","enabled":true,"minScore":6,"rung":5,...}, {"action":"ban","duration":"6h","enabled":true,"minScore":10,"rung":6,...}] $ nix eval --json .#nixosConfigurations.vpn.config.fleet.crowdsec.enforcement.reputation.enable true $ nix eval --raw .#nixosConfigurations.public.config.system.build.toplevel.drvPath /nix/store/3ckiivwyljda7sf6n3gv973iabmh12nb-nixos-system-public-26.11.20260909.7b66dac.drv $ nix eval --raw .#nixosConfigurations.vpn.config.system.build.toplevel.drvPath /nix/store/avypw4zb3kpmw49023iwh5xz3zsxz2sz-nixos-system-vpn-26.11.20260909.7b66dac.drv ``` Toplevel drvPath forces every assertion on both hosts; the five new ones evaluate `true` on `public` and `vpn`. ## Live verification (after deploy) 1. `ssh vpn cscli profiles list` -> `fleet_reputation_rung_4/5/6` present with 15m/1h/6h; no `rung_7`/`rung_8`. 2. The card's decision round-trip, run against the LAPI with a documentation TEST-NET address so no real source is touched: - `cscli decisions add --ip 192.0.2.199 --duration 1m --scenario fleet/request-shape-reputation` -> appears in `cscli decisions list -o json` with that scenario; `cscli decisions delete --ip 192.0.2.199` removes it. - `11.0.0.1` must never hold a decision (whitelist + assertion above). ## Out of scope, stated - Wiring the scorer to POST alerts (`--enforce` still refuses) - the remaining half of enforcement, and it needs a machine credential decision from the owner. - A delay module in the caddy build, and a per-source slow mechanism. - The rung-2 challenge layer, already landed in #2979.
feat(edge): reputation ladder policy - rung table + rung-3 slow budget (NCFG#1991)
All checks were successful
Policy Gates / Worker-scope reaper worker signature (mutation-tested) (pull_request) Successful in 6s
PR base guard / Base drift / conflict check (pull_request) Successful in 4s
Policy Gates / Kanban pool capacity knob (runtime override + clamp, mutation-tested) (pull_request) Successful in 3s
Policy Gates / Sentinel pass budget contract (prompt forbids the full board walk, mutation-tested) (pull_request) Successful in 4s
Policy Gates / CI-scratch reaper class table (mutation-tested) (pull_request) Successful in 4s
foremerge intent (advisory) all 3 changed path(s) covered by a live foremerge intent
Policy Gates / Fleet cache sweep class table (mutation-tested) (pull_request) Successful in 5s
NixOS Build Check / Scope changed deployable hosts (pull_request) Successful in 32s
Review / reviewbot check (pull_request) Successful in 23s
NixOS Build Check / Flake input regression guard (pull_request) Successful in 7s
Secret Scan / gitleaks scan (pull_request) Successful in 35s
Policy Gates / foremerge accept-order contract (real binary) (pull_request) Successful in 1m15s
Policy Gates / Scheduled foremerge reap command line (mutation-tested) (pull_request) Successful in 5s
NixOS Build Check / Hermes runtime gates (one eval of vpn's runtime) (pull_request) Successful in 1m57s
Policy Gates / .forgejo/tests python suites (hermetic) (pull_request) Successful in 59s
Policy Gates / Fleet control ledger (sealed profile fails the build, mutation-tested) (pull_request) Successful in 20s
NixOS Build Check / Build changed host closures (per-host budget) (pull_request) Successful in 4m53s
NixOS Build Check / Gate summary (pull_request) Successful in 1s
Repo Gates / Repo gates (script-only battery) (pull_request) Successful in 6m32s
613d2daa4f
The scorer from #2949 counts offences and proposes a rung; nothing turned a
rung into an action. This adds the policy layer.

`fleet.crowdsec.enforcement.reputation` (crowdsec.nix) declares the ladder as
one table - score threshold, action, duration, enabled - and generates one LAPI
profile per ENABLED ban rung from it. Each ban rung carries its own derived
scenario (`<scenario>/rung-<n>`) because a single scenario name can hold only
one duration, which would have flattened 15m/1h/6h into whichever profile
matched first. Rungs 7 and 8 (24h/7d) are declared and disabled: #1984 puts a
24h+ ban behind an owner ruling, so it must not be reachable by a scorer tuning
change. Rung 3 is declared and disabled because neither half exists yet (the
scorer's BANDS skips score 2, and caddy has no delay handler).

Eval assertions refuse a malformed table: rungs out of order, a decreasing
threshold, a ban without a duration, `enable` with no enabled ban rung left, or
a whitelist that no longer contains the mesh (the postoverflow whitelist is the
only thing keeping a reputation ban off 11.0.0.1).

`fleet.edgeLimits.slowRung` (edge-limits.nix) is the rung-3 budget: 250ms-1500ms
of added latency on 35% of matching requests, rendered into blockFor beside the
rate limit. It ships off because the pinned caddy 2.11.4 build has no
delay/delay_random module (`caddy list-modules`); enabling it without that
module fails `caddy validate` at deploy, so the option is declared with the
budget and the exact directive it would render, and the gap is written down.

vpn (the LAPI) sets `enforcement.reputation.enable = true` so the ban rungs
exist where decisions are made. Nothing can fire: the scorer is dry-run and
posts no alerts.
hermes merged commit 0dd9ede680 into main 2026-11-27 19:53:11 -06:00
hermes deleted branch kb/NCFG-1991-reputation-ladder-policy 2026-11-27 19:53:12 -06:00
Sign in to join this conversation.
No reviewers
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
ymrtech/nix-config!2996
No description provided.