netsec-scan: read flows-*.jsonl.gz so a cold start baselines the retained window, not the live file

The collector gzips on rotation, so FLOW_PATTERN 'flows-*.jsonl' saw 1 of 5
files (measured: 1/72 of the retained window). Archives are immutable, so each
is read once, whole, decrypted lazily and recorded in state['archives'].

- archives are bounded (ARCHIVE_MAX_SECONDS/BYTES/FILES, newest first) and
  flows are consumed in batches; a partial pass leaves state seeded=false and
  reports the unread files as pending, so the next tick continues instead of
  alerting from a window it has not examined
- the alert window comes from the coverage start in the consumed filenames
  (monotone), so 'no prior in ~Xh of observed flows' is now verifiable
- the seed absorbs every egress tuple in the window, not just findings (a
  web-port tuple never becomes one on its first tick); a warm state meeting
  archives for the first time absorbs them the same way
- a torn .gz keeps its readable prefix, is noted in state/seed.failed, and does
  not abort the tick; in-flight *.gz.tmp.* markers are never read
- report.json carries window_h/covered_since/seed; 12 new tests
This commit is contained in:
Sirius DevOps 2026-11-27 02:09:51 -05:00
commit ba1bef3814
8 changed files with 690 additions and 98 deletions

View file

@ -36,7 +36,10 @@ def empty() -> Dict[str, Any]:
"beacon": {}, # tuple -> {socket: ts}
"egress_counts": {}, # tuple -> {n ticks seen, first, last_tick}
"observed_since": None, # earliest flow timestamp ever observed (ISO)
"files": {}, # name -> {offset, carry, size}
"files": {}, # name -> {offset, carry, size} (plain, appended to)
"archives": {}, # name -> {size, read_at, lines} (.jsonl.gz, read once)
"archive_baseline": False, # archives have been baselined once (absorbed silently)
"seed": {}, # summary of the baseline run: window, files, tuples
"degraded": {}, # failure class -> iso of last announcement
"day": {"date": datetime.now(timezone.utc).strftime("%Y-%m-%d"),
"flows": 0, "rules": {}, "egress": [], "new_dsts": []},
@ -57,7 +60,7 @@ def load(path: Path) -> Dict[str, Any]:
base = empty()
for key, value in base.items():
data.setdefault(key, value)
for key in ("seen", "beacon", "egress_counts", "files", "degraded"):
for key in ("seen", "beacon", "egress_counts", "files", "archives", "degraded"):
if not isinstance(data.get(key), dict):
data[key] = {}
return data