Add rate-based burst-detection foundation, propose-only (D-0051) #128

Merged
hannah-vernon merged 4 commits from feature/burst-detection into dev 2026-09-22 17:40:11 -05:00
Owner

What does this PR do?

Adds a generic, propose-only rate-based burst-detection foundation (D-0051). Single-event detection rules cannot count, so this introduces a per-(signal, source) sliding-window aggregate: BurstDetector maintains windowed counts and, when a signal reaches its threshold within the window, proposes an incident for review.

  • Fed from CorrelationWorker (the single stage every ingested event passes through), so no new pipeline queue is added.
  • A firing becomes an Incident with a distinct correlation key burst:{signal}:{sourceKey} (never merged with the per-IP incidents from TimeWindowCorrelator), carrying the windowed event ids and one evidence item scored min(3.0 + 0.2 * (count - threshold), 5.0), then flows through the existing classification/policy/decision path to /decisions.
  • Reference signal: admin authentication failures (AuthFailureBurstSignal: LoginFailed/TotpFailed/StepUpFailed/WebAuthnFailed, keyed by source IP).
  • Window and cooldown state are durable in PostgreSQL from the outset (burst_windows, burst_cooldowns) with per-record pruning and an atomic cooldown upsert, so counts survive restarts and concurrent instances cannot both fire.
  • Six controls (GlobalEnabled, AuthFailureEnabled, AuthFailureThreshold, AuthFailureWindowSeconds, AuthFailureCooldownSeconds, AuthFailureActionEligible) are a database-owned single-row burst_detection_settings table following the D-0050 config-store pattern: seeded create-only from BurstDetectionOptions, edited on /configuration#burst-detection (step-up gated, audited), hot-refreshed on the viegard_config_burst_detection_settings NOTIFY channel, and exposed read-only at GET /api/v1/burst/settings.
  • Propose-only: the action-eligible flag defaults false and the system runs in dry-run posture, so a firing is a review proposal, never an unattended action.

The originating slow-loris HTTP 408 case remains deferred (TODO Path A vs B) as a future consumer of this foundation.

Fixes # N/A

How was this tested?

  • dotnet build - 0 errors, 0 warnings (full solution)
  • dotnet test - all tests pass (207 AdminApi, 553 Application; new burst tests included)
  • Manually tested on the in-memory rig: clean startup; GET /api/v1/burst/settings returns correct defaults and requires auth; /configuration renders the burst section; authenticated edit round-trip persisted new values with version incremented and seeded flipping to true.

New unit/integration tests: read-only API defaults and round-trip, save endpoint (persist, unchecked-box disable, invalid value, version conflict), and Postgres window/cooldown round-trip. The three burst tables were added to the integration-test truncate list.

Checklist

  • I have read the Contributing Guide
  • Changes are focused - one logical change per PR
  • Documentation updated (README.md / DECISIONS.md / TODO.md / AGENT-README.md, if applicable)
  • New dependencies are MIT/Apache-2.0/BSD, security-vetted, and recorded in THIRD-PARTY-NOTICES.md (no new dependencies)
  • No secrets, credentials, or real infrastructure identifiers in the diff
  • No commented-out code or debug leftovers
