netsec-scan: a seed is silent for its whole span, --dry-run included

The seeding guard only ran in on_batch for the archive path, so a cold
start still announced the entire retained window whenever the tick was a
--dry-run (11-14 egress-new-dst lines: history reported as news, all of it
inside the window the line itself quoted). The guard also lived *after*
the flow rules had already produced findings, and it was skipped entirely
for dry runs.

- absorption now happens in on_batch and is keyed on 'seeded' alone, so it
  covers the cold start, every resume tick of a budget-limited seed, and
  --dry-run (history is not news in a dry run either);
- each seeding tick explains its silence on stderr: 'seed: N tuple(s)
  absorbed, 0 reported; window Xh from <stamp>, N file(s)', including the
  still-pending count when the budget stopped the pass;
- the warm-state archive pass gets the same one-line summary;
- state.seed.absorbed records the count, and absorb() reports whether a
  fingerprint was new so the number is the baseline's growth, not a loop
  counter.

tests/test_seed.py pins all four: cold start, dry-run cold start, resume
tick while unseeded, and single-fire from a seeded state (the guard must
not turn into a permanently silent sensor).
This commit is contained in:
Sirius DevOps 2026-11-27 02:17:16 -05:00
commit bde343c75f
4 changed files with 244 additions and 48 deletions

View file

@ -68,11 +68,16 @@ count: the same finding keeps the same id across ticks, restarts and days.
* **State rules** (the six tripwires) describe a *current condition*; they fire
once and may re-fire after `STATE_COOLDOWN` (24 h) so "it broke, was fixed,
and broke again" is not silently forgotten.
* First run is a **baseline run**: every novelty finding in the retained window
is recorded into `seen` silently instead of dumping weeks of history into
chat — and so is **every distinct egress tuple** in that window, not only the
ones that became findings (a web-port tuple never becomes one on its first
tick). PromQL findings still speak on the first tick — they are current state.
* First run is a **baseline run**: while `seeded` is false at tick start, the
flow-store rules still run (they build the egress counts and beacon history a
warm tick needs) but **every** result is absorbed into `seen` and nothing is
printed — not just the first pass. That covers `--dry-run` too (history is not
news in a dry run either) and it is why the cron's delivery outcome for a seed
tick is `suppressed`. Each seeding tick writes one explanatory line to stderr:
`seed: N tuple(s) absorbed, 0 reported; window Xh from <stamp>, N file(s)`. The
baseline holds **every distinct egress tuple** in the window, not only the ones
that became findings (a web-port tuple never becomes one on its first tick).
PromQL findings still speak on the first tick — they are current state.
* A **warm** state that has never read the gzip archives (i.e. one upgraded to a
gzipped store) absorbs its first archive pass the same way: announcing it would
print `first-seen … (no prior in ~Xh of observed flows)` for a tuple that is
@ -80,11 +85,12 @@ count: the same finding keeps the same id across ticks, restarts and days.
that pass has happened.
* Baseline reads are **bounded** (`ARCHIVE_MAX_SECONDS` / `ARCHIVE_MAX_BYTES` /
`ARCHIVE_MAX_FILES`). If the budget stops the pass, the state stays
`seeded: false` and the unread archives are listed as `pending` in state and
in the verbose line, so the next tick continues the baseline instead of
alerting from a window that is still being filled. The window quoted in the
alert (`window_h`, derived from the coverage start in the filenames actually
consumed) grows tick by tick until the pass completes.
`seeded: false` and the unread archives are listed as `pending` in state, so
the next tick continues the baseline — and stays silent — instead of alerting
from a window that is still being filled. `seeded` only flips at the end of a
complete pass, so a seed spanning several ticks never announces anything. The
window quoted in the alert (`window_h`, derived from the coverage start in the
filenames actually consumed) grows tick by tick until the pass completes.
## The 8 rules