Commit graph netsec-agent/netsec_scan/rules.py
Author SHA1 Message Date
Sirius DevOps
ba1bef3814 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
2026-11-27 02:09:51 -05:00
sirius
be60d74159 netsec-scan: second-tick gate for web-port egress novelty (kill CDN churn)
One CI run produced 20 one-shot AWS/GitHub CDN destinations in a single 5-minute
tick (21-line message, nothing reached the operator only because delivery was
unresolved). First-seen tuples now carry per-tick observation counts in state:
web ports (80/443/8080/8443) need two distinct ticks before alerting, non-web
ports and any DROPPED verdict still alert on first sight. A beacon/exfil
destination is retried; CDN rotation is not.

Also: cron deliver switched to local because this profile has
platforms.telegram.enabled=false (deliver=telegram errors 'no delivery target
resolved'), and the README now documents that constraint.
2026-11-27 00:32:25 -05:00
sirius
c31d46a037 netsec-scan: honest observation window, /dropped tuples, report baseline counts
- first-seen egress is gated by the cumulative seen-set only (deleting a
  fingerprint re-arms the rule); the alert states the observed window
  (~20m / 3.2h / 2.1d) instead of implying the collector holds weeks.
- a DROPPED attempt on a new to-world tuple is keyed separately from forwarded
  traffic to the same destination and graded HIGH.
- daily report counts every external tuple seen that day, not just novel ones.
- drop-prune of the dead state['egress'] map; tests cover the single-fire rearm,
  day counters and the egress union.
- README: measured collector volume/tombstones/partial-tail behaviour, scheduler
  shim path.
2026-11-27 00:24:22 -05:00
sirius
68b2616cc5 netsec-scan: deterministic sensor (6 PromQL tripwires + 2 flow-store novelty rules)
Silent ticks (empty stdout, exit 0), one line per stable fingerprint, cumulative
union-only seen-set at ~/.hermes/cron/netsec-scan-state.json, memoized sensor-
degradation line, daily baseline report. Stdlib only; reads the collector's
JSONL over SSH with per-file byte offsets and Prometheus via the k8s API proxy.
40 unit tests against fixtures recorded from the live collector.
2026-11-27 00:20:46 -05:00