## What does this PR do? Adds a generic, propose-only **rate-based burst-detection foundation** (D-0051). Single-event detection rules cannot count, so this introduces a per-(signal, source) sliding-window aggregate: `BurstDetector` maintains windowed counts and, when a signal reaches its threshold within the window, proposes an incident for review. - Fed from `CorrelationWorker` (the single stage every ingested event passes through), so no new pipeline queue is added. - A firing becomes an Incident with a distinct correlation key `burst:{signal}:{sourceKey}` (never merged with the per-IP incidents from `TimeWindowCorrelator`), carrying the windowed event ids and one evidence item scored `min(3.0 + 0.2 * (count - threshold), 5.0)`, then flows through the existing classification/policy/decision path to `/decisions`. - Reference signal: admin authentication failures (`AuthFailureBurstSignal`: LoginFailed/TotpFailed/StepUpFailed/WebAuthnFailed, keyed by source IP). - Window and cooldown state are durable in PostgreSQL from the outset (`burst_windows`, `burst_cooldowns`) with per-record pruning and an atomic cooldown upsert, so counts survive restarts and concurrent instances cannot both fire. - Six controls (`GlobalEnabled`, `AuthFailureEnabled`, `AuthFailureThreshold`, `AuthFailureWindowSeconds`, `AuthFailureCooldownSeconds`, `AuthFailureActionEligible`) are a database-owned single-row `burst_detection_settings` table following the D-0050 config-store pattern: seeded create-only from `BurstDetectionOptions`, edited on `/configuration#burst-detection` (step-up gated, audited), hot-refreshed on the `viegard_config_burst_detection_settings` NOTIFY channel, and exposed read-only at `GET /api/v1/burst/settings`. - **Propose-only:** the action-eligible flag defaults false and the system runs in dry-run posture, so a firing is a review proposal, never an unattended action. The originating slow-loris HTTP 408 case remains deferred (TODO Path A vs B) as a future consumer of this foundation. Fixes # N/A ## How was this tested? - [x] `dotnet build` - 0 errors, 0 warnings (full solution) - [x] `dotnet test` - all tests pass (207 AdminApi, 553 Application; new burst tests included) - [x] Manually tested on the in-memory rig: clean startup; `GET /api/v1/burst/settings` returns correct defaults and requires auth; `/configuration` renders the burst section; authenticated edit round-trip persisted new values with `version` incremented and `seeded` flipping to true. New unit/integration tests: read-only API defaults and round-trip, save endpoint (persist, unchecked-box disable, invalid value, version conflict), and Postgres window/cooldown round-trip. The three burst tables were added to the integration-test truncate list. ## Checklist - [x] I have read the [Contributing Guide](../CONTRIBUTING.md) - [x] Changes are focused - one logical change per PR - [x] Documentation updated (README.md / DECISIONS.md / TODO.md / AGENT-README.md, if applicable) - [x] New dependencies are MIT/Apache-2.0/BSD, security-vetted, and recorded in THIRD-PARTY-NOTICES.md (no new dependencies) - [x] No secrets, credentials, or real infrastructure identifiers in the diff - [x] No commented-out code or debug leftovers
Note the 408 incomplete-request finding on /decisions (a single 408 with
0 body and a ~60s request time is over-weighted to severity 6) and the
two proposed paths (reweight-and-accumulate vs an explicit windowed
burst detector), deferred for a future decision.  Mark the generic
rate-based burst-detection foundation as in progress, decoupled from the
slow-loris path.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Introduce the standalone rate-based burst detector foundation (propose-only):
BurstDetectionSettings/Values/Validator, settings store interface and source
snapshot, IBurstSignal with the AuthFailureBurstSignal reference signal, the
durable IBurstWindowStore contract, and the BurstDetector engine.  Add in-memory
settings and window stores plus 17 Application unit tests.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Durable settings store (pg_notify change signalling, optimistic concurrency)
mirroring the classifier-settings store, plus a (signal, source) sliding-window
occurrence store and atomic cooldown upsert.  Adds row types, mappings, DbContext
configuration, DI registration, and the AddBurstDetection EF migration.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Complete the propose-only rate-based burst-detection foundation on top of
the Application spine and Postgres stores.  The detector is driven from
CorrelationWorker (the single every-event stage), fires a distinct
burst:{signal}:{sourceKey} incident through the existing
classification/policy/decision path, and is fed by the durable Postgres
window and cooldown stores.

- PipelineHost: seed, NOTIFY-driven refresh, and logging diagnostics
  workers; BurstDetector integration in CorrelationWorker; DI wiring.
- AdminApi: burst-detection options/store/source DI; step-up-gated,
  audited save endpoint and TryRead form parsing; read-only
  GET /api/v1/burst/settings; /configuration#burst-detection section.
- Tests: read-only API defaults/round-trip, save endpoint (persist,
  unchecked-box disable, invalid, version conflict), and Postgres
  window/cooldown round-trip; burst tables added to the truncate list.
  Verified against the in-memory rig (startup, defaults, authenticated
  edit round-trip, version increment).
- Docs: DECISIONS D-0051, AGENT-README, ARCHITECTURE, TODO, read-only-api.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
hannah-vernon deleted branch feature/burst-detection 2026-09-22 17:40:11 -05:00
Sign in to join this conversation.
No reviewers
No labels
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
hannah-vernon/viegard-sentinel!128
No description provided.