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.
This commit is contained in:
commit
68b2616cc5
19 changed files with 1902 additions and 0 deletions
4
.gitignore
vendored
Normal file
4
.gitignore
vendored
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
__pycache__/
|
||||
*.pyc
|
||||
reports/*.json
|
||||
reports/*.tmp
|
||||
193
README.md
Normal file
193
README.md
Normal file
|
|
@ -0,0 +1,193 @@
|
|||
# netsec-agent
|
||||
|
||||
Deterministic network-security sensor for the Sirius homelab cluster.
|
||||
|
||||
**The LLM never decides whether something is odd.** This program decides, in
|
||||
code, cheaply, and emits **one line per fingerprint**. A Hermes cron job runs it
|
||||
every 5 minutes; its stdout *is* the alert (the gateway owns delivery). Waking an
|
||||
investigator agent on a hit is a separate, deliberate step — not done here.
|
||||
|
||||
```
|
||||
┌──────────────────────────────┐
|
||||
Prometheus ─────▶│ │──▶ stdout: nothing (calm)
|
||||
(kubectl get │ netsec_scan │ or 1 line per fingerprint
|
||||
--raw, read-only)│ │
|
||||
/var/log/netsec ─▶│ (SSH + sudo -n, byte-offset │──▶ state: cumulative seen-set
|
||||
(collector JSONL)│ incremental reads) │──▶ reports/YYYY-MM-DD.json
|
||||
└──────────────────────────────┘
|
||||
```
|
||||
|
||||
## Layout
|
||||
|
||||
| Path | What |
|
||||
|---|---|
|
||||
| `netsec_scan/` | the program (Python 3, **stdlib only** — no `pip install` on the host) |
|
||||
| `netsec_scan/config.py` | every tunable, next to the measurement it came from |
|
||||
| `netsec_scan/rules.py` | the 8 rules |
|
||||
| `netsec_scan/flows.py` | collector access (remote byte-offset reads) + Cilium flow parsing |
|
||||
| `netsec_scan/prom.py` | PromQL through the k8s API proxy |
|
||||
| `netsec_scan/state.py` | cumulative seen-set, offsets, report counters |
|
||||
| `netsec_scan/report.py` | daily baseline report |
|
||||
| `run.sh` | entrypoint (`exec python3 -m netsec_scan "$@"` from the repo root) |
|
||||
| `tests/` | unit tests + 3 small fixtures recorded from the live collector |
|
||||
|
||||
Run it by hand:
|
||||
|
||||
```bash
|
||||
cd ~/Projects/netsec-agent && ./run.sh # silent tick, exit 0
|
||||
./run.sh --verbose # same, diagnostics on stderr
|
||||
./run.sh --fixture tests/fixtures/beacon-shaped.jsonl --dry-run # what-would-I-say
|
||||
python3 -m unittest discover -s tests # 40 tests, no network
|
||||
```
|
||||
|
||||
## Output contract
|
||||
|
||||
| Situation | stdout | exit |
|
||||
|---|---|---|
|
||||
| calm tick | **empty** — no "monitoring N flows" line, ever | 0 |
|
||||
| hit | one line per fingerprint, `SEV <fp12> <rule> <detail>`, ≤ 200 chars | 0 |
|
||||
| sensor input unavailable | one **memoized** line naming the class (`HTTP 503`, `timeout`, `no-flows-file`, …) | non-zero, state file untouched |
|
||||
|
||||
Example:
|
||||
|
||||
```
|
||||
HIGH a3f19c02b7de egress-new-dst osint/osint-app->203.0.113.9:4444/tcp first-seen 03:12Z (no prior in retained window)
|
||||
MEDIUM 0fbb2e28bb07 egress-new-dst flux-system/source-controller->104.18.30.120:443/tcp first-seen 05:10Z (no prior in retained window)
|
||||
```
|
||||
|
||||
**Fingerprint** = `sha256(rule + entity)[:12]`. Never a timestamp, never a
|
||||
count: the same finding keeps the same id across ticks, restarts and days.
|
||||
|
||||
## Dedupe model
|
||||
|
||||
* `seen` is a **cumulative, union-only** map `fp -> {rule, kind, entity, severity, first, last_alert}`,
|
||||
persisted at `~/.hermes/cron/netsec-scan-state.json` (not inside a `{job_id}`
|
||||
directory — the scheduler reclaims those). It is never replaced by the current
|
||||
tick's findings, so a transiently-empty read cannot re-alert history.
|
||||
* **Novelty rules** (`egress-new-dst`, `beacon-shape`) fire **once, ever** per fp.
|
||||
* **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. PromQL findings still speak on the first tick — they are current state.
|
||||
|
||||
## The 8 rules
|
||||
|
||||
Six PromQL tripwires (read-only, via
|
||||
`kubectl get --raw /api/v1/namespaces/monitoring/services/http:kube-prometheus-stack-prometheus:9090/proxy/api/v1/query`)
|
||||
and two flow-store rules (`/var/log/netsec/*.jsonl` on siriussec).
|
||||
|
||||
| # | Rule | Severity | What it detects | Threshold | Backing series (2026-11-27) |
|
||||
|---|---|---|---|---|---|
|
||||
| 1 | `hubble-loss` | HIGH | Hubble ring-buffer loss — the rule that says the other rules are blind | `sum by(node)(rate(hubble_lost_events_total[15m]))` > **0.05/s** | 3 (siriussec 0.60, linode 0.13, rpi 0.00) |
|
||||
| 2 | `drop-spike` | MEDIUM | TCP/UDP drop-rate spike vs a 1 h baseline (ICMPv6 neighbour-discovery noise excluded) | > **0.05/s** and > **3×** 1 h baseline | 4 series by reason/protocol; TCP/ICMPv6 split measured |
|
||||
| 3 | `syn-sweep` | MEDIUM | connects that never complete (SYN without SYN-ACK) | SYN > **1/s** and ratio > **3** | 4 (SYN 10.6/s, SYN-ACK 6.7/s → ratio 1.59 at idle) |
|
||||
| 4 | `rst-storm` | MEDIUM | refused/reset connection storm | RST > **2/s** and > **10×** 6 h average | 1 RST series, 2.5/s at idle |
|
||||
| 5 | `new-port` | LOW | a server-range port (1-32767) that carried flows now but none 24 h ago | `count by(port) … unless … offset 24h` | 131 port series; 4 named ports in 24 h at deploy |
|
||||
| 6 | `http-error-ratio` | MEDIUM | L7 4xx/5xx share shift (public gateway) | > **0.5** of ≥ **0.5 req/s** (15 m) | 20 status series; 2.2 % at idle |
|
||||
| 7 | `egress-new-dst` | HIGH (non-web port) / MEDIUM (80/443) | first-seen `(workload, dst_ip, dst_port)` outside pod/mesh/LAN space — candidate beacon or exfil | no prior in the retained window (cumulative seen-set) | 21 workload→world tuples in the first 15 min captured |
|
||||
| 8 | `beacon-shape` | HIGH | periodic connections from one workload to one `dst:port` — C2 shape | ≥ **20** distinct client sockets in 2 h, inter-arrival **CV < 0.15**, mean interval ≤ 900 s | requires ≥ 20 conns; the busiest real tuple measured 9 sockets / CV 1.57 |
|
||||
|
||||
**Deliberately not implemented** (and why):
|
||||
|
||||
* **Per-workload PromQL rules.** The `pod` label on every `hubble_*` metric is
|
||||
the *Cilium agent* pod (`pod="cilium-vs7sb"`), not the workload. A rule
|
||||
`by (pod)` measures agents and is permanently flat. Workload attribution comes
|
||||
from the flow JSONL instead. No `by (pod)` exists anywhere in this code.
|
||||
* **`hubble_dns_*` / DNS response codes.** The metric family does not exist in
|
||||
this build (0 series).
|
||||
* **HTTP attack-shape text rules** (`../`, `union select`, `.env` probes,
|
||||
scanner UAs). `cilium-envoy` emits **no access log** (audit finding F7, card
|
||||
`t_e662b03a`), so there is no data source. When that card lands, this is where
|
||||
the parser goes.
|
||||
* **`verdict != FORWARDED` as its own rule.** It fires permanently at rest
|
||||
(constant ICMPv6 L3 drops) — a day-one false positive. TCP/UDP drops are
|
||||
covered by rule 2 instead.
|
||||
* **East-west / identity-flip rules.** Useful, but they need a policy baseline
|
||||
that does not exist yet (3 NetworkPolicies cluster-wide). Adding them now would
|
||||
be noise, and noise mutes the channel.
|
||||
|
||||
`new-port` is LOW and `drop-spike` carries a floor for the same reason: a rule
|
||||
that can be made quiet only by hiding a real signal gets dropped instead of
|
||||
tuned, per the design note.
|
||||
|
||||
## Re-deriving a baseline
|
||||
|
||||
Each rule's number is a one-liner. Re-run these before changing a threshold:
|
||||
|
||||
```bash
|
||||
promq() { kubectl get --raw "/api/v1/namespaces/monitoring/services/http:kube-prometheus-stack-prometheus:9090/proxy/api/v1/query?query=$(python3 -c 'import sys,urllib.parse;print(urllib.parse.quote(sys.argv[1]))' "$1")"; }
|
||||
|
||||
promq 'sum by (node) (rate(hubble_lost_events_total[15m]))' # rule 1
|
||||
promq 'sum by (reason,protocol) (rate(hubble_drop_total[5m]))' # rule 2
|
||||
promq 'sum by (flag) (rate(hubble_tcp_flags_total[5m]))' # rules 3-4
|
||||
promq 'count by (port) (hubble_port_distribution_total)' # rule 5
|
||||
promq 'sum(rate(hubble_http_requests_total[15m]))' # rule 6
|
||||
promq 'sum(rate(hubble_http_requests_total{status=~"4..|5.."}[15m]))' # rule 6
|
||||
|
||||
# rules 7-8: what the flow store says this window
|
||||
ssh -i ~/.ssh/lancelot_priv Lancelot@10.10.0.2 'sudo -n cat /var/log/netsec/flows-*.jsonl' \
|
||||
| python3 -c 'import sys,json,collections
|
||||
c=collections.Counter()
|
||||
for l in sys.stdin:
|
||||
f=json.loads(l)["flow"]; ip=f.get("IP") or {}
|
||||
w=(f.get("source") or {}).get("namespace"); d=ip.get("destination")
|
||||
l4=f.get("l4") or {}; p=next(iter(l4),None)
|
||||
if w and d and p: c[(w,d,(l4[p] or {}).get("destination_port"))]+=1
|
||||
for k,v in c.most_common(20): print(v,k)'
|
||||
```
|
||||
|
||||
The daily report (`reports/YYYY-MM-DD.json`) is the same data written down:
|
||||
counts per rule, flows seen that day, egress tuples seen, top 10 new destinations.
|
||||
It is refreshed on every tick (so "today" always exists) and becomes final at the
|
||||
UTC day rollover. No alert is ever raised from it.
|
||||
|
||||
## Where the inputs come from
|
||||
|
||||
* **Flows**: the `netsec/hubble-flow-collector` DaemonSet on siriussec writes
|
||||
filtered JSONL to the host's `/var/log/netsec` (drops, policy verdicts, all L7,
|
||||
and `trace:to-network` whose peer is outside `10.244.0.0/16` + `10.10.0.0/24`).
|
||||
This sensor reads it over SSH as `[email protected]` with `sudo -n`, using a
|
||||
**per-file byte offset** kept in state — a tick pulls only new bytes. It never
|
||||
polls `hubble observe`: the agent ring buffer is ~28 s at 148 flows/s, so a
|
||||
poll is lossy by design.
|
||||
* **Prometheus**: the monitoring Service through the API proxy, read-only, no
|
||||
port-forward, no new credentials.
|
||||
|
||||
### Flow parsing notes (learned the hard way)
|
||||
|
||||
* Anchor field extraction on the `"IP":{…}` object: trace lines carry
|
||||
`"ethernet":{"source":"98:fa:…"}` **before** `IP`, so an unanchored
|
||||
`"source":"` match hands you a MAC.
|
||||
* Workload identity is `namespace/workload` from the peer's `workloads[]` or
|
||||
`k8s:app` label — **never** the pod name, which changes on every rollout and
|
||||
would mint a new fingerprint each deploy.
|
||||
* `reserved:*` peers (host, world, remote-node, ingress) are not workloads. The
|
||||
node's own egress to CDN IPs would otherwise dominate rule 7 with churn.
|
||||
* Destinations in pod/mesh/service/LAN/CGNAT/link-local/multicast space are not
|
||||
egress; documentation ranges (`203.0.113.0/24` & co) are treated as external so
|
||||
a synthetic fixture behaves like a real destination.
|
||||
|
||||
## Deployment
|
||||
|
||||
| Piece | Where |
|
||||
|---|---|
|
||||
| repo | `sirius/netsec-agent` on Forgejo, cloned at `~/Projects/netsec-agent` |
|
||||
| shim | `~/.hermes/scripts/netsec-scan.sh` → `exec /home/lancelot/Projects/netsec-agent/run.sh "$@"` (`chmod +x`: a non-executable shim fails with `Permission denied` **on empty stdout**, which looks exactly like a healthy silent tick) |
|
||||
| cron | Hermes job `netsec-scan`, `no_agent` script job, every 5 minutes, `workdir ~/Projects/netsec-agent`, `script netsec-scan.sh`, `deliver telegram` |
|
||||
| state | `~/.hermes/cron/netsec-scan-state.json` (+ `.memo.json` for degradation wording) |
|
||||
| reports | `~/Projects/netsec-agent/reports/YYYY-MM-DD.json` |
|
||||
|
||||
Blast radius: one program, one shim, one cron job. No cluster writes, no
|
||||
credentials, no LLM call, no secret reads.
|
||||
|
||||
## Verified behaviour (2026-11-27)
|
||||
|
||||
* 40 unit tests pass against recorded fixtures.
|
||||
* First live tick seeded 21 egress tuples and 21 beacon buckets silently, wrote
|
||||
the state file and `reports/2026-11-27.json`.
|
||||
* Single-fire: deleting one key from `seen` re-emits exactly one line, and the
|
||||
immediately following run is silent.
|
||||
* Cron delivery proven through `~/.hermes/cron/executions.db`
|
||||
(`delivery_outcome=delivered`) — see the task handoff for the transcript.
|
||||
10
netsec_scan/__init__.py
Normal file
10
netsec_scan/__init__.py
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
"""netsec-scan — deterministic network-security sensor for the Sirius homelab.
|
||||
|
||||
The LLM never decides whether something is odd: this program decides, in code,
|
||||
and emits one line per fingerprint. Designed to be run by a 5-minute Hermes
|
||||
cron job whose stdout *is* the alert.
|
||||
|
||||
See README.md for the rule set, thresholds and how to re-derive a baseline.
|
||||
"""
|
||||
|
||||
__version__ = "1.0.0"
|
||||
296
netsec_scan/__main__.py
Normal file
296
netsec_scan/__main__.py
Normal file
|
|
@ -0,0 +1,296 @@
|
|||
"""Entry point: one tick of the deterministic sensor.
|
||||
|
||||
Contract (see README):
|
||||
* calm tick -> empty stdout, exit 0
|
||||
* hit -> one line per fingerprint, `SEV <fp> <rule> <detail>` (<= 200 chars)
|
||||
* degradation-> one memoized line naming the failure class, exit non-zero,
|
||||
state file untouched
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import argparse
|
||||
import json
|
||||
import os
|
||||
import sys
|
||||
import time
|
||||
import traceback
|
||||
from datetime import datetime, timezone
|
||||
from pathlib import Path
|
||||
from typing import Any, Dict, List, Optional, Tuple
|
||||
|
||||
from . import config, report, rules, state as state_mod
|
||||
from .flows import (
|
||||
BaseStore,
|
||||
LocalFlowStore,
|
||||
RemoteFlowStore,
|
||||
SingleFileStore,
|
||||
iter_lines,
|
||||
parse_flow,
|
||||
)
|
||||
from .prom import SensorError
|
||||
from .rules import SEVERITY_ORDER, Finding
|
||||
|
||||
|
||||
# ------------------------------------------------------------- helpers ----
|
||||
def log(msg: str, verbose: bool) -> None:
|
||||
if verbose:
|
||||
print("netsec-scan: " + msg, file=sys.stderr)
|
||||
|
||||
|
||||
def memo_path(state_path: Path) -> Path:
|
||||
"""Degradation memo lives beside the state file, never inside it."""
|
||||
return state_path.with_name(state_path.stem + ".memo.json")
|
||||
|
||||
|
||||
def load_memo(path: Path) -> Dict[str, str]:
|
||||
try:
|
||||
data = json.loads(path.read_text())
|
||||
return data if isinstance(data, dict) else {}
|
||||
except (OSError, ValueError):
|
||||
return {}
|
||||
|
||||
|
||||
def save_memo(path: Path, memo: Dict[str, str]) -> None:
|
||||
try:
|
||||
path.parent.mkdir(parents=True, exist_ok=True)
|
||||
tmp = path.with_suffix(path.suffix + ".tmp")
|
||||
tmp.write_text(json.dumps(memo, indent=2, sort_keys=True) + "\n")
|
||||
os.replace(tmp, path)
|
||||
except OSError:
|
||||
pass
|
||||
|
||||
|
||||
def render(finding: Finding) -> str:
|
||||
line = "%s %s %s %s" % (finding.severity, finding.fingerprint,
|
||||
finding.rule, finding.detail)
|
||||
if len(line) > config.MAX_LINE:
|
||||
line = line[: config.MAX_LINE - 1] + "\u2026"
|
||||
return line
|
||||
|
||||
|
||||
def collect_flows(store: BaseStore, st: Dict[str, Any], verbose: bool) -> Tuple[List, int, int]:
|
||||
"""Read every un-consumed byte of every collector file; parse complete lines."""
|
||||
files = store.list_files()
|
||||
parsed = []
|
||||
malformed = 0
|
||||
live = set()
|
||||
for name, size in files:
|
||||
live.add(name)
|
||||
entry = st["files"].get(name) or {"offset": 0, "size": 0}
|
||||
offset = int(entry.get("offset", 0) or 0)
|
||||
if size < offset: # truncated or replaced under us
|
||||
log("file %s shrank (%d < %d); restarting at 0" % (name, size, offset), verbose)
|
||||
offset = 0
|
||||
if size == offset:
|
||||
st["files"][name] = {"offset": offset, "size": size}
|
||||
continue
|
||||
data = store.read_from(name, offset)
|
||||
lines, partial = iter_lines(data)
|
||||
consumed = offset + len(data) - len(partial)
|
||||
for line in lines:
|
||||
line = line.strip()
|
||||
if not line:
|
||||
continue
|
||||
try:
|
||||
obj = json.loads(line)
|
||||
except ValueError:
|
||||
malformed += 1
|
||||
continue
|
||||
flow = parse_flow(obj)
|
||||
if flow is None:
|
||||
malformed += 1
|
||||
continue
|
||||
parsed.append(flow)
|
||||
st["files"][name] = {"offset": consumed, "size": size}
|
||||
log("read %s: %d bytes, %d lines" % (name, len(data), len(lines)), verbose)
|
||||
# Forget files the collector rotated away (their bytes are already consumed).
|
||||
for name in list(st["files"]):
|
||||
if name not in live:
|
||||
st["files"].pop(name, None)
|
||||
return parsed, malformed, len(files)
|
||||
|
||||
|
||||
def apply_dedupe(findings: List[Finding], st: Dict[str, Any], now: float,
|
||||
dry_run: bool) -> List[Finding]:
|
||||
"""Emit each fingerprint once; state rules may re-fire after the cooldown."""
|
||||
emit: List[Finding] = []
|
||||
seen = st["seen"]
|
||||
for finding in findings:
|
||||
prev = seen.get(finding.fingerprint)
|
||||
if dry_run:
|
||||
emit.append(finding)
|
||||
continue
|
||||
if prev is None:
|
||||
seen[finding.fingerprint] = {
|
||||
"rule": finding.rule,
|
||||
"kind": finding.kind,
|
||||
"entity": finding.entity,
|
||||
"severity": finding.severity,
|
||||
"first": datetime.now(timezone.utc).isoformat(timespec="seconds"),
|
||||
"last_alert": datetime.now(timezone.utc).isoformat(timespec="seconds"),
|
||||
}
|
||||
emit.append(finding)
|
||||
continue
|
||||
if finding.kind == "state":
|
||||
try:
|
||||
last = datetime.fromisoformat(prev.get("last_alert", "")).timestamp()
|
||||
except (TypeError, ValueError):
|
||||
last = 0.0
|
||||
if now - last >= config.STATE_COOLDOWN:
|
||||
prev["last_alert"] = datetime.now(timezone.utc).isoformat(timespec="seconds")
|
||||
emit.append(finding)
|
||||
return emit
|
||||
|
||||
|
||||
def record_counters(st: Dict[str, Any], flows: int, emitted: List[Finding],
|
||||
new_egress: List[str], malformed: int) -> None:
|
||||
state_mod.roll_day(st)
|
||||
day = st["day"]
|
||||
day["flows"] = int(day.get("flows", 0)) + flows
|
||||
for finding in emitted:
|
||||
day["rules"][finding.rule] = int(day["rules"].get(finding.rule, 0)) + 1
|
||||
if finding.rule == "egress-new-dst":
|
||||
day["egress"].append(finding.entity)
|
||||
day["new_dsts"].append(
|
||||
{"tuple": finding.entity,
|
||||
"first_seen": datetime.now(timezone.utc).isoformat(timespec="seconds")})
|
||||
st["totals"]["ticks"] = int(st["totals"].get("ticks", 0)) + 1
|
||||
st["totals"]["flows"] = int(st["totals"].get("flows", 0)) + flows
|
||||
st["totals"]["findings"] = int(st["totals"].get("findings", 0)) + len(emitted)
|
||||
st["totals"]["malformed"] = int(st["totals"].get("malformed", 0)) + malformed
|
||||
|
||||
|
||||
# ----------------------------------------------------------------- main ----
|
||||
def parse_args(argv: Optional[List[str]] = None) -> argparse.Namespace:
|
||||
parser = argparse.ArgumentParser(
|
||||
prog="netsec-scan",
|
||||
description="Deterministic netsec sensor: silent when calm, one line per hit.")
|
||||
parser.add_argument("--fixture", help="read this JSONL file instead of the live collector")
|
||||
parser.add_argument("--flows-dir", help="read flows-*.jsonl from this local directory")
|
||||
parser.add_argument("--dry-run", action="store_true",
|
||||
help="print findings without writing state/report and without seen-set dedupe")
|
||||
parser.add_argument("--no-prom", action="store_true", help="skip the PromQL tripwires")
|
||||
parser.add_argument("--state", help="state file path (default ~/.hermes/cron/netsec-scan-state.json)")
|
||||
parser.add_argument("--reports", help="report directory (default ~/Projects/netsec-agent/reports)")
|
||||
parser.add_argument("--verbose", action="store_true", help="debug lines on stderr")
|
||||
return parser.parse_args(argv)
|
||||
|
||||
|
||||
def main(argv: Optional[List[str]] = None) -> int:
|
||||
args = parse_args(argv)
|
||||
state_path = Path(args.state or config.STATE_FILE)
|
||||
reports_dir = Path(args.reports or config.REPORT_DIR)
|
||||
now = time.time()
|
||||
|
||||
if args.fixture:
|
||||
store: BaseStore = SingleFileStore(args.fixture)
|
||||
prom_enabled = False
|
||||
elif args.flows_dir:
|
||||
store = LocalFlowStore(args.flows_dir)
|
||||
prom_enabled = not args.no_prom
|
||||
else:
|
||||
store = RemoteFlowStore()
|
||||
prom_enabled = not args.no_prom
|
||||
|
||||
try:
|
||||
st = state_mod.load(state_path)
|
||||
except SensorError as exc:
|
||||
print("SENSOR %s netsec-scan: %s" % (exc.cls, exc.detail or exc.cls))
|
||||
return 2
|
||||
|
||||
try:
|
||||
flows, malformed, file_count = collect_flows(store, st, args.verbose)
|
||||
log("parsed %d flows from %d file(s), %d malformed"
|
||||
% (len(flows), file_count, malformed), args.verbose)
|
||||
|
||||
findings: List[Finding] = []
|
||||
if prom_enabled:
|
||||
for rule in rules.PROM_RULES:
|
||||
try:
|
||||
findings.extend(rule(_prommod()))
|
||||
except SensorError:
|
||||
raise
|
||||
except Exception as exc: # a broken rule must not eat the tick
|
||||
log("rule %s failed: %s" % (rule.__name__, exc), args.verbose)
|
||||
raise SensorError("prom-error", "%s: %s" % (rule.__name__, exc))
|
||||
|
||||
seeding = not st.get("seeded")
|
||||
new_egress = rules.rule_egress_first_seen(flows, st["egress"], _utcnow())
|
||||
beacon = rules.rule_beacon(flows, st["beacon"], now)
|
||||
rules.prune_beacon(st["beacon"], now)
|
||||
flow_findings = new_egress + beacon
|
||||
|
||||
if seeding and not args.dry_run:
|
||||
# Baseline run: record history silently instead of dumping the
|
||||
# retained window into chat. PromQL findings still speak (they are
|
||||
# current state, not history).
|
||||
for finding in flow_findings:
|
||||
st["seen"].setdefault(finding.fingerprint, {
|
||||
"rule": finding.rule, "kind": finding.kind, "entity": finding.entity,
|
||||
"severity": finding.severity,
|
||||
"first": datetime.now(timezone.utc).isoformat(timespec="seconds"),
|
||||
"last_alert": datetime.now(timezone.utc).isoformat(timespec="seconds"),
|
||||
"seeded": True,
|
||||
})
|
||||
st["seeded"] = True
|
||||
st["seeded_at"] = datetime.now(timezone.utc).isoformat(timespec="seconds")
|
||||
log("seed run: %d flow findings recorded silently" % len(flow_findings),
|
||||
args.verbose)
|
||||
flow_findings = []
|
||||
|
||||
emitted = apply_dedupe(findings + flow_findings, st, now, args.dry_run)
|
||||
|
||||
record_counters(st, len(flows), emitted, new_egress, malformed)
|
||||
state_mod.prune(st)
|
||||
|
||||
if not args.dry_run:
|
||||
state_mod.save(state_path, st)
|
||||
report.write(st, reports_dir)
|
||||
|
||||
except SensorError as exc:
|
||||
return degrade(state_path, exc, args.verbose)
|
||||
except Exception as exc: # never fail silently
|
||||
traceback.print_exc(file=sys.stderr)
|
||||
return degrade(state_path, SensorError("internal-error", str(exc)[:160]), args.verbose)
|
||||
|
||||
emitted.sort(key=lambda f: (SEVERITY_ORDER.get(f.severity, 9), f.rule, f.entity))
|
||||
for finding in emitted:
|
||||
print(render(finding))
|
||||
return 0
|
||||
|
||||
|
||||
def _utcnow() -> datetime:
|
||||
return datetime.now(timezone.utc)
|
||||
|
||||
|
||||
def _prommod():
|
||||
from . import prom
|
||||
return prom
|
||||
|
||||
|
||||
def degrade(state_path: Path, exc: SensorError, verbose: bool) -> int:
|
||||
"""One memoized line per failure class; state file is never touched."""
|
||||
memo_file = memo_path(state_path)
|
||||
memo = load_memo(memo_file)
|
||||
now = time.time()
|
||||
last = memo.get(exc.cls)
|
||||
announce = True
|
||||
if last:
|
||||
try:
|
||||
announce = (now - datetime.fromisoformat(last).timestamp()) >= config.DEGRADED_MEMO
|
||||
except (TypeError, ValueError):
|
||||
announce = True
|
||||
if announce:
|
||||
detail = exc.detail or exc.cls
|
||||
print("SENSOR %s netsec-scan: sensor input unavailable (%s)" % (exc.cls, detail))
|
||||
memo[exc.cls] = datetime.now(timezone.utc).isoformat(timespec="seconds")
|
||||
save_memo(memo_file, memo)
|
||||
if verbose:
|
||||
print("netsec-scan: degraded class=%s detail=%s" % (exc.cls, exc.detail),
|
||||
file=sys.stderr)
|
||||
return 1
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
sys.exit(main())
|
||||
121
netsec_scan/config.py
Normal file
121
netsec_scan/config.py
Normal file
|
|
@ -0,0 +1,121 @@
|
|||
"""Every tunable in one place, with the measurement it came from.
|
||||
|
||||
Thresholds are deliberately conservative in the sense of *few, quiet rules*
|
||||
rather than tight numbers: a rule that fires on ordinary traffic gets the whole
|
||||
channel muted. Each value below was checked against live data on 2026-11-27
|
||||
(see README "Baselines").
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import os
|
||||
from pathlib import Path
|
||||
|
||||
HOME = Path.home()
|
||||
|
||||
# ---------------------------------------------------------------- paths ----
|
||||
# The state file must NOT live inside a {job_id} dir: the scheduler reclaims
|
||||
# those. ~/.hermes/cron/ is stable.
|
||||
STATE_FILE = Path(
|
||||
os.environ.get("NETSEC_SCAN_STATE", HOME / ".hermes" / "cron" / "netsec-scan-state.json")
|
||||
)
|
||||
REPORT_DIR = Path(
|
||||
os.environ.get("NETSEC_SCAN_REPORTS", HOME / "Projects" / "netsec-agent" / "reports")
|
||||
)
|
||||
|
||||
# ------------------------------------------------- collector (remote) ----
|
||||
# The collector is a DaemonSet on siriussec writing hostPath /var/log/netsec.
|
||||
# The sensor runs on the admin host, so it reads those files over SSH with
|
||||
# `sudo -n` (NOPASSWD is configured for Lancelot). Never poll hubble directly:
|
||||
# the agent ring buffer is ~28 s at 148 flows/s, so a poll is lossy by design.
|
||||
SSH_HOST = os.environ.get("NETSEC_SCAN_SSH_HOST", "[email protected]")
|
||||
SSH_KEY = os.environ.get("NETSEC_SCAN_SSH_KEY", str(HOME / ".ssh" / "lancelot_priv"))
|
||||
SSH_TIMEOUT = int(os.environ.get("NETSEC_SCAN_SSH_TIMEOUT", "60"))
|
||||
FLOW_DIR = os.environ.get("NETSEC_SCAN_FLOW_DIR", "/var/log/netsec")
|
||||
FLOW_PATTERN = os.environ.get("NETSEC_SCAN_FLOW_PATTERN", "flows-*.jsonl")
|
||||
FLOW_GLOB = FLOW_DIR + "/" + FLOW_PATTERN
|
||||
|
||||
# ----------------------------------------------------- prometheus ----
|
||||
PROM_PROXY = (
|
||||
"/api/v1/namespaces/monitoring/services/"
|
||||
"http:kube-prometheus-stack-prometheus:9090/proxy"
|
||||
)
|
||||
PROM_TIMEOUT = int(os.environ.get("NETSEC_SCAN_PROM_TIMEOUT", "25"))
|
||||
|
||||
# ----------------------------------------------------- thresholds ----
|
||||
# Hubble pipeline loss: events/s over 15m. Measured 0.60/s siriussec, 0.13/s
|
||||
# linode, 0.00/s rpi at idle — i.e. the sensor is already blind to ~0.7 % of
|
||||
# traffic. This rule exists so the other rules cannot lie about being calm.
|
||||
LOST_EVENTS_RATE = 0.05
|
||||
|
||||
# TCP/UDP drops (ICMPv6 UNSUPPORTED_L3_PROTOCOL excluded — it is constant
|
||||
# neighbour-discovery noise at ~0.39/s and would mask a real spike).
|
||||
DROP_FLOOR = 0.05 # events/s; below this a "spike" is one packet
|
||||
DROP_RATIO = 3.0 # vs the 1h baseline rate
|
||||
|
||||
# SYN without SYN-ACK (connect sweep). Measured 1.59 at idle; ring-buffer loss
|
||||
# also nudges it up, hence the 3x gate and the absolute floor.
|
||||
SYN_RATIO = 3.0
|
||||
SYN_FLOOR = 1.0 # SYN/s
|
||||
|
||||
# RST storm: 10x the 6h average. Measured 2.5/s at idle (ephemeral-port churn).
|
||||
RST_RATIO = 10.0
|
||||
RST_FLOOR = 2.0 # RST/s
|
||||
|
||||
# L7 error share. Measured 0.15/s errors of 6.9/s requests (2.2 %).
|
||||
HTTP_ERROR_RATIO = 0.5
|
||||
HTTP_MIN_RATE = 0.5 # requests/s, so a single 404 in a quiet minute cannot trip it
|
||||
|
||||
# Ports below the Linux ephemeral range (32768-60999) that appear in
|
||||
# hubble_port_distribution_total for the first time in 24h are treated as new
|
||||
# listeners. Without the cut, every client source port is a "new port".
|
||||
NEW_PORT_CEILING = 32768
|
||||
NEW_PORT_LOOKBACK = "24h"
|
||||
|
||||
# Flow-store novelty.
|
||||
BEACON_MIN_CONNS = 20 # connections (distinct client sockets) from one workload to one dst:port
|
||||
BEACON_MAX_CV = 0.15 # coefficient of variation of inter-arrival times
|
||||
BEACON_WINDOW = 7200 # seconds of connection history kept per tuple (2h)
|
||||
BEACON_MAX_INTERVAL = 900.0 # mean interval ceiling; 30s beacons fit, 1h cron-ish traffic does not
|
||||
|
||||
# Severity for a first-seen egress tuple: standard web ports are common CDN
|
||||
# churn, everything else is a much stronger beacon/exfil signal.
|
||||
WEB_PORTS = frozenset({80, 443, 8080, 8443})
|
||||
|
||||
# Re-alert cooldown for *state* tripwires (current-condition rules). Flow
|
||||
# novelty is permanent: a tuple fires exactly once, ever. A state rule gets to
|
||||
# fire again after this window so "it broke, was fixed, and broke again" is not
|
||||
# silently forgotten.
|
||||
STATE_COOLDOWN = 86400 # 24h
|
||||
|
||||
# Sensor degradation memo: the same class of failure is announced once per
|
||||
# window, not every 5 minutes.
|
||||
DEGRADED_MEMO = 6 * 3600
|
||||
|
||||
# State bounds (a cumulative seen-set cannot grow forever).
|
||||
MAX_SEEN = 20000
|
||||
MAX_EGRESS = 20000
|
||||
MAX_BEACON_TUPLES = 2000
|
||||
MAX_DAY_EGRESS = 500
|
||||
|
||||
# Output contract.
|
||||
MAX_LINE = 200
|
||||
|
||||
# Local network space. Anything not "global" is not egress; these are explicit
|
||||
# so the rule reads correctly even if a future Python changes is_global.
|
||||
NON_EGRESS_NETS = (
|
||||
"0.0.0.0/8",
|
||||
"10.0.0.0/8", # includes pod 10.244/16, mesh 10.10/24, service 10.96/12
|
||||
"100.64.0.0/10", # CGNAT (tailnet)
|
||||
"127.0.0.0/8",
|
||||
"169.254.0.0/16",
|
||||
"172.16.0.0/12",
|
||||
"192.168.0.0/16", # homelab LAN
|
||||
"::1/128",
|
||||
"fc00::/7",
|
||||
"fe80::/10",
|
||||
"ff00::/8",
|
||||
)
|
||||
|
||||
KUBECTL_CANDIDATES = ("kubectl", "/usr/sbin/kubectl", "/usr/bin/kubectl", "/usr/local/bin/kubectl")
|
||||
SSH_CANDIDATES = ("ssh", "/usr/sbin/ssh", "/usr/bin/ssh")
|
||||
306
netsec_scan/flows.py
Normal file
306
netsec_scan/flows.py
Normal file
|
|
@ -0,0 +1,306 @@
|
|||
"""Flow-store access and parsing.
|
||||
|
||||
Two sources, one parser:
|
||||
|
||||
* `RemoteFlowStore` reads the collector's JSONL on siriussec over SSH with a
|
||||
per-file byte offset, so a 5-minute tick pulls only the new bytes (the whole
|
||||
retained window is <= 1 GiB, but 900 MiB every tick would be absurd).
|
||||
* `LocalFlowStore` reads a directory (tests, fixtures, dev).
|
||||
|
||||
Only complete lines are consumed; a trailing partial line is carried in state
|
||||
and re-parented to the next tick.
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import hashlib
|
||||
import ipaddress
|
||||
import json
|
||||
import os
|
||||
import shlex
|
||||
import shutil
|
||||
import subprocess
|
||||
from dataclasses import dataclass, field
|
||||
from datetime import datetime, timezone
|
||||
from pathlib import Path
|
||||
from typing import Dict, Iterable, List, Optional, Tuple
|
||||
|
||||
from . import config
|
||||
from .prom import SensorError
|
||||
|
||||
_LOCAL_NETS = tuple(ipaddress.ip_network(n) for n in config.NON_EGRESS_NETS)
|
||||
# Documentation ranges are not routable, so nothing legitimate ever talks to
|
||||
# them — which makes them a fine destination for fixtures and for a synthetic
|
||||
# single-line demo. Python >= 3.13 classifies them `is_private`, so they are
|
||||
# whitelisted here explicitly rather than left to a version-dependent flag.
|
||||
_DOC_NETS = (
|
||||
ipaddress.ip_network("192.0.2.0/24"),
|
||||
ipaddress.ip_network("198.51.100.0/24"),
|
||||
ipaddress.ip_network("203.0.113.0/24"),
|
||||
ipaddress.ip_network("2001:db8::/32"),
|
||||
)
|
||||
|
||||
# Peers carrying any of these prefixes are not workloads (nodes, world, the
|
||||
# gateway). `reserved:remote-node` / `reserved:host` egress is the node's own
|
||||
# software fetching things — attributing novelty to it produces CDN-IP churn,
|
||||
# not security signal.
|
||||
_RESERVED_PREFIX = "reserved:"
|
||||
|
||||
|
||||
def parse_ts(text: str) -> Optional[datetime]:
|
||||
if not text:
|
||||
return None
|
||||
try:
|
||||
return datetime.fromisoformat(text.replace("Z", "+00:00"))
|
||||
except ValueError:
|
||||
return None
|
||||
|
||||
|
||||
def is_external(ip: Optional[str]) -> bool:
|
||||
"""True only for a globally routable unicast destination outside local space.
|
||||
|
||||
Deliberately not `addr.is_global`: since Python 3.13 that returns False for
|
||||
documentation ranges (203.0.113.0/24 & co), which would make a synthetic
|
||||
beacon fixture invisible. Private/link-local/multicast/loopback/reserved
|
||||
are excluded explicitly, and NON_EGRESS_NETS covers the homelab's real
|
||||
address space (pod CIDR, mesh, LAN, CGNAT/tailnet).
|
||||
"""
|
||||
if not ip:
|
||||
return False
|
||||
try:
|
||||
addr = ipaddress.ip_address(ip)
|
||||
except ValueError:
|
||||
return False
|
||||
if any(addr in net for net in _LOCAL_NETS):
|
||||
return False
|
||||
if any(addr in net for net in _DOC_NETS):
|
||||
return True
|
||||
if (addr.is_private or addr.is_multicast or addr.is_link_local
|
||||
or addr.is_loopback or addr.is_unspecified or addr.is_reserved):
|
||||
return False
|
||||
return True
|
||||
|
||||
|
||||
def workload_name(peer: Optional[dict]) -> Optional[str]:
|
||||
"""Stable workload identity (`namespace/name`) for a Cilium peer.
|
||||
|
||||
Pod names change on every rollout, so a fingerprint built from
|
||||
`pod_name` would re-alert on every deploy. Prefer the workload object, then
|
||||
the app labels, and only fall back to a de-hashed pod name.
|
||||
"""
|
||||
if not isinstance(peer, dict):
|
||||
return None
|
||||
labels = peer.get("labels") or []
|
||||
if any(str(lbl).startswith(_RESERVED_PREFIX) for lbl in labels):
|
||||
return None
|
||||
ns = peer.get("namespace") or ""
|
||||
for lbl in labels:
|
||||
if lbl.startswith("k8s:io.kubernetes.pod.namespace="):
|
||||
ns = ns or lbl.split("=", 1)[1]
|
||||
name = None
|
||||
for wl in peer.get("workloads") or []:
|
||||
if isinstance(wl, dict) and wl.get("name"):
|
||||
name = wl["name"]
|
||||
break
|
||||
if not name:
|
||||
for lbl in labels:
|
||||
for key in ("k8s:app=", "k8s:app.kubernetes.io/name="):
|
||||
if lbl.startswith(key):
|
||||
name = lbl[len(key):]
|
||||
break
|
||||
if name:
|
||||
break
|
||||
if not name:
|
||||
pod = peer.get("pod_name")
|
||||
if pod:
|
||||
# strip a Deployment/ReplicaSet suffix: name-hash1-hash2
|
||||
parts = pod.split("-")
|
||||
if len(parts) >= 3 and len(parts[-1]) >= 5 and len(parts[-2]) >= 5:
|
||||
name = "-".join(parts[:-2])
|
||||
else:
|
||||
name = pod
|
||||
if not name:
|
||||
return None
|
||||
return f"{ns}/{name}" if ns else name
|
||||
|
||||
|
||||
@dataclass
|
||||
class Flow:
|
||||
time: Optional[datetime]
|
||||
type: str
|
||||
verdict: str
|
||||
src_ip: Optional[str]
|
||||
dst_ip: Optional[str]
|
||||
proto: Optional[str]
|
||||
src_port: Optional[int]
|
||||
dst_port: Optional[int]
|
||||
src_workload: Optional[str]
|
||||
dst_workload: Optional[str]
|
||||
event_type: Optional[int] = None
|
||||
keys: Tuple[str, ...] = field(default_factory=tuple)
|
||||
|
||||
|
||||
def _peer_ports(l4: dict, proto: str) -> Tuple[Optional[int], Optional[int]]:
|
||||
body = l4.get(proto) if isinstance(l4, dict) else None
|
||||
if not isinstance(body, dict):
|
||||
return None, None
|
||||
sp, dp = body.get("source_port"), body.get("destination_port")
|
||||
return (int(sp) if isinstance(sp, int) else None, int(dp) if isinstance(dp, int) else None)
|
||||
|
||||
|
||||
def parse_flow(obj: dict) -> Optional[Flow]:
|
||||
flow = obj.get("flow") if isinstance(obj, dict) else None
|
||||
if not isinstance(flow, dict):
|
||||
return None
|
||||
ip = flow.get("IP") or {}
|
||||
src_ip, dst_ip = ip.get("source"), ip.get("destination")
|
||||
if not src_ip or not dst_ip:
|
||||
# ARP/non-IP trace events and any malformed line are unusable to every
|
||||
# rule here; counting them as parsed would inflate the flow counters.
|
||||
return None
|
||||
l4 = flow.get("l4") or {}
|
||||
proto = next(iter(l4), None) if isinstance(l4, dict) else None
|
||||
sp, dp = _peer_ports(l4, proto) if proto else (None, None)
|
||||
etype = (flow.get("event_type") or {}).get("type")
|
||||
return Flow(
|
||||
time=parse_ts(flow.get("time") or ""),
|
||||
type=str(flow.get("Type") or ""),
|
||||
verdict=str(flow.get("verdict") or ""),
|
||||
src_ip=src_ip,
|
||||
dst_ip=dst_ip,
|
||||
proto=proto,
|
||||
src_port=sp,
|
||||
dst_port=dp,
|
||||
src_workload=workload_name(flow.get("source")),
|
||||
dst_workload=workload_name(flow.get("destination")),
|
||||
event_type=etype if isinstance(etype, int) else None,
|
||||
)
|
||||
|
||||
|
||||
def iter_lines(data: bytes) -> Tuple[List[str], bytes]:
|
||||
"""Split a byte chunk into complete lines, returning the trailing partial."""
|
||||
if not data:
|
||||
return [], b""
|
||||
idx = data.rfind(b"\n")
|
||||
if idx < 0:
|
||||
return [], data
|
||||
complete = data[:idx].decode("utf-8", "replace")
|
||||
return complete.split("\n"), data[idx + 1:]
|
||||
|
||||
|
||||
# --------------------------------------------------------------- stores ----
|
||||
class BaseStore:
|
||||
def list_files(self) -> List[Tuple[str, int]]:
|
||||
raise NotImplementedError
|
||||
|
||||
def read_from(self, name: str, offset: int) -> bytes:
|
||||
raise NotImplementedError
|
||||
|
||||
|
||||
def _ssh_bin() -> str:
|
||||
for cand in config.SSH_CANDIDATES:
|
||||
if cand.startswith("/"):
|
||||
if os.path.exists(cand):
|
||||
return cand
|
||||
else:
|
||||
found = shutil.which(cand)
|
||||
if found:
|
||||
return found
|
||||
raise SensorError("no-ssh", "ssh client not found")
|
||||
|
||||
|
||||
class RemoteFlowStore(BaseStore):
|
||||
def __init__(self, host: str = None, key: str = None):
|
||||
self.host = host or config.SSH_HOST
|
||||
self.key = key or config.SSH_KEY
|
||||
|
||||
def _run(self, remote_cmd: str) -> "subprocess.CompletedProcess":
|
||||
try:
|
||||
return subprocess.run(
|
||||
[
|
||||
_ssh_bin(), "-i", self.key,
|
||||
"-o", "BatchMode=yes",
|
||||
"-o", "ConnectTimeout=10",
|
||||
"-o", "ServerAliveInterval=5",
|
||||
"-o", "ServerAliveCountMax=4",
|
||||
self.host, remote_cmd,
|
||||
],
|
||||
capture_output=True, timeout=config.SSH_TIMEOUT,
|
||||
)
|
||||
except subprocess.TimeoutExpired:
|
||||
raise SensorError("ssh-timeout", "ssh to %s exceeded %ss" % (self.host, config.SSH_TIMEOUT))
|
||||
|
||||
def list_files(self) -> List[Tuple[str, int]]:
|
||||
# `find -printf` rather than a shell glob: the glob must not be quoted
|
||||
# (quoted == literal, stat fails) and must not be unquoted (shell
|
||||
# injection surface). find needs neither.
|
||||
cmd = "sudo -n find %s -maxdepth 1 -type f -name %s -printf '%%f %%s\\n'" % (
|
||||
shlex.quote(config.FLOW_DIR), shlex.quote(config.FLOW_PATTERN))
|
||||
proc = self._run(cmd)
|
||||
out = proc.stdout.decode("utf-8", "replace")
|
||||
if proc.returncode != 0:
|
||||
err = proc.stderr.decode("utf-8", "replace").strip()
|
||||
if "No such file" in err or "cannot" in err and "stat" in err:
|
||||
raise SensorError("no-flows-file",
|
||||
"no JSONL under %s on %s" % (config.FLOW_DIR, self.host))
|
||||
if "sudo" in err.lower() or "password" in err.lower():
|
||||
raise SensorError("sudo-denied", err[:160])
|
||||
raise SensorError("ssh-fail", err[:160])
|
||||
files = []
|
||||
for line in out.splitlines():
|
||||
parts = line.rsplit(" ", 1)
|
||||
if len(parts) != 2 or not parts[1].isdigit():
|
||||
continue
|
||||
files.append((os.path.basename(parts[0]), int(parts[1])))
|
||||
if not files:
|
||||
raise SensorError("no-flows-file", "collector directory is empty on %s" % self.host)
|
||||
return files
|
||||
|
||||
def read_from(self, name: str, offset: int) -> bytes:
|
||||
path = os.path.join(config.FLOW_DIR, os.path.basename(name))
|
||||
# tail -c +N is 1-based: +1 is the first byte.
|
||||
cmd = "sudo -n tail -c +%d %s" % (offset + 1, shlex.quote(path))
|
||||
proc = self._run(cmd)
|
||||
if proc.returncode != 0:
|
||||
err = proc.stderr.decode("utf-8", "replace").strip()
|
||||
raise SensorError("ssh-fail", err[:160] or "tail failed")
|
||||
return proc.stdout
|
||||
|
||||
|
||||
class LocalFlowStore(BaseStore):
|
||||
"""For tests, fixtures and local re-runs against a copied collector dir."""
|
||||
|
||||
def __init__(self, directory: str):
|
||||
self.directory = Path(directory)
|
||||
|
||||
def list_files(self) -> List[Tuple[str, int]]:
|
||||
files = []
|
||||
for path in sorted(self.directory.glob("flows-*.jsonl")):
|
||||
files.append((path.name, path.stat().st_size))
|
||||
if not files:
|
||||
raise SensorError("no-flows-file", "no flows-*.jsonl in %s" % self.directory)
|
||||
return files
|
||||
|
||||
def read_from(self, name: str, offset: int) -> bytes:
|
||||
data = (self.directory / name).read_bytes()
|
||||
return data[offset:]
|
||||
|
||||
|
||||
class SingleFileStore(BaseStore):
|
||||
"""One fixture file, read whole; used by --fixture."""
|
||||
|
||||
def __init__(self, path: str):
|
||||
self.path = Path(path)
|
||||
|
||||
def list_files(self) -> List[Tuple[str, int]]:
|
||||
if not self.path.is_file():
|
||||
raise SensorError("no-flows-file", "fixture not found: %s" % self.path)
|
||||
return [(self.path.name, self.path.stat().st_size)]
|
||||
|
||||
def read_from(self, name: str, offset: int) -> bytes:
|
||||
return self.path.read_bytes()[offset:]
|
||||
|
||||
|
||||
def fingerprint(kind: str, entity: str) -> str:
|
||||
"""Stable id of (rule, entity). Never includes a timestamp or a count."""
|
||||
return hashlib.sha256(f"{kind}|{entity}".encode("utf-8")).hexdigest()[:12]
|
||||
81
netsec_scan/prom.py
Normal file
81
netsec_scan/prom.py
Normal file
|
|
@ -0,0 +1,81 @@
|
|||
"""Read-only Prometheus access through the Kubernetes API proxy.
|
||||
|
||||
No port-forward, no extra credentials: `kubectl get --raw` against the
|
||||
monitoring Service proxy works from the admin host as the operator.
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import json
|
||||
import os
|
||||
import shutil
|
||||
import subprocess
|
||||
import urllib.parse
|
||||
from typing import Iterable, List, Tuple
|
||||
|
||||
from . import config
|
||||
|
||||
|
||||
class SensorError(Exception):
|
||||
"""A sensor input is unavailable. `cls` is the memoizable failure class."""
|
||||
|
||||
def __init__(self, cls: str, detail: str = ""):
|
||||
super().__init__(detail or cls)
|
||||
self.cls = cls
|
||||
self.detail = detail
|
||||
|
||||
|
||||
def _which(candidates: Iterable[str]) -> str:
|
||||
for cand in candidates:
|
||||
path = shutil.which(cand) if not cand.startswith("/") else (cand if os.path.exists(cand) else None)
|
||||
if path:
|
||||
return path
|
||||
raise SensorError("no-kubectl", "kubectl not found in PATH")
|
||||
|
||||
|
||||
def _classify(text: str) -> str:
|
||||
low = text.lower()
|
||||
if "503" in low or "serviceunavailable" in low or "service unavailable" in low:
|
||||
return "HTTP 503"
|
||||
if "timeout" in low or "timed out" in low or "deadline" in low:
|
||||
return "timeout"
|
||||
if "connection refused" in low or "no such host" in low:
|
||||
return "api-unreachable"
|
||||
return "prom-error"
|
||||
|
||||
|
||||
def raw(path: str) -> dict:
|
||||
kubectl = _which(config.KUBECTL_CANDIDATES)
|
||||
try:
|
||||
proc = subprocess.run(
|
||||
[kubectl, "get", "--raw", path],
|
||||
capture_output=True, text=True, timeout=config.PROM_TIMEOUT,
|
||||
)
|
||||
except subprocess.TimeoutExpired:
|
||||
raise SensorError("timeout", "kubectl get --raw exceeded %ss" % config.PROM_TIMEOUT)
|
||||
if proc.returncode != 0:
|
||||
raise SensorError(_classify(proc.stderr or proc.stdout), (proc.stderr or "").strip()[:200])
|
||||
try:
|
||||
return json.loads(proc.stdout)
|
||||
except ValueError:
|
||||
raise SensorError("prom-bad-json", proc.stdout[:120])
|
||||
|
||||
|
||||
def query(expr: str) -> List[Tuple[dict, float]]:
|
||||
"""Instant query. Returns [(metric_labels, value)] or raises SensorError."""
|
||||
path = config.PROM_PROXY + "/api/v1/query?query=" + urllib.parse.quote(expr)
|
||||
payload = raw(path)
|
||||
if payload.get("status") != "success":
|
||||
raise SensorError("prom-error", str(payload.get("error", ""))[:160])
|
||||
out: List[Tuple[dict, float]] = []
|
||||
for series in payload["data"]["result"]:
|
||||
try:
|
||||
out.append((series.get("metric") or {}, float(series["value"][1])))
|
||||
except (KeyError, IndexError, ValueError):
|
||||
continue
|
||||
return out
|
||||
|
||||
|
||||
def scalar(expr: str) -> float:
|
||||
"""Sum of an (expected single-series) query; 0.0 when it matches nothing."""
|
||||
return sum(v for _, v in query(expr))
|
||||
47
netsec_scan/report.py
Normal file
47
netsec_scan/report.py
Normal file
|
|
@ -0,0 +1,47 @@
|
|||
"""Daily baseline report — no alert, just the numbers thresholds get tuned from.
|
||||
|
||||
Written to `reports/YYYY-MM-DD.json` on every tick, so the file for "today"
|
||||
always exists and carries real counts; it becomes final at the UTC day
|
||||
rollover when a new file starts.
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import json
|
||||
import os
|
||||
from datetime import datetime, timezone
|
||||
from pathlib import Path
|
||||
from typing import Any, Dict
|
||||
|
||||
from . import config
|
||||
|
||||
|
||||
def build(state: Dict[str, Any]) -> Dict[str, Any]:
|
||||
day = state.get("day") or {}
|
||||
egress = day.get("egress", [])
|
||||
new_dsts = day.get("new_dsts", [])
|
||||
rules = day.get("rules", {})
|
||||
flows = int(day.get("flows", 0))
|
||||
return {
|
||||
"date": day.get("date"),
|
||||
"generated_at": datetime.now(timezone.utc).isoformat(timespec="seconds"),
|
||||
"flows": flows,
|
||||
"findings_emitted": {k: int(v) for k, v in sorted(rules.items())},
|
||||
"findings_total": sum(int(v) for v in rules.values() if str(v).isdigit()),
|
||||
"egress_tuples_seen": len(egress),
|
||||
"egress_tuples": sorted(egress),
|
||||
"top_new_destinations": new_dsts[-10:],
|
||||
"seen_fingerprints_cumulative": len(state.get("seen", {})),
|
||||
"state_totals": state.get("totals", {}),
|
||||
}
|
||||
|
||||
|
||||
def write(state: Dict[str, Any], directory: Path = None) -> Path:
|
||||
directory = Path(directory or config.REPORT_DIR)
|
||||
directory.mkdir(parents=True, exist_ok=True)
|
||||
day = (state.get("day") or {}).get("date") or datetime.now(timezone.utc).strftime("%Y-%m-%d")
|
||||
path = directory / f"{day}.json"
|
||||
tmp = path.with_suffix(".json.tmp")
|
||||
tmp.write_text(json.dumps(build(state), indent=2, sort_keys=True) + "\n")
|
||||
os.replace(tmp, path)
|
||||
return path
|
||||
242
netsec_scan/rules.py
Normal file
242
netsec_scan/rules.py
Normal file
|
|
@ -0,0 +1,242 @@
|
|||
"""The eight rules. Deterministic: a rule either trips on code or it doesn't.
|
||||
|
||||
Six PromQL tripwires + two flow-store novelty rules. Nothing here is allowed to
|
||||
use the `pod` label on a `hubble_*` metric: it is the Cilium *agent* pod, so a
|
||||
per-workload PromQL rule would measure agents forever. Workload attribution
|
||||
comes from the flow JSONL instead.
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import statistics
|
||||
import time
|
||||
from dataclasses import dataclass, field
|
||||
from datetime import datetime, timezone
|
||||
from typing import Dict, Iterable, List, Optional, Tuple
|
||||
|
||||
from . import config
|
||||
from .flows import Flow, fingerprint, is_external
|
||||
|
||||
|
||||
@dataclass
|
||||
class Finding:
|
||||
rule: str
|
||||
kind: str # "state" (cooldown) | "novelty" (fire once, ever)
|
||||
severity: str # HIGH | MEDIUM | LOW
|
||||
entity: str
|
||||
detail: str
|
||||
fingerprint: str = field(default="")
|
||||
|
||||
def __post_init__(self) -> None:
|
||||
if not self.fingerprint:
|
||||
self.fingerprint = fingerprint(self.rule, self.entity)
|
||||
|
||||
|
||||
SEVERITY_ORDER = {"HIGH": 0, "MEDIUM": 1, "LOW": 2}
|
||||
|
||||
|
||||
def _ts(t: Optional[datetime]) -> str:
|
||||
if not t:
|
||||
return "??:??Z"
|
||||
return t.astimezone(timezone.utc).strftime("%H:%MZ")
|
||||
|
||||
|
||||
# ------------------------------------------------------- PromQL rules ----
|
||||
def rule_lost_events(prom) -> List[Finding]:
|
||||
"""Hubble ring-buffer loss — the rule that says the others are blind."""
|
||||
out = []
|
||||
for labels, value in prom.query("sum by (node) (rate(hubble_lost_events_total[15m]))"):
|
||||
if value > config.LOST_EVENTS_RATE:
|
||||
node = labels.get("node", "?")
|
||||
out.append(Finding(
|
||||
rule="hubble-loss", kind="state", severity="HIGH",
|
||||
entity="node=%s" % node,
|
||||
detail="node=%s lost %.2f events/s over 15m (ring buffer) - other rules are blind to that share"
|
||||
% (node, value),
|
||||
))
|
||||
return out
|
||||
|
||||
|
||||
def rule_drop_spike(prom) -> List[Finding]:
|
||||
"""TCP/UDP drop-rate spike against a 1 h baseline.
|
||||
|
||||
ICMPv6 UNSUPPORTED_L3_PROTOCOL is excluded: it is constant neighbour
|
||||
discovery (~0.39/s), and including it means the baseline can never be
|
||||
zero, so a real TCP drop spike is diluted.
|
||||
"""
|
||||
sel = 'hubble_drop_total{protocol!="ICMPv6"}'
|
||||
cur = prom.scalar("sum(rate(%s[5m]))" % sel)
|
||||
base = prom.scalar("sum(rate(%s[1h] offset 5m))" % sel)
|
||||
if cur > config.DROP_FLOOR and cur > config.DROP_RATIO * max(base, 1e-9):
|
||||
if base > 0.005:
|
||||
shape = "%.2f/s vs 1h baseline %.2f/s (%.1fx)" % (cur, base, cur / base)
|
||||
else:
|
||||
shape = "%.2f/s with no 1h baseline (%.0f drops over 5m)" % (cur, cur * 300)
|
||||
return [Finding(
|
||||
rule="drop-spike", kind="state", severity="MEDIUM", entity="cluster",
|
||||
detail="tcp/udp drops " + shape,
|
||||
)]
|
||||
return []
|
||||
|
||||
|
||||
def rule_syn_sweep(prom) -> List[Finding]:
|
||||
syn = prom.scalar('sum(rate(hubble_tcp_flags_total{flag="SYN"}[5m]))')
|
||||
synack = prom.scalar('sum(rate(hubble_tcp_flags_total{flag="SYN-ACK"}[5m]))')
|
||||
ratio = syn / synack if synack > 0 else (float("inf") if syn > 0 else 0.0)
|
||||
if syn > config.SYN_FLOOR and ratio > config.SYN_RATIO:
|
||||
return [Finding(
|
||||
rule="syn-sweep", kind="state", severity="MEDIUM", entity="cluster",
|
||||
detail="SYN %.1f/s vs SYN-ACK %.1f/s (ratio %.1f) - connects that never complete"
|
||||
% (syn, synack, ratio),
|
||||
)]
|
||||
return []
|
||||
|
||||
|
||||
def rule_rst_storm(prom) -> List[Finding]:
|
||||
cur = prom.scalar('sum(rate(hubble_tcp_flags_total{flag="RST"}[5m]))')
|
||||
base = prom.scalar(
|
||||
'avg_over_time(sum(rate(hubble_tcp_flags_total{flag="RST"}[5m]))[6h:5m])')
|
||||
if cur > config.RST_FLOOR and cur > config.RST_RATIO * max(base, 1e-9):
|
||||
return [Finding(
|
||||
rule="rst-storm", kind="state", severity="MEDIUM", entity="cluster",
|
||||
detail="RST %.1f/s vs 6h average %.1f/s (%.1fx) - refused/reset connections"
|
||||
% (cur, base, cur / max(base, 1e-9)),
|
||||
)]
|
||||
return []
|
||||
|
||||
|
||||
def rule_new_port(prom) -> List[Finding]:
|
||||
"""A server-range port that carried no flows 24 h ago.
|
||||
|
||||
Ephemeral client ports (>= 32768) are excluded, otherwise every new outbound
|
||||
socket is a "new port".
|
||||
"""
|
||||
q = (
|
||||
'count by (port) (hubble_port_distribution_total{port!="0"})'
|
||||
' unless count by (port) (hubble_port_distribution_total{port!="0"} offset %s)'
|
||||
% config.NEW_PORT_LOOKBACK
|
||||
)
|
||||
out = []
|
||||
for labels, _value in prom.query(q):
|
||||
port = labels.get("port", "")
|
||||
try:
|
||||
port_i = int(port)
|
||||
except ValueError:
|
||||
continue
|
||||
if port_i <= 0 or port_i >= config.NEW_PORT_CEILING:
|
||||
continue
|
||||
out.append(Finding(
|
||||
rule="new-port", kind="state", severity="LOW", entity="port=%d" % port_i,
|
||||
detail="port %d carried flows now but none 24h ago - new listener or new peer port" % port_i,
|
||||
))
|
||||
return out
|
||||
|
||||
|
||||
def rule_http_errors(prom) -> List[Finding]:
|
||||
total = prom.scalar("sum(rate(hubble_http_requests_total[15m]))")
|
||||
err = prom.scalar('sum(rate(hubble_http_requests_total{status=~"4..|5.."}[15m]))')
|
||||
if total > config.HTTP_MIN_RATE and err > 0:
|
||||
share = err / total
|
||||
if share > config.HTTP_ERROR_RATIO:
|
||||
return [Finding(
|
||||
rule="http-error-ratio", kind="state", severity="MEDIUM", entity="cluster",
|
||||
detail="L7 4xx/5xx share %.2f of %.1f req/s (15m)" % (share, total),
|
||||
)]
|
||||
return []
|
||||
|
||||
|
||||
PROM_RULES = (
|
||||
rule_lost_events,
|
||||
rule_drop_spike,
|
||||
rule_syn_sweep,
|
||||
rule_rst_storm,
|
||||
rule_new_port,
|
||||
rule_http_errors,
|
||||
)
|
||||
|
||||
|
||||
# ---------------------------------------------------- flow-store rules ----
|
||||
def _egress_key(flow: Flow) -> Optional[str]:
|
||||
"""`workload->ip:port/proto` for an external, workload-originated flow."""
|
||||
if flow.type != "L3_L4" or flow.proto not in ("TCP", "UDP"):
|
||||
return None
|
||||
if not flow.src_workload or not is_external(flow.dst_ip) or flow.dst_port is None:
|
||||
return None
|
||||
return "%s->%s:%d/%s" % (flow.src_workload, flow.dst_ip, flow.dst_port, flow.proto.lower())
|
||||
|
||||
|
||||
def prune_beacon(beacon: Dict[str, Dict[str, float]], now: float) -> None:
|
||||
"""Drop sockets that fell out of the window from every tracked tuple."""
|
||||
cutoff = now - config.BEACON_WINDOW
|
||||
for key in list(beacon):
|
||||
kept = {s: t for s, t in beacon[key].items() if t >= cutoff}
|
||||
if kept:
|
||||
beacon[key] = kept
|
||||
else:
|
||||
beacon.pop(key, None)
|
||||
|
||||
|
||||
def rule_egress_first_seen(flows: Iterable[Flow], egress_seen: Dict[str, str],
|
||||
now: datetime) -> List[Finding]:
|
||||
"""First-seen egress tuple = candidate beacon/exfil.
|
||||
|
||||
The seen-set is cumulative and seeded silently on the first run, so
|
||||
deploying this sensor cannot dump the whole retained history into chat.
|
||||
"""
|
||||
out: List[Finding] = []
|
||||
for flow in flows:
|
||||
key = _egress_key(flow)
|
||||
if not key or key in egress_seen:
|
||||
continue
|
||||
egress_seen[key] = (flow.time or now).astimezone(timezone.utc).isoformat()
|
||||
port = flow.dst_port
|
||||
severity = "MEDIUM" if port in config.WEB_PORTS else "HIGH"
|
||||
out.append(Finding(
|
||||
rule="egress-new-dst", kind="novelty", severity=severity, entity=key,
|
||||
detail="%s first-seen %s (no prior in retained window)" % (key, _ts(flow.time)),
|
||||
))
|
||||
return out
|
||||
|
||||
|
||||
def rule_beacon(flows: Iterable[Flow], beacon: Dict[str, Dict[str, float]],
|
||||
now: float) -> List[Finding]:
|
||||
"""Periodic connections to one destination: C2 shape, not app traffic.
|
||||
|
||||
Counts distinct client sockets (src_ip:src_port) per (workload, dst, port)
|
||||
rather than packets — a single long-lived connection produces hundreds of
|
||||
trace events and would look like a high count. Beaconing is judged on the
|
||||
inter-arrival CV of *new* sockets over the retained window (2 h).
|
||||
"""
|
||||
touched = set()
|
||||
for flow in flows:
|
||||
key = _egress_key(flow)
|
||||
if not key:
|
||||
continue
|
||||
sock = "%s:%s" % (flow.src_ip, flow.src_port)
|
||||
stamp = (flow.time.timestamp() if flow.time else now)
|
||||
bucket = beacon.setdefault(key, {})
|
||||
bucket.setdefault(sock, stamp)
|
||||
touched.add(key)
|
||||
|
||||
cutoff = now - config.BEACON_WINDOW
|
||||
out: List[Finding] = []
|
||||
for key in touched:
|
||||
bucket = {s: t for s, t in beacon.get(key, {}).items() if t >= cutoff}
|
||||
beacon[key] = bucket
|
||||
if len(bucket) < config.BEACON_MIN_CONNS:
|
||||
continue
|
||||
times = sorted(bucket.values())
|
||||
gaps = [b - a for a, b in zip(times, times[1:]) if b > a]
|
||||
if len(gaps) < config.BEACON_MIN_CONNS - 1:
|
||||
continue
|
||||
mean = statistics.fmean(gaps)
|
||||
if mean <= 0 or mean > config.BEACON_MAX_INTERVAL:
|
||||
continue
|
||||
cv = statistics.pstdev(gaps) / mean
|
||||
if cv < config.BEACON_MAX_CV:
|
||||
out.append(Finding(
|
||||
rule="beacon-shape", kind="novelty", severity="HIGH", entity=key,
|
||||
detail="%s %d conns in %dh, jitter %.2f (mean %.0fs)"
|
||||
% (key, len(bucket), config.BEACON_WINDOW // 3600, cv, mean),
|
||||
))
|
||||
return out
|
||||
122
netsec_scan/state.py
Normal file
122
netsec_scan/state.py
Normal file
|
|
@ -0,0 +1,122 @@
|
|||
"""State file: cumulative seen-set, per-file read offsets, report counters.
|
||||
|
||||
Rules of the house:
|
||||
* the seen-set is UNIONED, never replaced — a transiently-empty read must not
|
||||
re-alert history;
|
||||
* a write is atomic (tmp + rename) and 0600;
|
||||
* a corrupt file is a hard failure (exit non-zero, nothing touched), not a
|
||||
silent reset that re-alerts everything.
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import json
|
||||
import os
|
||||
import time
|
||||
from datetime import datetime, timezone
|
||||
from pathlib import Path
|
||||
from typing import Any, Dict, List, Tuple
|
||||
|
||||
from . import config
|
||||
from .prom import SensorError
|
||||
|
||||
VERSION = 1
|
||||
|
||||
|
||||
def _now_iso() -> str:
|
||||
return datetime.now(timezone.utc).isoformat(timespec="seconds")
|
||||
|
||||
|
||||
def empty() -> Dict[str, Any]:
|
||||
return {
|
||||
"version": VERSION,
|
||||
"created_at": _now_iso(),
|
||||
"seeded": False, # flow novelty has been baselined once
|
||||
"seen": {}, # fp -> {rule, kind, entity, severity, first, last_alert}
|
||||
"egress": {}, # tuple -> first_seen iso (cumulative)
|
||||
"beacon": {}, # tuple -> {socket: ts}
|
||||
"files": {}, # name -> {offset, carry, size}
|
||||
"degraded": {}, # failure class -> iso of last announcement
|
||||
"day": {"date": datetime.now(timezone.utc).strftime("%Y-%m-%d"),
|
||||
"flows": 0, "rules": {}, "egress": [], "new_dsts": []},
|
||||
"totals": {"ticks": 0, "flows": 0, "findings": 0},
|
||||
}
|
||||
|
||||
|
||||
def load(path: Path) -> Dict[str, Any]:
|
||||
path = Path(path)
|
||||
if not path.exists():
|
||||
return empty()
|
||||
try:
|
||||
data = json.loads(path.read_text())
|
||||
except (OSError, ValueError) as exc:
|
||||
raise SensorError("state-corrupt", "%s: %s" % (path, exc))
|
||||
if not isinstance(data, dict) or data.get("version") != VERSION:
|
||||
raise SensorError("state-corrupt", "unexpected schema in %s" % path)
|
||||
base = empty()
|
||||
for key, value in base.items():
|
||||
data.setdefault(key, value)
|
||||
for key in ("seen", "egress", "beacon", "files", "degraded"):
|
||||
if not isinstance(data.get(key), dict):
|
||||
data[key] = {}
|
||||
return data
|
||||
|
||||
|
||||
def save(path: Path, state: Dict[str, Any]) -> None:
|
||||
path = Path(path)
|
||||
path.parent.mkdir(parents=True, exist_ok=True)
|
||||
tmp = path.with_suffix(path.suffix + ".tmp")
|
||||
payload = json.dumps(state, separators=(",", ":"), sort_keys=True)
|
||||
fd = os.open(tmp, os.O_WRONLY | os.O_CREAT | os.O_TRUNC, 0o600)
|
||||
with os.fdopen(fd, "w") as handle:
|
||||
handle.write(payload)
|
||||
os.replace(tmp, path)
|
||||
|
||||
|
||||
def prune(state: Dict[str, Any]) -> None:
|
||||
"""Bound every cumulative structure so a long-lived sensor stays small."""
|
||||
seen = state["seen"]
|
||||
if len(seen) > config.MAX_SEEN:
|
||||
ordered = sorted(seen.items(), key=lambda kv: kv[1].get("first", ""))
|
||||
for key, _ in ordered[: len(ordered) - config.MAX_SEEN + 2000]:
|
||||
seen.pop(key, None)
|
||||
egress = state["egress"]
|
||||
if len(egress) > config.MAX_EGRESS:
|
||||
ordered = sorted(egress.items(), key=lambda kv: kv[1])
|
||||
for key, _ in ordered[: len(ordered) - config.MAX_EGRESS + 2000]:
|
||||
egress.pop(key, None)
|
||||
beacon = state["beacon"]
|
||||
if len(beacon) > config.MAX_BEACON_TUPLES:
|
||||
ordered = sorted(beacon.items(),
|
||||
key=lambda kv: max(kv[1].values()) if kv[1] else 0)
|
||||
for key, _ in ordered[: len(ordered) - config.MAX_BEACON_TUPLES + 200]:
|
||||
beacon.pop(key, None)
|
||||
day = state["day"]
|
||||
if len(day.get("egress", [])) > config.MAX_DAY_EGRESS:
|
||||
day["egress"] = day["egress"][-config.MAX_DAY_EGRESS:]
|
||||
if len(day.get("new_dsts", [])) > config.MAX_DAY_EGRESS:
|
||||
day["new_dsts"] = day["new_dsts"][-config.MAX_DAY_EGRESS:]
|
||||
|
||||
|
||||
def roll_day(state: Dict[str, Any]) -> None:
|
||||
"""Carry report counters into a fresh UTC day (old day stays on disk)."""
|
||||
today = datetime.now(timezone.utc).strftime("%Y-%m-%d")
|
||||
day = state.get("day") or {}
|
||||
if day.get("date") != today:
|
||||
state["day"] = {"date": today, "flows": 0, "rules": {}, "egress": [], "new_dsts": []}
|
||||
|
||||
|
||||
def degraded_memo(state: Dict[str, Any], cls: str, now: float) -> bool:
|
||||
"""True when this failure class was already announced inside the window."""
|
||||
last = state.get("degraded", {}).get(cls)
|
||||
if last is None:
|
||||
return False
|
||||
try:
|
||||
stamp = datetime.fromisoformat(last).timestamp()
|
||||
except (TypeError, ValueError):
|
||||
return False
|
||||
return (now - stamp) < config.DEGRADED_MEMO
|
||||
|
||||
|
||||
def note_degraded(state: Dict[str, Any], cls: str) -> None:
|
||||
state.setdefault("degraded", {})[cls] = _now_iso()
|
||||
0
reports/.gitkeep
Normal file
0
reports/.gitkeep
Normal file
6
run.sh
Executable file
6
run.sh
Executable file
|
|
@ -0,0 +1,6 @@
|
|||
#!/bin/sh
|
||||
# netsec-scan entrypoint. Runs from the repo root so `python3 -m netsec_scan`
|
||||
# resolves the package; stdout is the alert, stderr is diagnostics.
|
||||
set -u
|
||||
cd /home/lancelot/Projects/netsec-agent || exit 1
|
||||
exec python3 -m netsec_scan "$@"
|
||||
24
tests/fixtures/beacon-shaped.jsonl
vendored
Normal file
24
tests/fixtures/beacon-shaped.jsonl
vendored
Normal file
|
|
@ -0,0 +1,24 @@
|
|||
{"flow":{"time":"2026-11-27T04:00:00.000000Z","uuid":"29e775f0-ff10-48c3-8ed1-8b88b9b9e794","emitter":{"name":"Hubble","version":"1.20.1+g7d68cfb3"},"verdict":"FORWARDED","ethernet":{"source":"f2:dc:16:84:bb:34","destination":"c6:f6:e9:76:45:36"},"IP":{"source":"10.244.0.184","destination":"104.18.30.120","ipVersion":"IPv4"},"l4":{"TCP":{"source_port":40000,"destination_port":443,"flags":{"SYN":true}}},"source":{"ID":455,"identity":40606,"cluster_name":"default","namespace":"flux-system","labels":["gen:io.cilium.k8s.named-ports=healthz.TCP.9440_http.TCP.9090_http-prom.TCP.8080","k8s:app.kubernetes.io/component=source-controller","k8s:app.kubernetes.io/instance=flux-system","k8s:app.kubernetes.io/part-of=flux","k8s:app.kubernetes.io/version=v2.9.5","k8s:app=source-controller","k8s:io.cilium.k8s.namespace.labels.app.kubernetes.io/instance=flux-system","k8s:io.cilium.k8s.namespace.labels.app.kubernetes.io/part-of=flux","k8s:io.cilium.k8s.namespace.labels.app.kubernetes.io/version=v2.9.5","k8s:io.cilium.k8s.namespace.labels.kubernetes.io/metadata.name=flux-system","k8s:io.cilium.k8s.namespace.labels.kustomize.toolkit.fluxcd.io/name=flux-system","k8s:io.cilium.k8s.namespace.labels.kustomize.toolkit.fluxcd.io/namespace=flux-system","k8s:io.cilium.k8s.namespace.labels.pod-security.kubernetes.io/warn-version=latest","k8s:io.cilium.k8s.namespace.labels.pod-security.kubernetes.io/warn=restricted","k8s:io.cilium.k8s.policy.cluster=default","k8s:io.cilium.k8s.policy.serviceaccount=source-controller","k8s:io.kubernetes.pod.namespace=flux-system"],"pod_name":"source-controller-56549698b5-2lvmc","workloads":[{"name":"source-controller","kind":"Deployment"}]},"destination":{"identity":2,"labels":["reserved:world"]},"Type":"L3_L4","node_name":"siriussec","node_labels":["beta.kubernetes.io/arch=amd64","beta.kubernetes.io/os=linux","gateway=true","kubernetes.io/arch=amd64","kubernetes.io/hostname=siriussec","kubernetes.io/os=linux","node-role.kubernetes.io/control-plane=","node-role.kubernetes.io/gateway=true","node-role.kubernetes.io/worker=","node.kubernetes.io/exclude-from-external-load-balancers="],"event_type":{"type":5},"traffic_direction":"EGRESS","policy_match_type":4,"is_reply":false,"Summary":"TCP Flags: SYN","egress_allowed_by":[{"name":"allow-egress","namespace":"flux-system","labels":["k8s:io.cilium.k8s.policy.derived-from=NetworkPolicy","k8s:io.cilium.k8s.policy.name=allow-egress","k8s:io.cilium.k8s.policy.namespace=flux-system","k8s:io.cilium.k8s.policy.uid=1baa50f5-a60f-4c58-bc53-34ab012d2ccc"],"revision":"17","kind":"NetworkPolicy"}],"policy_log":[""]}}
|
||||
{"flow":{"time":"2026-11-27T04:00:30.000000Z","uuid":"29e775f0-ff10-48c3-8ed1-8b88b9b9e794","emitter":{"name":"Hubble","version":"1.20.1+g7d68cfb3"},"verdict":"FORWARDED","ethernet":{"source":"f2:dc:16:84:bb:34","destination":"c6:f6:e9:76:45:36"},"IP":{"source":"10.244.0.184","destination":"104.18.30.120","ipVersion":"IPv4"},"l4":{"TCP":{"source_port":40001,"destination_port":443,"flags":{"SYN":true}}},"source":{"ID":455,"identity":40606,"cluster_name":"default","namespace":"flux-system","labels":["gen:io.cilium.k8s.named-ports=healthz.TCP.9440_http.TCP.9090_http-prom.TCP.8080","k8s:app.kubernetes.io/component=source-controller","k8s:app.kubernetes.io/instance=flux-system","k8s:app.kubernetes.io/part-of=flux","k8s:app.kubernetes.io/version=v2.9.5","k8s:app=source-controller","k8s:io.cilium.k8s.namespace.labels.app.kubernetes.io/instance=flux-system","k8s:io.cilium.k8s.namespace.labels.app.kubernetes.io/part-of=flux","k8s:io.cilium.k8s.namespace.labels.app.kubernetes.io/version=v2.9.5","k8s:io.cilium.k8s.namespace.labels.kubernetes.io/metadata.name=flux-system","k8s:io.cilium.k8s.namespace.labels.kustomize.toolkit.fluxcd.io/name=flux-system","k8s:io.cilium.k8s.namespace.labels.kustomize.toolkit.fluxcd.io/namespace=flux-system","k8s:io.cilium.k8s.namespace.labels.pod-security.kubernetes.io/warn-version=latest","k8s:io.cilium.k8s.namespace.labels.pod-security.kubernetes.io/warn=restricted","k8s:io.cilium.k8s.policy.cluster=default","k8s:io.cilium.k8s.policy.serviceaccount=source-controller","k8s:io.kubernetes.pod.namespace=flux-system"],"pod_name":"source-controller-56549698b5-2lvmc","workloads":[{"name":"source-controller","kind":"Deployment"}]},"destination":{"identity":2,"labels":["reserved:world"]},"Type":"L3_L4","node_name":"siriussec","node_labels":["beta.kubernetes.io/arch=amd64","beta.kubernetes.io/os=linux","gateway=true","kubernetes.io/arch=amd64","kubernetes.io/hostname=siriussec","kubernetes.io/os=linux","node-role.kubernetes.io/control-plane=","node-role.kubernetes.io/gateway=true","node-role.kubernetes.io/worker=","node.kubernetes.io/exclude-from-external-load-balancers="],"event_type":{"type":5},"traffic_direction":"EGRESS","policy_match_type":4,"is_reply":false,"Summary":"TCP Flags: SYN","egress_allowed_by":[{"name":"allow-egress","namespace":"flux-system","labels":["k8s:io.cilium.k8s.policy.derived-from=NetworkPolicy","k8s:io.cilium.k8s.policy.name=allow-egress","k8s:io.cilium.k8s.policy.namespace=flux-system","k8s:io.cilium.k8s.policy.uid=1baa50f5-a60f-4c58-bc53-34ab012d2ccc"],"revision":"17","kind":"NetworkPolicy"}],"policy_log":[""]}}
|
||||
{"flow":{"time":"2026-11-27T04:01:00.000000Z","uuid":"29e775f0-ff10-48c3-8ed1-8b88b9b9e794","emitter":{"name":"Hubble","version":"1.20.1+g7d68cfb3"},"verdict":"FORWARDED","ethernet":{"source":"f2:dc:16:84:bb:34","destination":"c6:f6:e9:76:45:36"},"IP":{"source":"10.244.0.184","destination":"104.18.30.120","ipVersion":"IPv4"},"l4":{"TCP":{"source_port":40002,"destination_port":443,"flags":{"SYN":true}}},"source":{"ID":455,"identity":40606,"cluster_name":"default","namespace":"flux-system","labels":["gen:io.cilium.k8s.named-ports=healthz.TCP.9440_http.TCP.9090_http-prom.TCP.8080","k8s:app.kubernetes.io/component=source-controller","k8s:app.kubernetes.io/instance=flux-system","k8s:app.kubernetes.io/part-of=flux","k8s:app.kubernetes.io/version=v2.9.5","k8s:app=source-controller","k8s:io.cilium.k8s.namespace.labels.app.kubernetes.io/instance=flux-system","k8s:io.cilium.k8s.namespace.labels.app.kubernetes.io/part-of=flux","k8s:io.cilium.k8s.namespace.labels.app.kubernetes.io/version=v2.9.5","k8s:io.cilium.k8s.namespace.labels.kubernetes.io/metadata.name=flux-system","k8s:io.cilium.k8s.namespace.labels.kustomize.toolkit.fluxcd.io/name=flux-system","k8s:io.cilium.k8s.namespace.labels.kustomize.toolkit.fluxcd.io/namespace=flux-system","k8s:io.cilium.k8s.namespace.labels.pod-security.kubernetes.io/warn-version=latest","k8s:io.cilium.k8s.namespace.labels.pod-security.kubernetes.io/warn=restricted","k8s:io.cilium.k8s.policy.cluster=default","k8s:io.cilium.k8s.policy.serviceaccount=source-controller","k8s:io.kubernetes.pod.namespace=flux-system"],"pod_name":"source-controller-56549698b5-2lvmc","workloads":[{"name":"source-controller","kind":"Deployment"}]},"destination":{"identity":2,"labels":["reserved:world"]},"Type":"L3_L4","node_name":"siriussec","node_labels":["beta.kubernetes.io/arch=amd64","beta.kubernetes.io/os=linux","gateway=true","kubernetes.io/arch=amd64","kubernetes.io/hostname=siriussec","kubernetes.io/os=linux","node-role.kubernetes.io/control-plane=","node-role.kubernetes.io/gateway=true","node-role.kubernetes.io/worker=","node.kubernetes.io/exclude-from-external-load-balancers="],"event_type":{"type":5},"traffic_direction":"EGRESS","policy_match_type":4,"is_reply":false,"Summary":"TCP Flags: SYN","egress_allowed_by":[{"name":"allow-egress","namespace":"flux-system","labels":["k8s:io.cilium.k8s.policy.derived-from=NetworkPolicy","k8s:io.cilium.k8s.policy.name=allow-egress","k8s:io.cilium.k8s.policy.namespace=flux-system","k8s:io.cilium.k8s.policy.uid=1baa50f5-a60f-4c58-bc53-34ab012d2ccc"],"revision":"17","kind":"NetworkPolicy"}],"policy_log":[""]}}
|
||||
{"flow":{"time":"2026-11-27T04:01:30.000000Z","uuid":"29e775f0-ff10-48c3-8ed1-8b88b9b9e794","emitter":{"name":"Hubble","version":"1.20.1+g7d68cfb3"},"verdict":"FORWARDED","ethernet":{"source":"f2:dc:16:84:bb:34","destination":"c6:f6:e9:76:45:36"},"IP":{"source":"10.244.0.184","destination":"104.18.30.120","ipVersion":"IPv4"},"l4":{"TCP":{"source_port":40003,"destination_port":443,"flags":{"SYN":true}}},"source":{"ID":455,"identity":40606,"cluster_name":"default","namespace":"flux-system","labels":["gen:io.cilium.k8s.named-ports=healthz.TCP.9440_http.TCP.9090_http-prom.TCP.8080","k8s:app.kubernetes.io/component=source-controller","k8s:app.kubernetes.io/instance=flux-system","k8s:app.kubernetes.io/part-of=flux","k8s:app.kubernetes.io/version=v2.9.5","k8s:app=source-controller","k8s:io.cilium.k8s.namespace.labels.app.kubernetes.io/instance=flux-system","k8s:io.cilium.k8s.namespace.labels.app.kubernetes.io/part-of=flux","k8s:io.cilium.k8s.namespace.labels.app.kubernetes.io/version=v2.9.5","k8s:io.cilium.k8s.namespace.labels.kubernetes.io/metadata.name=flux-system","k8s:io.cilium.k8s.namespace.labels.kustomize.toolkit.fluxcd.io/name=flux-system","k8s:io.cilium.k8s.namespace.labels.kustomize.toolkit.fluxcd.io/namespace=flux-system","k8s:io.cilium.k8s.namespace.labels.pod-security.kubernetes.io/warn-version=latest","k8s:io.cilium.k8s.namespace.labels.pod-security.kubernetes.io/warn=restricted","k8s:io.cilium.k8s.policy.cluster=default","k8s:io.cilium.k8s.policy.serviceaccount=source-controller","k8s:io.kubernetes.pod.namespace=flux-system"],"pod_name":"source-controller-56549698b5-2lvmc","workloads":[{"name":"source-controller","kind":"Deployment"}]},"destination":{"identity":2,"labels":["reserved:world"]},"Type":"L3_L4","node_name":"siriussec","node_labels":["beta.kubernetes.io/arch=amd64","beta.kubernetes.io/os=linux","gateway=true","kubernetes.io/arch=amd64","kubernetes.io/hostname=siriussec","kubernetes.io/os=linux","node-role.kubernetes.io/control-plane=","node-role.kubernetes.io/gateway=true","node-role.kubernetes.io/worker=","node.kubernetes.io/exclude-from-external-load-balancers="],"event_type":{"type":5},"traffic_direction":"EGRESS","policy_match_type":4,"is_reply":false,"Summary":"TCP Flags: SYN","egress_allowed_by":[{"name":"allow-egress","namespace":"flux-system","labels":["k8s:io.cilium.k8s.policy.derived-from=NetworkPolicy","k8s:io.cilium.k8s.policy.name=allow-egress","k8s:io.cilium.k8s.policy.namespace=flux-system","k8s:io.cilium.k8s.policy.uid=1baa50f5-a60f-4c58-bc53-34ab012d2ccc"],"revision":"17","kind":"NetworkPolicy"}],"policy_log":[""]}}
|
||||
{"flow":{"time":"2026-11-27T04:02:00.000000Z","uuid":"29e775f0-ff10-48c3-8ed1-8b88b9b9e794","emitter":{"name":"Hubble","version":"1.20.1+g7d68cfb3"},"verdict":"FORWARDED","ethernet":{"source":"f2:dc:16:84:bb:34","destination":"c6:f6:e9:76:45:36"},"IP":{"source":"10.244.0.184","destination":"104.18.30.120","ipVersion":"IPv4"},"l4":{"TCP":{"source_port":40004,"destination_port":443,"flags":{"SYN":true}}},"source":{"ID":455,"identity":40606,"cluster_name":"default","namespace":"flux-system","labels":["gen:io.cilium.k8s.named-ports=healthz.TCP.9440_http.TCP.9090_http-prom.TCP.8080","k8s:app.kubernetes.io/component=source-controller","k8s:app.kubernetes.io/instance=flux-system","k8s:app.kubernetes.io/part-of=flux","k8s:app.kubernetes.io/version=v2.9.5","k8s:app=source-controller","k8s:io.cilium.k8s.namespace.labels.app.kubernetes.io/instance=flux-system","k8s:io.cilium.k8s.namespace.labels.app.kubernetes.io/part-of=flux","k8s:io.cilium.k8s.namespace.labels.app.kubernetes.io/version=v2.9.5","k8s:io.cilium.k8s.namespace.labels.kubernetes.io/metadata.name=flux-system","k8s:io.cilium.k8s.namespace.labels.kustomize.toolkit.fluxcd.io/name=flux-system","k8s:io.cilium.k8s.namespace.labels.kustomize.toolkit.fluxcd.io/namespace=flux-system","k8s:io.cilium.k8s.namespace.labels.pod-security.kubernetes.io/warn-version=latest","k8s:io.cilium.k8s.namespace.labels.pod-security.kubernetes.io/warn=restricted","k8s:io.cilium.k8s.policy.cluster=default","k8s:io.cilium.k8s.policy.serviceaccount=source-controller","k8s:io.kubernetes.pod.namespace=flux-system"],"pod_name":"source-controller-56549698b5-2lvmc","workloads":[{"name":"source-controller","kind":"Deployment"}]},"destination":{"identity":2,"labels":["reserved:world"]},"Type":"L3_L4","node_name":"siriussec","node_labels":["beta.kubernetes.io/arch=amd64","beta.kubernetes.io/os=linux","gateway=true","kubernetes.io/arch=amd64","kubernetes.io/hostname=siriussec","kubernetes.io/os=linux","node-role.kubernetes.io/control-plane=","node-role.kubernetes.io/gateway=true","node-role.kubernetes.io/worker=","node.kubernetes.io/exclude-from-external-load-balancers="],"event_type":{"type":5},"traffic_direction":"EGRESS","policy_match_type":4,"is_reply":false,"Summary":"TCP Flags: SYN","egress_allowed_by":[{"name":"allow-egress","namespace":"flux-system","labels":["k8s:io.cilium.k8s.policy.derived-from=NetworkPolicy","k8s:io.cilium.k8s.policy.name=allow-egress","k8s:io.cilium.k8s.policy.namespace=flux-system","k8s:io.cilium.k8s.policy.uid=1baa50f5-a60f-4c58-bc53-34ab012d2ccc"],"revision":"17","kind":"NetworkPolicy"}],"policy_log":[""]}}
|
||||
{"flow":{"time":"2026-11-27T04:02:30.000000Z","uuid":"29e775f0-ff10-48c3-8ed1-8b88b9b9e794","emitter":{"name":"Hubble","version":"1.20.1+g7d68cfb3"},"verdict":"FORWARDED","ethernet":{"source":"f2:dc:16:84:bb:34","destination":"c6:f6:e9:76:45:36"},"IP":{"source":"10.244.0.184","destination":"104.18.30.120","ipVersion":"IPv4"},"l4":{"TCP":{"source_port":40005,"destination_port":443,"flags":{"SYN":true}}},"source":{"ID":455,"identity":40606,"cluster_name":"default","namespace":"flux-system","labels":["gen:io.cilium.k8s.named-ports=healthz.TCP.9440_http.TCP.9090_http-prom.TCP.8080","k8s:app.kubernetes.io/component=source-controller","k8s:app.kubernetes.io/instance=flux-system","k8s:app.kubernetes.io/part-of=flux","k8s:app.kubernetes.io/version=v2.9.5","k8s:app=source-controller","k8s:io.cilium.k8s.namespace.labels.app.kubernetes.io/instance=flux-system","k8s:io.cilium.k8s.namespace.labels.app.kubernetes.io/part-of=flux","k8s:io.cilium.k8s.namespace.labels.app.kubernetes.io/version=v2.9.5","k8s:io.cilium.k8s.namespace.labels.kubernetes.io/metadata.name=flux-system","k8s:io.cilium.k8s.namespace.labels.kustomize.toolkit.fluxcd.io/name=flux-system","k8s:io.cilium.k8s.namespace.labels.kustomize.toolkit.fluxcd.io/namespace=flux-system","k8s:io.cilium.k8s.namespace.labels.pod-security.kubernetes.io/warn-version=latest","k8s:io.cilium.k8s.namespace.labels.pod-security.kubernetes.io/warn=restricted","k8s:io.cilium.k8s.policy.cluster=default","k8s:io.cilium.k8s.policy.serviceaccount=source-controller","k8s:io.kubernetes.pod.namespace=flux-system"],"pod_name":"source-controller-56549698b5-2lvmc","workloads":[{"name":"source-controller","kind":"Deployment"}]},"destination":{"identity":2,"labels":["reserved:world"]},"Type":"L3_L4","node_name":"siriussec","node_labels":["beta.kubernetes.io/arch=amd64","beta.kubernetes.io/os=linux","gateway=true","kubernetes.io/arch=amd64","kubernetes.io/hostname=siriussec","kubernetes.io/os=linux","node-role.kubernetes.io/control-plane=","node-role.kubernetes.io/gateway=true","node-role.kubernetes.io/worker=","node.kubernetes.io/exclude-from-external-load-balancers="],"event_type":{"type":5},"traffic_direction":"EGRESS","policy_match_type":4,"is_reply":false,"Summary":"TCP Flags: SYN","egress_allowed_by":[{"name":"allow-egress","namespace":"flux-system","labels":["k8s:io.cilium.k8s.policy.derived-from=NetworkPolicy","k8s:io.cilium.k8s.policy.name=allow-egress","k8s:io.cilium.k8s.policy.namespace=flux-system","k8s:io.cilium.k8s.policy.uid=1baa50f5-a60f-4c58-bc53-34ab012d2ccc"],"revision":"17","kind":"NetworkPolicy"}],"policy_log":[""]}}
|
||||
{"flow":{"time":"2026-11-27T04:03:00.000000Z","uuid":"29e775f0-ff10-48c3-8ed1-8b88b9b9e794","emitter":{"name":"Hubble","version":"1.20.1+g7d68cfb3"},"verdict":"FORWARDED","ethernet":{"source":"f2:dc:16:84:bb:34","destination":"c6:f6:e9:76:45:36"},"IP":{"source":"10.244.0.184","destination":"104.18.30.120","ipVersion":"IPv4"},"l4":{"TCP":{"source_port":40006,"destination_port":443,"flags":{"SYN":true}}},"source":{"ID":455,"identity":40606,"cluster_name":"default","namespace":"flux-system","labels":["gen:io.cilium.k8s.named-ports=healthz.TCP.9440_http.TCP.9090_http-prom.TCP.8080","k8s:app.kubernetes.io/component=source-controller","k8s:app.kubernetes.io/instance=flux-system","k8s:app.kubernetes.io/part-of=flux","k8s:app.kubernetes.io/version=v2.9.5","k8s:app=source-controller","k8s:io.cilium.k8s.namespace.labels.app.kubernetes.io/instance=flux-system","k8s:io.cilium.k8s.namespace.labels.app.kubernetes.io/part-of=flux","k8s:io.cilium.k8s.namespace.labels.app.kubernetes.io/version=v2.9.5","k8s:io.cilium.k8s.namespace.labels.kubernetes.io/metadata.name=flux-system","k8s:io.cilium.k8s.namespace.labels.kustomize.toolkit.fluxcd.io/name=flux-system","k8s:io.cilium.k8s.namespace.labels.kustomize.toolkit.fluxcd.io/namespace=flux-system","k8s:io.cilium.k8s.namespace.labels.pod-security.kubernetes.io/warn-version=latest","k8s:io.cilium.k8s.namespace.labels.pod-security.kubernetes.io/warn=restricted","k8s:io.cilium.k8s.policy.cluster=default","k8s:io.cilium.k8s.policy.serviceaccount=source-controller","k8s:io.kubernetes.pod.namespace=flux-system"],"pod_name":"source-controller-56549698b5-2lvmc","workloads":[{"name":"source-controller","kind":"Deployment"}]},"destination":{"identity":2,"labels":["reserved:world"]},"Type":"L3_L4","node_name":"siriussec","node_labels":["beta.kubernetes.io/arch=amd64","beta.kubernetes.io/os=linux","gateway=true","kubernetes.io/arch=amd64","kubernetes.io/hostname=siriussec","kubernetes.io/os=linux","node-role.kubernetes.io/control-plane=","node-role.kubernetes.io/gateway=true","node-role.kubernetes.io/worker=","node.kubernetes.io/exclude-from-external-load-balancers="],"event_type":{"type":5},"traffic_direction":"EGRESS","policy_match_type":4,"is_reply":false,"Summary":"TCP Flags: SYN","egress_allowed_by":[{"name":"allow-egress","namespace":"flux-system","labels":["k8s:io.cilium.k8s.policy.derived-from=NetworkPolicy","k8s:io.cilium.k8s.policy.name=allow-egress","k8s:io.cilium.k8s.policy.namespace=flux-system","k8s:io.cilium.k8s.policy.uid=1baa50f5-a60f-4c58-bc53-34ab012d2ccc"],"revision":"17","kind":"NetworkPolicy"}],"policy_log":[""]}}
|
||||
{"flow":{"time":"2026-11-27T04:03:30.000000Z","uuid":"29e775f0-ff10-48c3-8ed1-8b88b9b9e794","emitter":{"name":"Hubble","version":"1.20.1+g7d68cfb3"},"verdict":"FORWARDED","ethernet":{"source":"f2:dc:16:84:bb:34","destination":"c6:f6:e9:76:45:36"},"IP":{"source":"10.244.0.184","destination":"104.18.30.120","ipVersion":"IPv4"},"l4":{"TCP":{"source_port":40007,"destination_port":443,"flags":{"SYN":true}}},"source":{"ID":455,"identity":40606,"cluster_name":"default","namespace":"flux-system","labels":["gen:io.cilium.k8s.named-ports=healthz.TCP.9440_http.TCP.9090_http-prom.TCP.8080","k8s:app.kubernetes.io/component=source-controller","k8s:app.kubernetes.io/instance=flux-system","k8s:app.kubernetes.io/part-of=flux","k8s:app.kubernetes.io/version=v2.9.5","k8s:app=source-controller","k8s:io.cilium.k8s.namespace.labels.app.kubernetes.io/instance=flux-system","k8s:io.cilium.k8s.namespace.labels.app.kubernetes.io/part-of=flux","k8s:io.cilium.k8s.namespace.labels.app.kubernetes.io/version=v2.9.5","k8s:io.cilium.k8s.namespace.labels.kubernetes.io/metadata.name=flux-system","k8s:io.cilium.k8s.namespace.labels.kustomize.toolkit.fluxcd.io/name=flux-system","k8s:io.cilium.k8s.namespace.labels.kustomize.toolkit.fluxcd.io/namespace=flux-system","k8s:io.cilium.k8s.namespace.labels.pod-security.kubernetes.io/warn-version=latest","k8s:io.cilium.k8s.namespace.labels.pod-security.kubernetes.io/warn=restricted","k8s:io.cilium.k8s.policy.cluster=default","k8s:io.cilium.k8s.policy.serviceaccount=source-controller","k8s:io.kubernetes.pod.namespace=flux-system"],"pod_name":"source-controller-56549698b5-2lvmc","workloads":[{"name":"source-controller","kind":"Deployment"}]},"destination":{"identity":2,"labels":["reserved:world"]},"Type":"L3_L4","node_name":"siriussec","node_labels":["beta.kubernetes.io/arch=amd64","beta.kubernetes.io/os=linux","gateway=true","kubernetes.io/arch=amd64","kubernetes.io/hostname=siriussec","kubernetes.io/os=linux","node-role.kubernetes.io/control-plane=","node-role.kubernetes.io/gateway=true","node-role.kubernetes.io/worker=","node.kubernetes.io/exclude-from-external-load-balancers="],"event_type":{"type":5},"traffic_direction":"EGRESS","policy_match_type":4,"is_reply":false,"Summary":"TCP Flags: SYN","egress_allowed_by":[{"name":"allow-egress","namespace":"flux-system","labels":["k8s:io.cilium.k8s.policy.derived-from=NetworkPolicy","k8s:io.cilium.k8s.policy.name=allow-egress","k8s:io.cilium.k8s.policy.namespace=flux-system","k8s:io.cilium.k8s.policy.uid=1baa50f5-a60f-4c58-bc53-34ab012d2ccc"],"revision":"17","kind":"NetworkPolicy"}],"policy_log":[""]}}
|
||||
{"flow":{"time":"2026-11-27T04:04:00.000000Z","uuid":"29e775f0-ff10-48c3-8ed1-8b88b9b9e794","emitter":{"name":"Hubble","version":"1.20.1+g7d68cfb3"},"verdict":"FORWARDED","ethernet":{"source":"f2:dc:16:84:bb:34","destination":"c6:f6:e9:76:45:36"},"IP":{"source":"10.244.0.184","destination":"104.18.30.120","ipVersion":"IPv4"},"l4":{"TCP":{"source_port":40008,"destination_port":443,"flags":{"SYN":true}}},"source":{"ID":455,"identity":40606,"cluster_name":"default","namespace":"flux-system","labels":["gen:io.cilium.k8s.named-ports=healthz.TCP.9440_http.TCP.9090_http-prom.TCP.8080","k8s:app.kubernetes.io/component=source-controller","k8s:app.kubernetes.io/instance=flux-system","k8s:app.kubernetes.io/part-of=flux","k8s:app.kubernetes.io/version=v2.9.5","k8s:app=source-controller","k8s:io.cilium.k8s.namespace.labels.app.kubernetes.io/instance=flux-system","k8s:io.cilium.k8s.namespace.labels.app.kubernetes.io/part-of=flux","k8s:io.cilium.k8s.namespace.labels.app.kubernetes.io/version=v2.9.5","k8s:io.cilium.k8s.namespace.labels.kubernetes.io/metadata.name=flux-system","k8s:io.cilium.k8s.namespace.labels.kustomize.toolkit.fluxcd.io/name=flux-system","k8s:io.cilium.k8s.namespace.labels.kustomize.toolkit.fluxcd.io/namespace=flux-system","k8s:io.cilium.k8s.namespace.labels.pod-security.kubernetes.io/warn-version=latest","k8s:io.cilium.k8s.namespace.labels.pod-security.kubernetes.io/warn=restricted","k8s:io.cilium.k8s.policy.cluster=default","k8s:io.cilium.k8s.policy.serviceaccount=source-controller","k8s:io.kubernetes.pod.namespace=flux-system"],"pod_name":"source-controller-56549698b5-2lvmc","workloads":[{"name":"source-controller","kind":"Deployment"}]},"destination":{"identity":2,"labels":["reserved:world"]},"Type":"L3_L4","node_name":"siriussec","node_labels":["beta.kubernetes.io/arch=amd64","beta.kubernetes.io/os=linux","gateway=true","kubernetes.io/arch=amd64","kubernetes.io/hostname=siriussec","kubernetes.io/os=linux","node-role.kubernetes.io/control-plane=","node-role.kubernetes.io/gateway=true","node-role.kubernetes.io/worker=","node.kubernetes.io/exclude-from-external-load-balancers="],"event_type":{"type":5},"traffic_direction":"EGRESS","policy_match_type":4,"is_reply":false,"Summary":"TCP Flags: SYN","egress_allowed_by":[{"name":"allow-egress","namespace":"flux-system","labels":["k8s:io.cilium.k8s.policy.derived-from=NetworkPolicy","k8s:io.cilium.k8s.policy.name=allow-egress","k8s:io.cilium.k8s.policy.namespace=flux-system","k8s:io.cilium.k8s.policy.uid=1baa50f5-a60f-4c58-bc53-34ab012d2ccc"],"revision":"17","kind":"NetworkPolicy"}],"policy_log":[""]}}
|
||||
{"flow":{"time":"2026-11-27T04:04:30.000000Z","uuid":"29e775f0-ff10-48c3-8ed1-8b88b9b9e794","emitter":{"name":"Hubble","version":"1.20.1+g7d68cfb3"},"verdict":"FORWARDED","ethernet":{"source":"f2:dc:16:84:bb:34","destination":"c6:f6:e9:76:45:36"},"IP":{"source":"10.244.0.184","destination":"104.18.30.120","ipVersion":"IPv4"},"l4":{"TCP":{"source_port":40009,"destination_port":443,"flags":{"SYN":true}}},"source":{"ID":455,"identity":40606,"cluster_name":"default","namespace":"flux-system","labels":["gen:io.cilium.k8s.named-ports=healthz.TCP.9440_http.TCP.9090_http-prom.TCP.8080","k8s:app.kubernetes.io/component=source-controller","k8s:app.kubernetes.io/instance=flux-system","k8s:app.kubernetes.io/part-of=flux","k8s:app.kubernetes.io/version=v2.9.5","k8s:app=source-controller","k8s:io.cilium.k8s.namespace.labels.app.kubernetes.io/instance=flux-system","k8s:io.cilium.k8s.namespace.labels.app.kubernetes.io/part-of=flux","k8s:io.cilium.k8s.namespace.labels.app.kubernetes.io/version=v2.9.5","k8s:io.cilium.k8s.namespace.labels.kubernetes.io/metadata.name=flux-system","k8s:io.cilium.k8s.namespace.labels.kustomize.toolkit.fluxcd.io/name=flux-system","k8s:io.cilium.k8s.namespace.labels.kustomize.toolkit.fluxcd.io/namespace=flux-system","k8s:io.cilium.k8s.namespace.labels.pod-security.kubernetes.io/warn-version=latest","k8s:io.cilium.k8s.namespace.labels.pod-security.kubernetes.io/warn=restricted","k8s:io.cilium.k8s.policy.cluster=default","k8s:io.cilium.k8s.policy.serviceaccount=source-controller","k8s:io.kubernetes.pod.namespace=flux-system"],"pod_name":"source-controller-56549698b5-2lvmc","workloads":[{"name":"source-controller","kind":"Deployment"}]},"destination":{"identity":2,"labels":["reserved:world"]},"Type":"L3_L4","node_name":"siriussec","node_labels":["beta.kubernetes.io/arch=amd64","beta.kubernetes.io/os=linux","gateway=true","kubernetes.io/arch=amd64","kubernetes.io/hostname=siriussec","kubernetes.io/os=linux","node-role.kubernetes.io/control-plane=","node-role.kubernetes.io/gateway=true","node-role.kubernetes.io/worker=","node.kubernetes.io/exclude-from-external-load-balancers="],"event_type":{"type":5},"traffic_direction":"EGRESS","policy_match_type":4,"is_reply":false,"Summary":"TCP Flags: SYN","egress_allowed_by":[{"name":"allow-egress","namespace":"flux-system","labels":["k8s:io.cilium.k8s.policy.derived-from=NetworkPolicy","k8s:io.cilium.k8s.policy.name=allow-egress","k8s:io.cilium.k8s.policy.namespace=flux-system","k8s:io.cilium.k8s.policy.uid=1baa50f5-a60f-4c58-bc53-34ab012d2ccc"],"revision":"17","kind":"NetworkPolicy"}],"policy_log":[""]}}
|
||||
{"flow":{"time":"2026-11-27T04:05:00.000000Z","uuid":"29e775f0-ff10-48c3-8ed1-8b88b9b9e794","emitter":{"name":"Hubble","version":"1.20.1+g7d68cfb3"},"verdict":"FORWARDED","ethernet":{"source":"f2:dc:16:84:bb:34","destination":"c6:f6:e9:76:45:36"},"IP":{"source":"10.244.0.184","destination":"104.18.30.120","ipVersion":"IPv4"},"l4":{"TCP":{"source_port":40010,"destination_port":443,"flags":{"SYN":true}}},"source":{"ID":455,"identity":40606,"cluster_name":"default","namespace":"flux-system","labels":["gen:io.cilium.k8s.named-ports=healthz.TCP.9440_http.TCP.9090_http-prom.TCP.8080","k8s:app.kubernetes.io/component=source-controller","k8s:app.kubernetes.io/instance=flux-system","k8s:app.kubernetes.io/part-of=flux","k8s:app.kubernetes.io/version=v2.9.5","k8s:app=source-controller","k8s:io.cilium.k8s.namespace.labels.app.kubernetes.io/instance=flux-system","k8s:io.cilium.k8s.namespace.labels.app.kubernetes.io/part-of=flux","k8s:io.cilium.k8s.namespace.labels.app.kubernetes.io/version=v2.9.5","k8s:io.cilium.k8s.namespace.labels.kubernetes.io/metadata.name=flux-system","k8s:io.cilium.k8s.namespace.labels.kustomize.toolkit.fluxcd.io/name=flux-system","k8s:io.cilium.k8s.namespace.labels.kustomize.toolkit.fluxcd.io/namespace=flux-system","k8s:io.cilium.k8s.namespace.labels.pod-security.kubernetes.io/warn-version=latest","k8s:io.cilium.k8s.namespace.labels.pod-security.kubernetes.io/warn=restricted","k8s:io.cilium.k8s.policy.cluster=default","k8s:io.cilium.k8s.policy.serviceaccount=source-controller","k8s:io.kubernetes.pod.namespace=flux-system"],"pod_name":"source-controller-56549698b5-2lvmc","workloads":[{"name":"source-controller","kind":"Deployment"}]},"destination":{"identity":2,"labels":["reserved:world"]},"Type":"L3_L4","node_name":"siriussec","node_labels":["beta.kubernetes.io/arch=amd64","beta.kubernetes.io/os=linux","gateway=true","kubernetes.io/arch=amd64","kubernetes.io/hostname=siriussec","kubernetes.io/os=linux","node-role.kubernetes.io/control-plane=","node-role.kubernetes.io/gateway=true","node-role.kubernetes.io/worker=","node.kubernetes.io/exclude-from-external-load-balancers="],"event_type":{"type":5},"traffic_direction":"EGRESS","policy_match_type":4,"is_reply":false,"Summary":"TCP Flags: SYN","egress_allowed_by":[{"name":"allow-egress","namespace":"flux-system","labels":["k8s:io.cilium.k8s.policy.derived-from=NetworkPolicy","k8s:io.cilium.k8s.policy.name=allow-egress","k8s:io.cilium.k8s.policy.namespace=flux-system","k8s:io.cilium.k8s.policy.uid=1baa50f5-a60f-4c58-bc53-34ab012d2ccc"],"revision":"17","kind":"NetworkPolicy"}],"policy_log":[""]}}
|
||||
{"flow":{"time":"2026-11-27T04:05:30.000000Z","uuid":"29e775f0-ff10-48c3-8ed1-8b88b9b9e794","emitter":{"name":"Hubble","version":"1.20.1+g7d68cfb3"},"verdict":"FORWARDED","ethernet":{"source":"f2:dc:16:84:bb:34","destination":"c6:f6:e9:76:45:36"},"IP":{"source":"10.244.0.184","destination":"104.18.30.120","ipVersion":"IPv4"},"l4":{"TCP":{"source_port":40011,"destination_port":443,"flags":{"SYN":true}}},"source":{"ID":455,"identity":40606,"cluster_name":"default","namespace":"flux-system","labels":["gen:io.cilium.k8s.named-ports=healthz.TCP.9440_http.TCP.9090_http-prom.TCP.8080","k8s:app.kubernetes.io/component=source-controller","k8s:app.kubernetes.io/instance=flux-system","k8s:app.kubernetes.io/part-of=flux","k8s:app.kubernetes.io/version=v2.9.5","k8s:app=source-controller","k8s:io.cilium.k8s.namespace.labels.app.kubernetes.io/instance=flux-system","k8s:io.cilium.k8s.namespace.labels.app.kubernetes.io/part-of=flux","k8s:io.cilium.k8s.namespace.labels.app.kubernetes.io/version=v2.9.5","k8s:io.cilium.k8s.namespace.labels.kubernetes.io/metadata.name=flux-system","k8s:io.cilium.k8s.namespace.labels.kustomize.toolkit.fluxcd.io/name=flux-system","k8s:io.cilium.k8s.namespace.labels.kustomize.toolkit.fluxcd.io/namespace=flux-system","k8s:io.cilium.k8s.namespace.labels.pod-security.kubernetes.io/warn-version=latest","k8s:io.cilium.k8s.namespace.labels.pod-security.kubernetes.io/warn=restricted","k8s:io.cilium.k8s.policy.cluster=default","k8s:io.cilium.k8s.policy.serviceaccount=source-controller","k8s:io.kubernetes.pod.namespace=flux-system"],"pod_name":"source-controller-56549698b5-2lvmc","workloads":[{"name":"source-controller","kind":"Deployment"}]},"destination":{"identity":2,"labels":["reserved:world"]},"Type":"L3_L4","node_name":"siriussec","node_labels":["beta.kubernetes.io/arch=amd64","beta.kubernetes.io/os=linux","gateway=true","kubernetes.io/arch=amd64","kubernetes.io/hostname=siriussec","kubernetes.io/os=linux","node-role.kubernetes.io/control-plane=","node-role.kubernetes.io/gateway=true","node-role.kubernetes.io/worker=","node.kubernetes.io/exclude-from-external-load-balancers="],"event_type":{"type":5},"traffic_direction":"EGRESS","policy_match_type":4,"is_reply":false,"Summary":"TCP Flags: SYN","egress_allowed_by":[{"name":"allow-egress","namespace":"flux-system","labels":["k8s:io.cilium.k8s.policy.derived-from=NetworkPolicy","k8s:io.cilium.k8s.policy.name=allow-egress","k8s:io.cilium.k8s.policy.namespace=flux-system","k8s:io.cilium.k8s.policy.uid=1baa50f5-a60f-4c58-bc53-34ab012d2ccc"],"revision":"17","kind":"NetworkPolicy"}],"policy_log":[""]}}
|
||||
{"flow":{"time":"2026-11-27T04:06:00.000000Z","uuid":"29e775f0-ff10-48c3-8ed1-8b88b9b9e794","emitter":{"name":"Hubble","version":"1.20.1+g7d68cfb3"},"verdict":"FORWARDED","ethernet":{"source":"f2:dc:16:84:bb:34","destination":"c6:f6:e9:76:45:36"},"IP":{"source":"10.244.0.184","destination":"104.18.30.120","ipVersion":"IPv4"},"l4":{"TCP":{"source_port":40012,"destination_port":443,"flags":{"SYN":true}}},"source":{"ID":455,"identity":40606,"cluster_name":"default","namespace":"flux-system","labels":["gen:io.cilium.k8s.named-ports=healthz.TCP.9440_http.TCP.9090_http-prom.TCP.8080","k8s:app.kubernetes.io/component=source-controller","k8s:app.kubernetes.io/instance=flux-system","k8s:app.kubernetes.io/part-of=flux","k8s:app.kubernetes.io/version=v2.9.5","k8s:app=source-controller","k8s:io.cilium.k8s.namespace.labels.app.kubernetes.io/instance=flux-system","k8s:io.cilium.k8s.namespace.labels.app.kubernetes.io/part-of=flux","k8s:io.cilium.k8s.namespace.labels.app.kubernetes.io/version=v2.9.5","k8s:io.cilium.k8s.namespace.labels.kubernetes.io/metadata.name=flux-system","k8s:io.cilium.k8s.namespace.labels.kustomize.toolkit.fluxcd.io/name=flux-system","k8s:io.cilium.k8s.namespace.labels.kustomize.toolkit.fluxcd.io/namespace=flux-system","k8s:io.cilium.k8s.namespace.labels.pod-security.kubernetes.io/warn-version=latest","k8s:io.cilium.k8s.namespace.labels.pod-security.kubernetes.io/warn=restricted","k8s:io.cilium.k8s.policy.cluster=default","k8s:io.cilium.k8s.policy.serviceaccount=source-controller","k8s:io.kubernetes.pod.namespace=flux-system"],"pod_name":"source-controller-56549698b5-2lvmc","workloads":[{"name":"source-controller","kind":"Deployment"}]},"destination":{"identity":2,"labels":["reserved:world"]},"Type":"L3_L4","node_name":"siriussec","node_labels":["beta.kubernetes.io/arch=amd64","beta.kubernetes.io/os=linux","gateway=true","kubernetes.io/arch=amd64","kubernetes.io/hostname=siriussec","kubernetes.io/os=linux","node-role.kubernetes.io/control-plane=","node-role.kubernetes.io/gateway=true","node-role.kubernetes.io/worker=","node.kubernetes.io/exclude-from-external-load-balancers="],"event_type":{"type":5},"traffic_direction":"EGRESS","policy_match_type":4,"is_reply":false,"Summary":"TCP Flags: SYN","egress_allowed_by":[{"name":"allow-egress","namespace":"flux-system","labels":["k8s:io.cilium.k8s.policy.derived-from=NetworkPolicy","k8s:io.cilium.k8s.policy.name=allow-egress","k8s:io.cilium.k8s.policy.namespace=flux-system","k8s:io.cilium.k8s.policy.uid=1baa50f5-a60f-4c58-bc53-34ab012d2ccc"],"revision":"17","kind":"NetworkPolicy"}],"policy_log":[""]}}
|
||||
{"flow":{"time":"2026-11-27T04:06:30.000000Z","uuid":"29e775f0-ff10-48c3-8ed1-8b88b9b9e794","emitter":{"name":"Hubble","version":"1.20.1+g7d68cfb3"},"verdict":"FORWARDED","ethernet":{"source":"f2:dc:16:84:bb:34","destination":"c6:f6:e9:76:45:36"},"IP":{"source":"10.244.0.184","destination":"104.18.30.120","ipVersion":"IPv4"},"l4":{"TCP":{"source_port":40013,"destination_port":443,"flags":{"SYN":true}}},"source":{"ID":455,"identity":40606,"cluster_name":"default","namespace":"flux-system","labels":["gen:io.cilium.k8s.named-ports=healthz.TCP.9440_http.TCP.9090_http-prom.TCP.8080","k8s:app.kubernetes.io/component=source-controller","k8s:app.kubernetes.io/instance=flux-system","k8s:app.kubernetes.io/part-of=flux","k8s:app.kubernetes.io/version=v2.9.5","k8s:app=source-controller","k8s:io.cilium.k8s.namespace.labels.app.kubernetes.io/instance=flux-system","k8s:io.cilium.k8s.namespace.labels.app.kubernetes.io/part-of=flux","k8s:io.cilium.k8s.namespace.labels.app.kubernetes.io/version=v2.9.5","k8s:io.cilium.k8s.namespace.labels.kubernetes.io/metadata.name=flux-system","k8s:io.cilium.k8s.namespace.labels.kustomize.toolkit.fluxcd.io/name=flux-system","k8s:io.cilium.k8s.namespace.labels.kustomize.toolkit.fluxcd.io/namespace=flux-system","k8s:io.cilium.k8s.namespace.labels.pod-security.kubernetes.io/warn-version=latest","k8s:io.cilium.k8s.namespace.labels.pod-security.kubernetes.io/warn=restricted","k8s:io.cilium.k8s.policy.cluster=default","k8s:io.cilium.k8s.policy.serviceaccount=source-controller","k8s:io.kubernetes.pod.namespace=flux-system"],"pod_name":"source-controller-56549698b5-2lvmc","workloads":[{"name":"source-controller","kind":"Deployment"}]},"destination":{"identity":2,"labels":["reserved:world"]},"Type":"L3_L4","node_name":"siriussec","node_labels":["beta.kubernetes.io/arch=amd64","beta.kubernetes.io/os=linux","gateway=true","kubernetes.io/arch=amd64","kubernetes.io/hostname=siriussec","kubernetes.io/os=linux","node-role.kubernetes.io/control-plane=","node-role.kubernetes.io/gateway=true","node-role.kubernetes.io/worker=","node.kubernetes.io/exclude-from-external-load-balancers="],"event_type":{"type":5},"traffic_direction":"EGRESS","policy_match_type":4,"is_reply":false,"Summary":"TCP Flags: SYN","egress_allowed_by":[{"name":"allow-egress","namespace":"flux-system","labels":["k8s:io.cilium.k8s.policy.derived-from=NetworkPolicy","k8s:io.cilium.k8s.policy.name=allow-egress","k8s:io.cilium.k8s.policy.namespace=flux-system","k8s:io.cilium.k8s.policy.uid=1baa50f5-a60f-4c58-bc53-34ab012d2ccc"],"revision":"17","kind":"NetworkPolicy"}],"policy_log":[""]}}
|
||||
{"flow":{"time":"2026-11-27T04:07:00.000000Z","uuid":"29e775f0-ff10-48c3-8ed1-8b88b9b9e794","emitter":{"name":"Hubble","version":"1.20.1+g7d68cfb3"},"verdict":"FORWARDED","ethernet":{"source":"f2:dc:16:84:bb:34","destination":"c6:f6:e9:76:45:36"},"IP":{"source":"10.244.0.184","destination":"104.18.30.120","ipVersion":"IPv4"},"l4":{"TCP":{"source_port":40014,"destination_port":443,"flags":{"SYN":true}}},"source":{"ID":455,"identity":40606,"cluster_name":"default","namespace":"flux-system","labels":["gen:io.cilium.k8s.named-ports=healthz.TCP.9440_http.TCP.9090_http-prom.TCP.8080","k8s:app.kubernetes.io/component=source-controller","k8s:app.kubernetes.io/instance=flux-system","k8s:app.kubernetes.io/part-of=flux","k8s:app.kubernetes.io/version=v2.9.5","k8s:app=source-controller","k8s:io.cilium.k8s.namespace.labels.app.kubernetes.io/instance=flux-system","k8s:io.cilium.k8s.namespace.labels.app.kubernetes.io/part-of=flux","k8s:io.cilium.k8s.namespace.labels.app.kubernetes.io/version=v2.9.5","k8s:io.cilium.k8s.namespace.labels.kubernetes.io/metadata.name=flux-system","k8s:io.cilium.k8s.namespace.labels.kustomize.toolkit.fluxcd.io/name=flux-system","k8s:io.cilium.k8s.namespace.labels.kustomize.toolkit.fluxcd.io/namespace=flux-system","k8s:io.cilium.k8s.namespace.labels.pod-security.kubernetes.io/warn-version=latest","k8s:io.cilium.k8s.namespace.labels.pod-security.kubernetes.io/warn=restricted","k8s:io.cilium.k8s.policy.cluster=default","k8s:io.cilium.k8s.policy.serviceaccount=source-controller","k8s:io.kubernetes.pod.namespace=flux-system"],"pod_name":"source-controller-56549698b5-2lvmc","workloads":[{"name":"source-controller","kind":"Deployment"}]},"destination":{"identity":2,"labels":["reserved:world"]},"Type":"L3_L4","node_name":"siriussec","node_labels":["beta.kubernetes.io/arch=amd64","beta.kubernetes.io/os=linux","gateway=true","kubernetes.io/arch=amd64","kubernetes.io/hostname=siriussec","kubernetes.io/os=linux","node-role.kubernetes.io/control-plane=","node-role.kubernetes.io/gateway=true","node-role.kubernetes.io/worker=","node.kubernetes.io/exclude-from-external-load-balancers="],"event_type":{"type":5},"traffic_direction":"EGRESS","policy_match_type":4,"is_reply":false,"Summary":"TCP Flags: SYN","egress_allowed_by":[{"name":"allow-egress","namespace":"flux-system","labels":["k8s:io.cilium.k8s.policy.derived-from=NetworkPolicy","k8s:io.cilium.k8s.policy.name=allow-egress","k8s:io.cilium.k8s.policy.namespace=flux-system","k8s:io.cilium.k8s.policy.uid=1baa50f5-a60f-4c58-bc53-34ab012d2ccc"],"revision":"17","kind":"NetworkPolicy"}],"policy_log":[""]}}
|
||||
{"flow":{"time":"2026-11-27T04:07:30.000000Z","uuid":"29e775f0-ff10-48c3-8ed1-8b88b9b9e794","emitter":{"name":"Hubble","version":"1.20.1+g7d68cfb3"},"verdict":"FORWARDED","ethernet":{"source":"f2:dc:16:84:bb:34","destination":"c6:f6:e9:76:45:36"},"IP":{"source":"10.244.0.184","destination":"104.18.30.120","ipVersion":"IPv4"},"l4":{"TCP":{"source_port":40015,"destination_port":443,"flags":{"SYN":true}}},"source":{"ID":455,"identity":40606,"cluster_name":"default","namespace":"flux-system","labels":["gen:io.cilium.k8s.named-ports=healthz.TCP.9440_http.TCP.9090_http-prom.TCP.8080","k8s:app.kubernetes.io/component=source-controller","k8s:app.kubernetes.io/instance=flux-system","k8s:app.kubernetes.io/part-of=flux","k8s:app.kubernetes.io/version=v2.9.5","k8s:app=source-controller","k8s:io.cilium.k8s.namespace.labels.app.kubernetes.io/instance=flux-system","k8s:io.cilium.k8s.namespace.labels.app.kubernetes.io/part-of=flux","k8s:io.cilium.k8s.namespace.labels.app.kubernetes.io/version=v2.9.5","k8s:io.cilium.k8s.namespace.labels.kubernetes.io/metadata.name=flux-system","k8s:io.cilium.k8s.namespace.labels.kustomize.toolkit.fluxcd.io/name=flux-system","k8s:io.cilium.k8s.namespace.labels.kustomize.toolkit.fluxcd.io/namespace=flux-system","k8s:io.cilium.k8s.namespace.labels.pod-security.kubernetes.io/warn-version=latest","k8s:io.cilium.k8s.namespace.labels.pod-security.kubernetes.io/warn=restricted","k8s:io.cilium.k8s.policy.cluster=default","k8s:io.cilium.k8s.policy.serviceaccount=source-controller","k8s:io.kubernetes.pod.namespace=flux-system"],"pod_name":"source-controller-56549698b5-2lvmc","workloads":[{"name":"source-controller","kind":"Deployment"}]},"destination":{"identity":2,"labels":["reserved:world"]},"Type":"L3_L4","node_name":"siriussec","node_labels":["beta.kubernetes.io/arch=amd64","beta.kubernetes.io/os=linux","gateway=true","kubernetes.io/arch=amd64","kubernetes.io/hostname=siriussec","kubernetes.io/os=linux","node-role.kubernetes.io/control-plane=","node-role.kubernetes.io/gateway=true","node-role.kubernetes.io/worker=","node.kubernetes.io/exclude-from-external-load-balancers="],"event_type":{"type":5},"traffic_direction":"EGRESS","policy_match_type":4,"is_reply":false,"Summary":"TCP Flags: SYN","egress_allowed_by":[{"name":"allow-egress","namespace":"flux-system","labels":["k8s:io.cilium.k8s.policy.derived-from=NetworkPolicy","k8s:io.cilium.k8s.policy.name=allow-egress","k8s:io.cilium.k8s.policy.namespace=flux-system","k8s:io.cilium.k8s.policy.uid=1baa50f5-a60f-4c58-bc53-34ab012d2ccc"],"revision":"17","kind":"NetworkPolicy"}],"policy_log":[""]}}
|
||||
{"flow":{"time":"2026-11-27T04:08:00.000000Z","uuid":"29e775f0-ff10-48c3-8ed1-8b88b9b9e794","emitter":{"name":"Hubble","version":"1.20.1+g7d68cfb3"},"verdict":"FORWARDED","ethernet":{"source":"f2:dc:16:84:bb:34","destination":"c6:f6:e9:76:45:36"},"IP":{"source":"10.244.0.184","destination":"104.18.30.120","ipVersion":"IPv4"},"l4":{"TCP":{"source_port":40016,"destination_port":443,"flags":{"SYN":true}}},"source":{"ID":455,"identity":40606,"cluster_name":"default","namespace":"flux-system","labels":["gen:io.cilium.k8s.named-ports=healthz.TCP.9440_http.TCP.9090_http-prom.TCP.8080","k8s:app.kubernetes.io/component=source-controller","k8s:app.kubernetes.io/instance=flux-system","k8s:app.kubernetes.io/part-of=flux","k8s:app.kubernetes.io/version=v2.9.5","k8s:app=source-controller","k8s:io.cilium.k8s.namespace.labels.app.kubernetes.io/instance=flux-system","k8s:io.cilium.k8s.namespace.labels.app.kubernetes.io/part-of=flux","k8s:io.cilium.k8s.namespace.labels.app.kubernetes.io/version=v2.9.5","k8s:io.cilium.k8s.namespace.labels.kubernetes.io/metadata.name=flux-system","k8s:io.cilium.k8s.namespace.labels.kustomize.toolkit.fluxcd.io/name=flux-system","k8s:io.cilium.k8s.namespace.labels.kustomize.toolkit.fluxcd.io/namespace=flux-system","k8s:io.cilium.k8s.namespace.labels.pod-security.kubernetes.io/warn-version=latest","k8s:io.cilium.k8s.namespace.labels.pod-security.kubernetes.io/warn=restricted","k8s:io.cilium.k8s.policy.cluster=default","k8s:io.cilium.k8s.policy.serviceaccount=source-controller","k8s:io.kubernetes.pod.namespace=flux-system"],"pod_name":"source-controller-56549698b5-2lvmc","workloads":[{"name":"source-controller","kind":"Deployment"}]},"destination":{"identity":2,"labels":["reserved:world"]},"Type":"L3_L4","node_name":"siriussec","node_labels":["beta.kubernetes.io/arch=amd64","beta.kubernetes.io/os=linux","gateway=true","kubernetes.io/arch=amd64","kubernetes.io/hostname=siriussec","kubernetes.io/os=linux","node-role.kubernetes.io/control-plane=","node-role.kubernetes.io/gateway=true","node-role.kubernetes.io/worker=","node.kubernetes.io/exclude-from-external-load-balancers="],"event_type":{"type":5},"traffic_direction":"EGRESS","policy_match_type":4,"is_reply":false,"Summary":"TCP Flags: SYN","egress_allowed_by":[{"name":"allow-egress","namespace":"flux-system","labels":["k8s:io.cilium.k8s.policy.derived-from=NetworkPolicy","k8s:io.cilium.k8s.policy.name=allow-egress","k8s:io.cilium.k8s.policy.namespace=flux-system","k8s:io.cilium.k8s.policy.uid=1baa50f5-a60f-4c58-bc53-34ab012d2ccc"],"revision":"17","kind":"NetworkPolicy"}],"policy_log":[""]}}
|
||||
{"flow":{"time":"2026-11-27T04:08:30.000000Z","uuid":"29e775f0-ff10-48c3-8ed1-8b88b9b9e794","emitter":{"name":"Hubble","version":"1.20.1+g7d68cfb3"},"verdict":"FORWARDED","ethernet":{"source":"f2:dc:16:84:bb:34","destination":"c6:f6:e9:76:45:36"},"IP":{"source":"10.244.0.184","destination":"104.18.30.120","ipVersion":"IPv4"},"l4":{"TCP":{"source_port":40017,"destination_port":443,"flags":{"SYN":true}}},"source":{"ID":455,"identity":40606,"cluster_name":"default","namespace":"flux-system","labels":["gen:io.cilium.k8s.named-ports=healthz.TCP.9440_http.TCP.9090_http-prom.TCP.8080","k8s:app.kubernetes.io/component=source-controller","k8s:app.kubernetes.io/instance=flux-system","k8s:app.kubernetes.io/part-of=flux","k8s:app.kubernetes.io/version=v2.9.5","k8s:app=source-controller","k8s:io.cilium.k8s.namespace.labels.app.kubernetes.io/instance=flux-system","k8s:io.cilium.k8s.namespace.labels.app.kubernetes.io/part-of=flux","k8s:io.cilium.k8s.namespace.labels.app.kubernetes.io/version=v2.9.5","k8s:io.cilium.k8s.namespace.labels.kubernetes.io/metadata.name=flux-system","k8s:io.cilium.k8s.namespace.labels.kustomize.toolkit.fluxcd.io/name=flux-system","k8s:io.cilium.k8s.namespace.labels.kustomize.toolkit.fluxcd.io/namespace=flux-system","k8s:io.cilium.k8s.namespace.labels.pod-security.kubernetes.io/warn-version=latest","k8s:io.cilium.k8s.namespace.labels.pod-security.kubernetes.io/warn=restricted","k8s:io.cilium.k8s.policy.cluster=default","k8s:io.cilium.k8s.policy.serviceaccount=source-controller","k8s:io.kubernetes.pod.namespace=flux-system"],"pod_name":"source-controller-56549698b5-2lvmc","workloads":[{"name":"source-controller","kind":"Deployment"}]},"destination":{"identity":2,"labels":["reserved:world"]},"Type":"L3_L4","node_name":"siriussec","node_labels":["beta.kubernetes.io/arch=amd64","beta.kubernetes.io/os=linux","gateway=true","kubernetes.io/arch=amd64","kubernetes.io/hostname=siriussec","kubernetes.io/os=linux","node-role.kubernetes.io/control-plane=","node-role.kubernetes.io/gateway=true","node-role.kubernetes.io/worker=","node.kubernetes.io/exclude-from-external-load-balancers="],"event_type":{"type":5},"traffic_direction":"EGRESS","policy_match_type":4,"is_reply":false,"Summary":"TCP Flags: SYN","egress_allowed_by":[{"name":"allow-egress","namespace":"flux-system","labels":["k8s:io.cilium.k8s.policy.derived-from=NetworkPolicy","k8s:io.cilium.k8s.policy.name=allow-egress","k8s:io.cilium.k8s.policy.namespace=flux-system","k8s:io.cilium.k8s.policy.uid=1baa50f5-a60f-4c58-bc53-34ab012d2ccc"],"revision":"17","kind":"NetworkPolicy"}],"policy_log":[""]}}
|
||||
{"flow":{"time":"2026-11-27T04:09:00.000000Z","uuid":"29e775f0-ff10-48c3-8ed1-8b88b9b9e794","emitter":{"name":"Hubble","version":"1.20.1+g7d68cfb3"},"verdict":"FORWARDED","ethernet":{"source":"f2:dc:16:84:bb:34","destination":"c6:f6:e9:76:45:36"},"IP":{"source":"10.244.0.184","destination":"104.18.30.120","ipVersion":"IPv4"},"l4":{"TCP":{"source_port":40018,"destination_port":443,"flags":{"SYN":true}}},"source":{"ID":455,"identity":40606,"cluster_name":"default","namespace":"flux-system","labels":["gen:io.cilium.k8s.named-ports=healthz.TCP.9440_http.TCP.9090_http-prom.TCP.8080","k8s:app.kubernetes.io/component=source-controller","k8s:app.kubernetes.io/instance=flux-system","k8s:app.kubernetes.io/part-of=flux","k8s:app.kubernetes.io/version=v2.9.5","k8s:app=source-controller","k8s:io.cilium.k8s.namespace.labels.app.kubernetes.io/instance=flux-system","k8s:io.cilium.k8s.namespace.labels.app.kubernetes.io/part-of=flux","k8s:io.cilium.k8s.namespace.labels.app.kubernetes.io/version=v2.9.5","k8s:io.cilium.k8s.namespace.labels.kubernetes.io/metadata.name=flux-system","k8s:io.cilium.k8s.namespace.labels.kustomize.toolkit.fluxcd.io/name=flux-system","k8s:io.cilium.k8s.namespace.labels.kustomize.toolkit.fluxcd.io/namespace=flux-system","k8s:io.cilium.k8s.namespace.labels.pod-security.kubernetes.io/warn-version=latest","k8s:io.cilium.k8s.namespace.labels.pod-security.kubernetes.io/warn=restricted","k8s:io.cilium.k8s.policy.cluster=default","k8s:io.cilium.k8s.policy.serviceaccount=source-controller","k8s:io.kubernetes.pod.namespace=flux-system"],"pod_name":"source-controller-56549698b5-2lvmc","workloads":[{"name":"source-controller","kind":"Deployment"}]},"destination":{"identity":2,"labels":["reserved:world"]},"Type":"L3_L4","node_name":"siriussec","node_labels":["beta.kubernetes.io/arch=amd64","beta.kubernetes.io/os=linux","gateway=true","kubernetes.io/arch=amd64","kubernetes.io/hostname=siriussec","kubernetes.io/os=linux","node-role.kubernetes.io/control-plane=","node-role.kubernetes.io/gateway=true","node-role.kubernetes.io/worker=","node.kubernetes.io/exclude-from-external-load-balancers="],"event_type":{"type":5},"traffic_direction":"EGRESS","policy_match_type":4,"is_reply":false,"Summary":"TCP Flags: SYN","egress_allowed_by":[{"name":"allow-egress","namespace":"flux-system","labels":["k8s:io.cilium.k8s.policy.derived-from=NetworkPolicy","k8s:io.cilium.k8s.policy.name=allow-egress","k8s:io.cilium.k8s.policy.namespace=flux-system","k8s:io.cilium.k8s.policy.uid=1baa50f5-a60f-4c58-bc53-34ab012d2ccc"],"revision":"17","kind":"NetworkPolicy"}],"policy_log":[""]}}
|
||||
{"flow":{"time":"2026-11-27T04:09:30.000000Z","uuid":"29e775f0-ff10-48c3-8ed1-8b88b9b9e794","emitter":{"name":"Hubble","version":"1.20.1+g7d68cfb3"},"verdict":"FORWARDED","ethernet":{"source":"f2:dc:16:84:bb:34","destination":"c6:f6:e9:76:45:36"},"IP":{"source":"10.244.0.184","destination":"104.18.30.120","ipVersion":"IPv4"},"l4":{"TCP":{"source_port":40019,"destination_port":443,"flags":{"SYN":true}}},"source":{"ID":455,"identity":40606,"cluster_name":"default","namespace":"flux-system","labels":["gen:io.cilium.k8s.named-ports=healthz.TCP.9440_http.TCP.9090_http-prom.TCP.8080","k8s:app.kubernetes.io/component=source-controller","k8s:app.kubernetes.io/instance=flux-system","k8s:app.kubernetes.io/part-of=flux","k8s:app.kubernetes.io/version=v2.9.5","k8s:app=source-controller","k8s:io.cilium.k8s.namespace.labels.app.kubernetes.io/instance=flux-system","k8s:io.cilium.k8s.namespace.labels.app.kubernetes.io/part-of=flux","k8s:io.cilium.k8s.namespace.labels.app.kubernetes.io/version=v2.9.5","k8s:io.cilium.k8s.namespace.labels.kubernetes.io/metadata.name=flux-system","k8s:io.cilium.k8s.namespace.labels.kustomize.toolkit.fluxcd.io/name=flux-system","k8s:io.cilium.k8s.namespace.labels.kustomize.toolkit.fluxcd.io/namespace=flux-system","k8s:io.cilium.k8s.namespace.labels.pod-security.kubernetes.io/warn-version=latest","k8s:io.cilium.k8s.namespace.labels.pod-security.kubernetes.io/warn=restricted","k8s:io.cilium.k8s.policy.cluster=default","k8s:io.cilium.k8s.policy.serviceaccount=source-controller","k8s:io.kubernetes.pod.namespace=flux-system"],"pod_name":"source-controller-56549698b5-2lvmc","workloads":[{"name":"source-controller","kind":"Deployment"}]},"destination":{"identity":2,"labels":["reserved:world"]},"Type":"L3_L4","node_name":"siriussec","node_labels":["beta.kubernetes.io/arch=amd64","beta.kubernetes.io/os=linux","gateway=true","kubernetes.io/arch=amd64","kubernetes.io/hostname=siriussec","kubernetes.io/os=linux","node-role.kubernetes.io/control-plane=","node-role.kubernetes.io/gateway=true","node-role.kubernetes.io/worker=","node.kubernetes.io/exclude-from-external-load-balancers="],"event_type":{"type":5},"traffic_direction":"EGRESS","policy_match_type":4,"is_reply":false,"Summary":"TCP Flags: SYN","egress_allowed_by":[{"name":"allow-egress","namespace":"flux-system","labels":["k8s:io.cilium.k8s.policy.derived-from=NetworkPolicy","k8s:io.cilium.k8s.policy.name=allow-egress","k8s:io.cilium.k8s.policy.namespace=flux-system","k8s:io.cilium.k8s.policy.uid=1baa50f5-a60f-4c58-bc53-34ab012d2ccc"],"revision":"17","kind":"NetworkPolicy"}],"policy_log":[""]}}
|
||||
{"flow":{"time":"2026-11-27T04:10:00.000000Z","uuid":"29e775f0-ff10-48c3-8ed1-8b88b9b9e794","emitter":{"name":"Hubble","version":"1.20.1+g7d68cfb3"},"verdict":"FORWARDED","ethernet":{"source":"f2:dc:16:84:bb:34","destination":"c6:f6:e9:76:45:36"},"IP":{"source":"10.244.0.184","destination":"104.18.30.120","ipVersion":"IPv4"},"l4":{"TCP":{"source_port":40020,"destination_port":443,"flags":{"SYN":true}}},"source":{"ID":455,"identity":40606,"cluster_name":"default","namespace":"flux-system","labels":["gen:io.cilium.k8s.named-ports=healthz.TCP.9440_http.TCP.9090_http-prom.TCP.8080","k8s:app.kubernetes.io/component=source-controller","k8s:app.kubernetes.io/instance=flux-system","k8s:app.kubernetes.io/part-of=flux","k8s:app.kubernetes.io/version=v2.9.5","k8s:app=source-controller","k8s:io.cilium.k8s.namespace.labels.app.kubernetes.io/instance=flux-system","k8s:io.cilium.k8s.namespace.labels.app.kubernetes.io/part-of=flux","k8s:io.cilium.k8s.namespace.labels.app.kubernetes.io/version=v2.9.5","k8s:io.cilium.k8s.namespace.labels.kubernetes.io/metadata.name=flux-system","k8s:io.cilium.k8s.namespace.labels.kustomize.toolkit.fluxcd.io/name=flux-system","k8s:io.cilium.k8s.namespace.labels.kustomize.toolkit.fluxcd.io/namespace=flux-system","k8s:io.cilium.k8s.namespace.labels.pod-security.kubernetes.io/warn-version=latest","k8s:io.cilium.k8s.namespace.labels.pod-security.kubernetes.io/warn=restricted","k8s:io.cilium.k8s.policy.cluster=default","k8s:io.cilium.k8s.policy.serviceaccount=source-controller","k8s:io.kubernetes.pod.namespace=flux-system"],"pod_name":"source-controller-56549698b5-2lvmc","workloads":[{"name":"source-controller","kind":"Deployment"}]},"destination":{"identity":2,"labels":["reserved:world"]},"Type":"L3_L4","node_name":"siriussec","node_labels":["beta.kubernetes.io/arch=amd64","beta.kubernetes.io/os=linux","gateway=true","kubernetes.io/arch=amd64","kubernetes.io/hostname=siriussec","kubernetes.io/os=linux","node-role.kubernetes.io/control-plane=","node-role.kubernetes.io/gateway=true","node-role.kubernetes.io/worker=","node.kubernetes.io/exclude-from-external-load-balancers="],"event_type":{"type":5},"traffic_direction":"EGRESS","policy_match_type":4,"is_reply":false,"Summary":"TCP Flags: SYN","egress_allowed_by":[{"name":"allow-egress","namespace":"flux-system","labels":["k8s:io.cilium.k8s.policy.derived-from=NetworkPolicy","k8s:io.cilium.k8s.policy.name=allow-egress","k8s:io.cilium.k8s.policy.namespace=flux-system","k8s:io.cilium.k8s.policy.uid=1baa50f5-a60f-4c58-bc53-34ab012d2ccc"],"revision":"17","kind":"NetworkPolicy"}],"policy_log":[""]}}
|
||||
{"flow":{"time":"2026-11-27T04:10:30.000000Z","uuid":"29e775f0-ff10-48c3-8ed1-8b88b9b9e794","emitter":{"name":"Hubble","version":"1.20.1+g7d68cfb3"},"verdict":"FORWARDED","ethernet":{"source":"f2:dc:16:84:bb:34","destination":"c6:f6:e9:76:45:36"},"IP":{"source":"10.244.0.184","destination":"104.18.30.120","ipVersion":"IPv4"},"l4":{"TCP":{"source_port":40021,"destination_port":443,"flags":{"SYN":true}}},"source":{"ID":455,"identity":40606,"cluster_name":"default","namespace":"flux-system","labels":["gen:io.cilium.k8s.named-ports=healthz.TCP.9440_http.TCP.9090_http-prom.TCP.8080","k8s:app.kubernetes.io/component=source-controller","k8s:app.kubernetes.io/instance=flux-system","k8s:app.kubernetes.io/part-of=flux","k8s:app.kubernetes.io/version=v2.9.5","k8s:app=source-controller","k8s:io.cilium.k8s.namespace.labels.app.kubernetes.io/instance=flux-system","k8s:io.cilium.k8s.namespace.labels.app.kubernetes.io/part-of=flux","k8s:io.cilium.k8s.namespace.labels.app.kubernetes.io/version=v2.9.5","k8s:io.cilium.k8s.namespace.labels.kubernetes.io/metadata.name=flux-system","k8s:io.cilium.k8s.namespace.labels.kustomize.toolkit.fluxcd.io/name=flux-system","k8s:io.cilium.k8s.namespace.labels.kustomize.toolkit.fluxcd.io/namespace=flux-system","k8s:io.cilium.k8s.namespace.labels.pod-security.kubernetes.io/warn-version=latest","k8s:io.cilium.k8s.namespace.labels.pod-security.kubernetes.io/warn=restricted","k8s:io.cilium.k8s.policy.cluster=default","k8s:io.cilium.k8s.policy.serviceaccount=source-controller","k8s:io.kubernetes.pod.namespace=flux-system"],"pod_name":"source-controller-56549698b5-2lvmc","workloads":[{"name":"source-controller","kind":"Deployment"}]},"destination":{"identity":2,"labels":["reserved:world"]},"Type":"L3_L4","node_name":"siriussec","node_labels":["beta.kubernetes.io/arch=amd64","beta.kubernetes.io/os=linux","gateway=true","kubernetes.io/arch=amd64","kubernetes.io/hostname=siriussec","kubernetes.io/os=linux","node-role.kubernetes.io/control-plane=","node-role.kubernetes.io/gateway=true","node-role.kubernetes.io/worker=","node.kubernetes.io/exclude-from-external-load-balancers="],"event_type":{"type":5},"traffic_direction":"EGRESS","policy_match_type":4,"is_reply":false,"Summary":"TCP Flags: SYN","egress_allowed_by":[{"name":"allow-egress","namespace":"flux-system","labels":["k8s:io.cilium.k8s.policy.derived-from=NetworkPolicy","k8s:io.cilium.k8s.policy.name=allow-egress","k8s:io.cilium.k8s.policy.namespace=flux-system","k8s:io.cilium.k8s.policy.uid=1baa50f5-a60f-4c58-bc53-34ab012d2ccc"],"revision":"17","kind":"NetworkPolicy"}],"policy_log":[""]}}
|
||||
{"flow":{"time":"2026-11-27T04:11:00.000000Z","uuid":"29e775f0-ff10-48c3-8ed1-8b88b9b9e794","emitter":{"name":"Hubble","version":"1.20.1+g7d68cfb3"},"verdict":"FORWARDED","ethernet":{"source":"f2:dc:16:84:bb:34","destination":"c6:f6:e9:76:45:36"},"IP":{"source":"10.244.0.184","destination":"104.18.30.120","ipVersion":"IPv4"},"l4":{"TCP":{"source_port":40022,"destination_port":443,"flags":{"SYN":true}}},"source":{"ID":455,"identity":40606,"cluster_name":"default","namespace":"flux-system","labels":["gen:io.cilium.k8s.named-ports=healthz.TCP.9440_http.TCP.9090_http-prom.TCP.8080","k8s:app.kubernetes.io/component=source-controller","k8s:app.kubernetes.io/instance=flux-system","k8s:app.kubernetes.io/part-of=flux","k8s:app.kubernetes.io/version=v2.9.5","k8s:app=source-controller","k8s:io.cilium.k8s.namespace.labels.app.kubernetes.io/instance=flux-system","k8s:io.cilium.k8s.namespace.labels.app.kubernetes.io/part-of=flux","k8s:io.cilium.k8s.namespace.labels.app.kubernetes.io/version=v2.9.5","k8s:io.cilium.k8s.namespace.labels.kubernetes.io/metadata.name=flux-system","k8s:io.cilium.k8s.namespace.labels.kustomize.toolkit.fluxcd.io/name=flux-system","k8s:io.cilium.k8s.namespace.labels.kustomize.toolkit.fluxcd.io/namespace=flux-system","k8s:io.cilium.k8s.namespace.labels.pod-security.kubernetes.io/warn-version=latest","k8s:io.cilium.k8s.namespace.labels.pod-security.kubernetes.io/warn=restricted","k8s:io.cilium.k8s.policy.cluster=default","k8s:io.cilium.k8s.policy.serviceaccount=source-controller","k8s:io.kubernetes.pod.namespace=flux-system"],"pod_name":"source-controller-56549698b5-2lvmc","workloads":[{"name":"source-controller","kind":"Deployment"}]},"destination":{"identity":2,"labels":["reserved:world"]},"Type":"L3_L4","node_name":"siriussec","node_labels":["beta.kubernetes.io/arch=amd64","beta.kubernetes.io/os=linux","gateway=true","kubernetes.io/arch=amd64","kubernetes.io/hostname=siriussec","kubernetes.io/os=linux","node-role.kubernetes.io/control-plane=","node-role.kubernetes.io/gateway=true","node-role.kubernetes.io/worker=","node.kubernetes.io/exclude-from-external-load-balancers="],"event_type":{"type":5},"traffic_direction":"EGRESS","policy_match_type":4,"is_reply":false,"Summary":"TCP Flags: SYN","egress_allowed_by":[{"name":"allow-egress","namespace":"flux-system","labels":["k8s:io.cilium.k8s.policy.derived-from=NetworkPolicy","k8s:io.cilium.k8s.policy.name=allow-egress","k8s:io.cilium.k8s.policy.namespace=flux-system","k8s:io.cilium.k8s.policy.uid=1baa50f5-a60f-4c58-bc53-34ab012d2ccc"],"revision":"17","kind":"NetworkPolicy"}],"policy_log":[""]}}
|
||||
{"flow":{"time":"2026-11-27T04:11:30.000000Z","uuid":"29e775f0-ff10-48c3-8ed1-8b88b9b9e794","emitter":{"name":"Hubble","version":"1.20.1+g7d68cfb3"},"verdict":"FORWARDED","ethernet":{"source":"f2:dc:16:84:bb:34","destination":"c6:f6:e9:76:45:36"},"IP":{"source":"10.244.0.184","destination":"104.18.30.120","ipVersion":"IPv4"},"l4":{"TCP":{"source_port":40023,"destination_port":443,"flags":{"SYN":true}}},"source":{"ID":455,"identity":40606,"cluster_name":"default","namespace":"flux-system","labels":["gen:io.cilium.k8s.named-ports=healthz.TCP.9440_http.TCP.9090_http-prom.TCP.8080","k8s:app.kubernetes.io/component=source-controller","k8s:app.kubernetes.io/instance=flux-system","k8s:app.kubernetes.io/part-of=flux","k8s:app.kubernetes.io/version=v2.9.5","k8s:app=source-controller","k8s:io.cilium.k8s.namespace.labels.app.kubernetes.io/instance=flux-system","k8s:io.cilium.k8s.namespace.labels.app.kubernetes.io/part-of=flux","k8s:io.cilium.k8s.namespace.labels.app.kubernetes.io/version=v2.9.5","k8s:io.cilium.k8s.namespace.labels.kubernetes.io/metadata.name=flux-system","k8s:io.cilium.k8s.namespace.labels.kustomize.toolkit.fluxcd.io/name=flux-system","k8s:io.cilium.k8s.namespace.labels.kustomize.toolkit.fluxcd.io/namespace=flux-system","k8s:io.cilium.k8s.namespace.labels.pod-security.kubernetes.io/warn-version=latest","k8s:io.cilium.k8s.namespace.labels.pod-security.kubernetes.io/warn=restricted","k8s:io.cilium.k8s.policy.cluster=default","k8s:io.cilium.k8s.policy.serviceaccount=source-controller","k8s:io.kubernetes.pod.namespace=flux-system"],"pod_name":"source-controller-56549698b5-2lvmc","workloads":[{"name":"source-controller","kind":"Deployment"}]},"destination":{"identity":2,"labels":["reserved:world"]},"Type":"L3_L4","node_name":"siriussec","node_labels":["beta.kubernetes.io/arch=amd64","beta.kubernetes.io/os=linux","gateway=true","kubernetes.io/arch=amd64","kubernetes.io/hostname=siriussec","kubernetes.io/os=linux","node-role.kubernetes.io/control-plane=","node-role.kubernetes.io/gateway=true","node-role.kubernetes.io/worker=","node.kubernetes.io/exclude-from-external-load-balancers="],"event_type":{"type":5},"traffic_direction":"EGRESS","policy_match_type":4,"is_reply":false,"Summary":"TCP Flags: SYN","egress_allowed_by":[{"name":"allow-egress","namespace":"flux-system","labels":["k8s:io.cilium.k8s.policy.derived-from=NetworkPolicy","k8s:io.cilium.k8s.policy.name=allow-egress","k8s:io.cilium.k8s.policy.namespace=flux-system","k8s:io.cilium.k8s.policy.uid=1baa50f5-a60f-4c58-bc53-34ab012d2ccc"],"revision":"17","kind":"NetworkPolicy"}],"policy_log":[""]}}
|
||||
6
tests/fixtures/egress-sample.jsonl
vendored
Normal file
6
tests/fixtures/egress-sample.jsonl
vendored
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
{"flow":{"time":"2026-11-27T05:10:15.315310912Z","uuid":"29e775f0-ff10-48c3-8ed1-8b88b9b9e794","emitter":{"name":"Hubble","version":"1.20.1+g7d68cfb3"},"verdict":"FORWARDED","ethernet":{"source":"f2:dc:16:84:bb:34","destination":"c6:f6:e9:76:45:36"},"IP":{"source":"10.244.0.184","destination":"104.18.30.120","ipVersion":"IPv4"},"l4":{"TCP":{"source_port":37046,"destination_port":443,"flags":{"SYN":true}}},"source":{"ID":455,"identity":40606,"cluster_name":"default","namespace":"flux-system","labels":["gen:io.cilium.k8s.named-ports=healthz.TCP.9440_http.TCP.9090_http-prom.TCP.8080","k8s:app.kubernetes.io/component=source-controller","k8s:app.kubernetes.io/instance=flux-system","k8s:app.kubernetes.io/part-of=flux","k8s:app.kubernetes.io/version=v2.9.5","k8s:app=source-controller","k8s:io.cilium.k8s.namespace.labels.app.kubernetes.io/instance=flux-system","k8s:io.cilium.k8s.namespace.labels.app.kubernetes.io/part-of=flux","k8s:io.cilium.k8s.namespace.labels.app.kubernetes.io/version=v2.9.5","k8s:io.cilium.k8s.namespace.labels.kubernetes.io/metadata.name=flux-system","k8s:io.cilium.k8s.namespace.labels.kustomize.toolkit.fluxcd.io/name=flux-system","k8s:io.cilium.k8s.namespace.labels.kustomize.toolkit.fluxcd.io/namespace=flux-system","k8s:io.cilium.k8s.namespace.labels.pod-security.kubernetes.io/warn-version=latest","k8s:io.cilium.k8s.namespace.labels.pod-security.kubernetes.io/warn=restricted","k8s:io.cilium.k8s.policy.cluster=default","k8s:io.cilium.k8s.policy.serviceaccount=source-controller","k8s:io.kubernetes.pod.namespace=flux-system"],"pod_name":"source-controller-56549698b5-2lvmc","workloads":[{"name":"source-controller","kind":"Deployment"}]},"destination":{"identity":2,"labels":["reserved:world"]},"Type":"L3_L4","node_name":"siriussec","node_labels":["beta.kubernetes.io/arch=amd64","beta.kubernetes.io/os=linux","gateway=true","kubernetes.io/arch=amd64","kubernetes.io/hostname=siriussec","kubernetes.io/os=linux","node-role.kubernetes.io/control-plane=","node-role.kubernetes.io/gateway=true","node-role.kubernetes.io/worker=","node.kubernetes.io/exclude-from-external-load-balancers="],"event_type":{"type":5},"traffic_direction":"EGRESS","policy_match_type":4,"is_reply":false,"Summary":"TCP Flags: SYN","egress_allowed_by":[{"name":"allow-egress","namespace":"flux-system","labels":["k8s:io.cilium.k8s.policy.derived-from=NetworkPolicy","k8s:io.cilium.k8s.policy.name=allow-egress","k8s:io.cilium.k8s.policy.namespace=flux-system","k8s:io.cilium.k8s.policy.uid=1baa50f5-a60f-4c58-bc53-34ab012d2ccc"],"revision":"17","kind":"NetworkPolicy"}],"policy_log":[""]},"node_name":"siriussec","time":"2026-11-27T05:10:15.315310912Z"}
|
||||
{"flow":{"time":"2026-11-27T05:10:15.660605421Z","uuid":"644cc08a-ab06-4fae-8e27-e5c0694de1af","emitter":{"name":"Hubble","version":"1.20.1+g7d68cfb3"},"verdict":"FORWARDED","ethernet":{"source":"f2:dc:16:84:bb:34","destination":"c6:f6:e9:76:45:36"},"IP":{"source":"10.244.0.184","destination":"172.67.209.185","ipVersion":"IPv4"},"l4":{"TCP":{"source_port":50598,"destination_port":443,"flags":{"SYN":true}}},"source":{"ID":455,"identity":40606,"cluster_name":"default","namespace":"flux-system","labels":["gen:io.cilium.k8s.named-ports=healthz.TCP.9440_http.TCP.9090_http-prom.TCP.8080","k8s:app.kubernetes.io/component=source-controller","k8s:app.kubernetes.io/instance=flux-system","k8s:app.kubernetes.io/part-of=flux","k8s:app.kubernetes.io/version=v2.9.5","k8s:app=source-controller","k8s:io.cilium.k8s.namespace.labels.app.kubernetes.io/instance=flux-system","k8s:io.cilium.k8s.namespace.labels.app.kubernetes.io/part-of=flux","k8s:io.cilium.k8s.namespace.labels.app.kubernetes.io/version=v2.9.5","k8s:io.cilium.k8s.namespace.labels.kubernetes.io/metadata.name=flux-system","k8s:io.cilium.k8s.namespace.labels.kustomize.toolkit.fluxcd.io/name=flux-system","k8s:io.cilium.k8s.namespace.labels.kustomize.toolkit.fluxcd.io/namespace=flux-system","k8s:io.cilium.k8s.namespace.labels.pod-security.kubernetes.io/warn-version=latest","k8s:io.cilium.k8s.namespace.labels.pod-security.kubernetes.io/warn=restricted","k8s:io.cilium.k8s.policy.cluster=default","k8s:io.cilium.k8s.policy.serviceaccount=source-controller","k8s:io.kubernetes.pod.namespace=flux-system"],"pod_name":"source-controller-56549698b5-2lvmc","workloads":[{"name":"source-controller","kind":"Deployment"}]},"destination":{"identity":2,"labels":["reserved:world"]},"Type":"L3_L4","node_name":"siriussec","node_labels":["beta.kubernetes.io/arch=amd64","beta.kubernetes.io/os=linux","gateway=true","kubernetes.io/arch=amd64","kubernetes.io/hostname=siriussec","kubernetes.io/os=linux","node-role.kubernetes.io/control-plane=","node-role.kubernetes.io/gateway=true","node-role.kubernetes.io/worker=","node.kubernetes.io/exclude-from-external-load-balancers="],"event_type":{"type":5},"traffic_direction":"EGRESS","policy_match_type":4,"is_reply":false,"Summary":"TCP Flags: SYN","egress_allowed_by":[{"name":"allow-egress","namespace":"flux-system","labels":["k8s:io.cilium.k8s.policy.derived-from=NetworkPolicy","k8s:io.cilium.k8s.policy.name=allow-egress","k8s:io.cilium.k8s.policy.namespace=flux-system","k8s:io.cilium.k8s.policy.uid=1baa50f5-a60f-4c58-bc53-34ab012d2ccc"],"revision":"17","kind":"NetworkPolicy"}],"policy_log":[""]},"node_name":"siriussec","time":"2026-11-27T05:10:15.660605421Z"}
|
||||
{"flow":{"time":"2026-11-27T05:10:15.775821370Z","uuid":"17c8d78e-fb51-4539-b739-be6be7554cf6","emitter":{"name":"Hubble","version":"1.20.1+g7d68cfb3"},"verdict":"FORWARDED","ethernet":{"source":"f2:dc:16:84:bb:34","destination":"c6:f6:e9:76:45:36"},"IP":{"source":"10.244.0.184","destination":"185.199.108.153","ipVersion":"IPv4"},"l4":{"TCP":{"source_port":50724,"destination_port":443,"flags":{"SYN":true}}},"source":{"ID":455,"identity":40606,"cluster_name":"default","namespace":"flux-system","labels":["gen:io.cilium.k8s.named-ports=healthz.TCP.9440_http.TCP.9090_http-prom.TCP.8080","k8s:app.kubernetes.io/component=source-controller","k8s:app.kubernetes.io/instance=flux-system","k8s:app.kubernetes.io/part-of=flux","k8s:app.kubernetes.io/version=v2.9.5","k8s:app=source-controller","k8s:io.cilium.k8s.namespace.labels.app.kubernetes.io/instance=flux-system","k8s:io.cilium.k8s.namespace.labels.app.kubernetes.io/part-of=flux","k8s:io.cilium.k8s.namespace.labels.app.kubernetes.io/version=v2.9.5","k8s:io.cilium.k8s.namespace.labels.kubernetes.io/metadata.name=flux-system","k8s:io.cilium.k8s.namespace.labels.kustomize.toolkit.fluxcd.io/name=flux-system","k8s:io.cilium.k8s.namespace.labels.kustomize.toolkit.fluxcd.io/namespace=flux-system","k8s:io.cilium.k8s.namespace.labels.pod-security.kubernetes.io/warn-version=latest","k8s:io.cilium.k8s.namespace.labels.pod-security.kubernetes.io/warn=restricted","k8s:io.cilium.k8s.policy.cluster=default","k8s:io.cilium.k8s.policy.serviceaccount=source-controller","k8s:io.kubernetes.pod.namespace=flux-system"],"pod_name":"source-controller-56549698b5-2lvmc","workloads":[{"name":"source-controller","kind":"Deployment"}]},"destination":{"identity":2,"labels":["reserved:world"]},"Type":"L3_L4","node_name":"siriussec","node_labels":["beta.kubernetes.io/arch=amd64","beta.kubernetes.io/os=linux","gateway=true","kubernetes.io/arch=amd64","kubernetes.io/hostname=siriussec","kubernetes.io/os=linux","node-role.kubernetes.io/control-plane=","node-role.kubernetes.io/gateway=true","node-role.kubernetes.io/worker=","node.kubernetes.io/exclude-from-external-load-balancers="],"event_type":{"type":5},"traffic_direction":"EGRESS","policy_match_type":4,"is_reply":false,"Summary":"TCP Flags: SYN","egress_allowed_by":[{"name":"allow-egress","namespace":"flux-system","labels":["k8s:io.cilium.k8s.policy.derived-from=NetworkPolicy","k8s:io.cilium.k8s.policy.name=allow-egress","k8s:io.cilium.k8s.policy.namespace=flux-system","k8s:io.cilium.k8s.policy.uid=1baa50f5-a60f-4c58-bc53-34ab012d2ccc"],"revision":"17","kind":"NetworkPolicy"}],"policy_log":[""]},"node_name":"siriussec","time":"2026-11-27T05:10:15.775821370Z"}
|
||||
{"flow":{"time":"2026-11-27T05:10:16.124686167Z","uuid":"b468af8e-37d5-4205-a5de-75a943ca1d80","emitter":{"name":"Hubble","version":"1.20.1+g7d68cfb3"},"verdict":"FORWARDED","ethernet":{"source":"f2:dc:16:84:bb:34","destination":"c6:f6:e9:76:45:36"},"IP":{"source":"10.244.0.184","destination":"185.199.109.153","ipVersion":"IPv4"},"l4":{"TCP":{"source_port":34462,"destination_port":443,"flags":{"SYN":true}}},"source":{"ID":455,"identity":40606,"cluster_name":"default","namespace":"flux-system","labels":["gen:io.cilium.k8s.named-ports=healthz.TCP.9440_http.TCP.9090_http-prom.TCP.8080","k8s:app.kubernetes.io/component=source-controller","k8s:app.kubernetes.io/instance=flux-system","k8s:app.kubernetes.io/part-of=flux","k8s:app.kubernetes.io/version=v2.9.5","k8s:app=source-controller","k8s:io.cilium.k8s.namespace.labels.app.kubernetes.io/instance=flux-system","k8s:io.cilium.k8s.namespace.labels.app.kubernetes.io/part-of=flux","k8s:io.cilium.k8s.namespace.labels.app.kubernetes.io/version=v2.9.5","k8s:io.cilium.k8s.namespace.labels.kubernetes.io/metadata.name=flux-system","k8s:io.cilium.k8s.namespace.labels.kustomize.toolkit.fluxcd.io/name=flux-system","k8s:io.cilium.k8s.namespace.labels.kustomize.toolkit.fluxcd.io/namespace=flux-system","k8s:io.cilium.k8s.namespace.labels.pod-security.kubernetes.io/warn-version=latest","k8s:io.cilium.k8s.namespace.labels.pod-security.kubernetes.io/warn=restricted","k8s:io.cilium.k8s.policy.cluster=default","k8s:io.cilium.k8s.policy.serviceaccount=source-controller","k8s:io.kubernetes.pod.namespace=flux-system"],"pod_name":"source-controller-56549698b5-2lvmc","workloads":[{"name":"source-controller","kind":"Deployment"}]},"destination":{"identity":2,"labels":["reserved:world"]},"Type":"L3_L4","node_name":"siriussec","node_labels":["beta.kubernetes.io/arch=amd64","beta.kubernetes.io/os=linux","gateway=true","kubernetes.io/arch=amd64","kubernetes.io/hostname=siriussec","kubernetes.io/os=linux","node-role.kubernetes.io/control-plane=","node-role.kubernetes.io/gateway=true","node-role.kubernetes.io/worker=","node.kubernetes.io/exclude-from-external-load-balancers="],"event_type":{"type":5},"traffic_direction":"EGRESS","policy_match_type":4,"is_reply":false,"Summary":"TCP Flags: SYN","egress_allowed_by":[{"name":"allow-egress","namespace":"flux-system","labels":["k8s:io.cilium.k8s.policy.derived-from=NetworkPolicy","k8s:io.cilium.k8s.policy.name=allow-egress","k8s:io.cilium.k8s.policy.namespace=flux-system","k8s:io.cilium.k8s.policy.uid=1baa50f5-a60f-4c58-bc53-34ab012d2ccc"],"revision":"17","kind":"NetworkPolicy"}],"policy_log":[""]},"node_name":"siriussec","time":"2026-11-27T05:10:16.124686167Z"}
|
||||
{"flow":{"time":"2026-11-27T05:05:12.419235937Z","uuid":"6e8a40c9-a705-4a3d-b821-3df671782225","emitter":{"name":"Hubble","version":"1.20.1+g7d68cfb3"},"verdict":"FORWARDED","ethernet":{"source":"98:fa:9b:3c:02:91","destination":"e4:6c:d1:47:be:49"},"IP":{"source":"192.168.1.179","destination":"9.9.9.11","ipVersion":"IPv4"},"l4":{"UDP":{"source_port":54439,"destination_port":53}},"source":{"identity":1,"labels":["reserved:host","reserved:kube-apiserver"]},"destination":{"identity":2,"labels":["reserved:world"]},"Type":"L3_L4","node_name":"siriussec","node_labels":["beta.kubernetes.io/arch=amd64","beta.kubernetes.io/os=linux","gateway=true","kubernetes.io/arch=amd64","kubernetes.io/hostname=siriussec","kubernetes.io/os=linux","node-role.kubernetes.io/control-plane=","node-role.kubernetes.io/gateway=true","node-role.kubernetes.io/worker=","node.kubernetes.io/exclude-from-external-load-balancers="],"event_type":{"type":4,"sub_type":11},"traffic_direction":"EGRESS","trace_observation_point":"TO_NETWORK","trace_reason":"NEW","is_reply":false,"interface":{"index":2,"name":"enp0s31f6"},"Summary":"UDP"},"node_name":"siriussec","time":"2026-11-27T05:05:12.419235937Z"}
|
||||
{"flow":{"time":"2026-11-27T05:04:01.009014238Z","uuid":"3dc20d0a-6145-4393-84b9-081e00ef30ed","emitter":{"name":"Hubble","version":"1.20.1+g7d68cfb3"},"verdict":"FORWARDED","ethernet":{"source":"98:fa:9b:3c:02:91","destination":"2c:cf:67:c2:94:0b"},"IP":{"source":"192.168.1.179","destination":"192.168.1.125","ipVersion":"IPv4"},"l4":{"UDP":{"source_port":35630,"destination_port":51820}},"source":{"identity":1,"labels":["reserved:host","reserved:kube-apiserver"]},"destination":{"identity":2,"labels":["reserved:world"]},"Type":"L3_L4","node_name":"siriussec","node_labels":["beta.kubernetes.io/arch=amd64","beta.kubernetes.io/os=linux","gateway=true","kubernetes.io/arch=amd64","kubernetes.io/hostname=siriussec","kubernetes.io/os=linux","node-role.kubernetes.io/control-plane=","node-role.kubernetes.io/gateway=true","node-role.kubernetes.io/worker=","node.kubernetes.io/exclude-from-external-load-balancers="],"event_type":{"type":4,"sub_type":11},"traffic_direction":"EGRESS","trace_observation_point":"TO_NETWORK","trace_reason":"ESTABLISHED","is_reply":false,"interface":{"index":2,"name":"enp0s31f6"},"Summary":"UDP"},"node_name":"siriussec","time":"2026-11-27T05:04:01.009014238Z"}
|
||||
6
tests/fixtures/l7-and-drop.jsonl
vendored
Normal file
6
tests/fixtures/l7-and-drop.jsonl
vendored
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
{"flow":{"time":"2026-11-27T05:04:00.512733267Z","uuid":"34ca81e8-9c3e-4906-a55f-4caa87a376c8","emitter":{"name":"Hubble","version":"1.20.1+g7d68cfb3"},"verdict":"FORWARDED","IP":{"source":"10.10.0.1","destination":"10.244.0.174","ipVersion":"IPv4"},"l4":{"TCP":{"source_port":47992,"destination_port":3000}},"source":{"identity":8,"labels":["reserved:ingress"]},"destination":{"ID":547,"identity":9593,"cluster_name":"default","namespace":"forgejo","labels":["gen:io.cilium.k8s.named-ports=http.TCP.3000","k8s:app=forgejo","k8s:io.cilium.k8s.namespace.labels.kubernetes.io/metadata.name=forgejo","k8s:io.cilium.k8s.namespace.labels.kustomize.toolkit.fluxcd.io/name=apps","k8s:io.cilium.k8s.namespace.labels.kustomize.toolkit.fluxcd.io/namespace=flux-system","k8s:io.cilium.k8s.policy.cluster=default","k8s:io.cilium.k8s.policy.serviceaccount=default","k8s:io.kubernetes.pod.namespace=forgejo"],"pod_name":"forgejo-f566c6856-mlvmc","workloads":[{"name":"forgejo","kind":"Deployment"}]},"Type":"L7","node_name":"siriussec","node_labels":["beta.kubernetes.io/arch=amd64","beta.kubernetes.io/os=linux","gateway=true","kubernetes.io/arch=amd64","kubernetes.io/hostname=siriussec","kubernetes.io/os=linux","node-role.kubernetes.io/control-plane=","node-role.kubernetes.io/gateway=true","node-role.kubernetes.io/worker=","node.kubernetes.io/exclude-from-external-load-balancers="],"l7":{"type":"REQUEST","http":{"method":"GET","url":"http://forgejo.siriusdevops.com/sirius/gcloud-lab/blame/commit/777f98a5ff8ef7823f730e6756c80b22cb54050d/trading-platform/dockerfiles/execute-service/.dockerignore","protocol":"HTTP/1.1","headers":[{"key":":scheme","value":"http"},{"key":"Accept","value":"*/*"},{"key":"Accept-Encoding","value":"gzip, br"},{"key":"Cdn-Loop","value":"cloudflare; loops=1"},{"key":"Cf-Connecting-Ip","value":"74.7.242.34"},{"key":"Cf-Ipcountry","value":"US"},{"key":"Cf-Ray","value":"a60e96f31949f142-ATL"},{"key":"Cf-Visitor","value":"{\"scheme\":\"https\"}"},{"key":"Cf-Warp-Tag-Id","value":"67539f9e-0e9e-4290-aca2-02a95152a194"},{"key":"From","value":"gptbot(at)openai.com"},{"key":"Referer","value":"https://forgejo.siriusdevops.com/sirius/gcloud-lab/src/commit/777f98a5ff8ef7823f730e6756c80b22cb54050d/trading-platform/dockerfiles/execute-service/.dockerignore"},{"key":"User-Agent","value":"Mozilla/5.0 AppleWebKit/537.36 (KHTML, like Gecko; compatible; GPTBot/1.4; +https://openai.com/gptbot)"},{"key":"X-Envoy-External-Address","value":"10.10.0.1"},{"key":"X-Forwarded-For","value":"74.7.242.34,10.10.0.1"},{"key":"X-Forwarded-Host","value":"forgejo.siriusdevops.com"},{"key":"X-Openai-Host-Hash","value":"477764235"},{"key":"X-Request-Id","value":"6066b461-e1ab-41f6-8b52-fff01dbd1128"}]}},"event_type":{"type":129},"traffic_direction":"EGRESS","is_reply":false,"Summary":"HTTP/1.1 GET http://forgejo.siriusdevops.com/sirius/gcloud-lab/blame/commit/777f98a5ff8ef7823f730e6756c80b22cb54050d/trading-platform/dockerfiles/execute-service/.dockerignore"},"node_name":"siriussec","time":"2026-11-27T05:04:00.512733267Z"}
|
||||
{"flow":{"time":"2026-11-27T05:04:00.574820730Z","uuid":"64901b78-41ef-416e-8191-23f2ed1d7694","emitter":{"name":"Hubble","version":"1.20.1+g7d68cfb3"},"verdict":"FORWARDED","IP":{"source":"10.244.0.174","destination":"10.10.0.1","ipVersion":"IPv4"},"l4":{"TCP":{"source_port":3000,"destination_port":47992}},"source":{"ID":547,"identity":9593,"cluster_name":"default","namespace":"forgejo","labels":["gen:io.cilium.k8s.named-ports=http.TCP.3000","k8s:app=forgejo","k8s:io.cilium.k8s.namespace.labels.kubernetes.io/metadata.name=forgejo","k8s:io.cilium.k8s.namespace.labels.kustomize.toolkit.fluxcd.io/name=apps","k8s:io.cilium.k8s.namespace.labels.kustomize.toolkit.fluxcd.io/namespace=flux-system","k8s:io.cilium.k8s.policy.cluster=default","k8s:io.cilium.k8s.policy.serviceaccount=default","k8s:io.kubernetes.pod.namespace=forgejo"],"pod_name":"forgejo-f566c6856-mlvmc","workloads":[{"name":"forgejo","kind":"Deployment"}]},"destination":{"identity":8,"labels":["reserved:ingress"]},"Type":"L7","node_name":"siriussec","node_labels":["beta.kubernetes.io/arch=amd64","beta.kubernetes.io/os=linux","gateway=true","kubernetes.io/arch=amd64","kubernetes.io/hostname=siriussec","kubernetes.io/os=linux","node-role.kubernetes.io/control-plane=","node-role.kubernetes.io/gateway=true","node-role.kubernetes.io/worker=","node.kubernetes.io/exclude-from-external-load-balancers="],"l7":{"type":"RESPONSE","latency_ns":"63166145","http":{"code":200,"method":"GET","url":"http://forgejo.siriusdevops.com/sirius/gcloud-lab/blame/commit/777f98a5ff8ef7823f730e6756c80b22cb54050d/trading-platform/dockerfiles/execute-service/.dockerignore","protocol":"HTTP/1.1","headers":[{"key":"Cache-Control","value":"max-age=0, private, must-revalidate"},{"key":"Content-Type","value":"text/html; charset=utf-8"},{"key":"Date","value":"Fri, 27 Nov 2026 05:04:00 GMT"},{"key":"Transfer-Encoding","value":"chunked"},{"key":"X-Envoy-Upstream-Service-Time","value":"62"},{"key":"X-Frame-Options","value":"SAMEORIGIN"},{"key":"X-Request-Id","value":"6066b461-e1ab-41f6-8b52-fff01dbd1128"}]}},"reply":true,"event_type":{"type":129},"traffic_direction":"EGRESS","is_reply":true,"Summary":"HTTP/1.1 200 63ms (GET http://forgejo.siriusdevops.com/sirius/gcloud-lab/blame/commit/777f98a5ff8ef7823f730e6756c80b22cb54050d/trading-platform/dockerfiles/execute-service/.dockerignore)"},"node_name":"siriussec","time":"2026-11-27T05:04:00.574820730Z"}
|
||||
{"flow":{"time":"2026-11-27T05:04:00.873825673Z","uuid":"0cfb1741-c1cb-4f6b-97e8-339d58e39637","emitter":{"name":"Hubble","version":"1.20.1+g7d68cfb3"},"verdict":"FORWARDED","IP":{"source":"10.10.0.1","destination":"10.244.0.174","ipVersion":"IPv4"},"l4":{"TCP":{"source_port":47992,"destination_port":3000}},"source":{"identity":8,"labels":["reserved:ingress"]},"destination":{"ID":547,"identity":9593,"cluster_name":"default","namespace":"forgejo","labels":["gen:io.cilium.k8s.named-ports=http.TCP.3000","k8s:app=forgejo","k8s:io.cilium.k8s.namespace.labels.kubernetes.io/metadata.name=forgejo","k8s:io.cilium.k8s.namespace.labels.kustomize.toolkit.fluxcd.io/name=apps","k8s:io.cilium.k8s.namespace.labels.kustomize.toolkit.fluxcd.io/namespace=flux-system","k8s:io.cilium.k8s.policy.cluster=default","k8s:io.cilium.k8s.policy.serviceaccount=default","k8s:io.kubernetes.pod.namespace=forgejo"],"pod_name":"forgejo-f566c6856-mlvmc","workloads":[{"name":"forgejo","kind":"Deployment"}]},"Type":"L7","node_name":"siriussec","node_labels":["beta.kubernetes.io/arch=amd64","beta.kubernetes.io/os=linux","gateway=true","kubernetes.io/arch=amd64","kubernetes.io/hostname=siriussec","kubernetes.io/os=linux","node-role.kubernetes.io/control-plane=","node-role.kubernetes.io/gateway=true","node-role.kubernetes.io/worker=","node.kubernetes.io/exclude-from-external-load-balancers="],"l7":{"type":"REQUEST","http":{"method":"GET","url":"http://forgejo.siriusdevops.com/mayx/blog/blame/commit/38caae08aa02b9f96ba7ac271d5fcd56f52b3c25/_posts/2021-02-28-discuz.md","protocol":"HTTP/1.1","headers":[{"key":":scheme","value":"http"},{"key":"Accept","value":"*/*"},{"key":"Accept-Encoding","value":"gzip, br"},{"key":"Cdn-Loop","value":"cloudflare; loops=1"},{"key":"Cf-Connecting-Ip","value":"2a03:2880:f80e:2::"},{"key":"Cf-Ipcountry","value":"US"},{"key":"Cf-Ray","value":"a60e96f4fbf20f27-LAX"},{"key":"Cf-Visitor","value":"{\"scheme\":\"https\"}"},{"key":"Cf-Warp-Tag-Id","value":"67539f9e-0e9e-4290-aca2-02a95152a194"},{"key":"User-Agent","value":"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/145.0.0.0 Safari/537.36 (compatible; meta-externalagent/1.1 (+https://developers.facebook.com/docs/sharing/webmasters/crawler))"},{"key":"X-Envoy-External-Address","value":"10.10.0.1"},{"key":"X-Forwarded-For","value":"2a03:2880:f80e:2::,10.10.0.1"},{"key":"X-Forwarded-Host","value":"forgejo.siriusdevops.com"},{"key":"X-Request-Id","value":"a9dc8013-4616-49e7-b8a2-62e0d1d32143"}]}},"event_type":{"type":129},"traffic_direction":"EGRESS","is_reply":false,"Summary":"HTTP/1.1 GET http://forgejo.siriusdevops.com/mayx/blog/blame/commit/38caae08aa02b9f96ba7ac271d5fcd56f52b3c25/_posts/2021-02-28-discuz.md"},"node_name":"siriussec","time":"2026-11-27T05:04:00.873825673Z"}
|
||||
{"flow":{"time":"2026-11-27T05:04:00.745040808Z","uuid":"2467ad53-c069-41ed-83f4-bdf067e7c1c9","emitter":{"name":"Hubble","version":"1.20.1+g7d68cfb3"},"verdict":"DROPPED","drop_reason":139,"ethernet":{"source":"62:52:35:53:a0:e9","destination":"33:33:00:00:00:16"},"IP":{"source":"fe80::6052:35ff:fe53:a0e9","destination":"ff02::16","ipVersion":"IPv6"},"l4":{"ICMPv6":{"type":143}},"source":{"identity":18533,"cluster_name":"default","labels":["k8s:app.kubernetes.io/name=hubble-flow-collector","k8s:app.kubernetes.io/part-of=netsec","k8s:io.cilium.k8s.namespace.labels.app.kubernetes.io/part-of=netsec","k8s:io.cilium.k8s.namespace.labels.kubernetes.io/metadata.name=netsec","k8s:io.cilium.k8s.namespace.labels.kustomize.toolkit.fluxcd.io/name=apps","k8s:io.cilium.k8s.namespace.labels.kustomize.toolkit.fluxcd.io/namespace=flux-system","k8s:io.cilium.k8s.policy.cluster=default","k8s:io.cilium.k8s.policy.serviceaccount=default","k8s:io.kubernetes.pod.namespace=netsec"]},"destination":{"labels":["reserved:unknown"]},"Type":"L3_L4","node_name":"siriussec","node_labels":["beta.kubernetes.io/arch=amd64","beta.kubernetes.io/os=linux","gateway=true","kubernetes.io/arch=amd64","kubernetes.io/hostname=siriussec","kubernetes.io/os=linux","node-role.kubernetes.io/control-plane=","node-role.kubernetes.io/gateway=true","node-role.kubernetes.io/worker=","node.kubernetes.io/exclude-from-external-load-balancers="],"event_type":{"type":1,"sub_type":139},"traffic_direction":"INGRESS","file":{"name":"bpf_lxc.c","line":1843},"drop_reason_desc":"UNSUPPORTED_L3_PROTOCOL","Summary":"ICMPv6 143(0)"},"node_name":"siriussec","time":"2026-11-27T05:04:00.745040808Z"}
|
||||
{"flow":{"time":"2026-11-27T05:04:00.745057200Z","uuid":"3e44a8b8-83e7-456f-8be3-3c24f6c9630a","emitter":{"name":"Hubble","version":"1.20.1+g7d68cfb3"},"verdict":"DROPPED","drop_reason":139,"ethernet":{"source":"62:52:35:53:a0:e9","destination":"33:33:00:00:00:02"},"IP":{"source":"fe80::6052:35ff:fe53:a0e9","destination":"ff02::2","ipVersion":"IPv6"},"l4":{"ICMPv6":{"type":133}},"source":{"identity":18533,"cluster_name":"default","labels":["k8s:app.kubernetes.io/name=hubble-flow-collector","k8s:app.kubernetes.io/part-of=netsec","k8s:io.cilium.k8s.namespace.labels.app.kubernetes.io/part-of=netsec","k8s:io.cilium.k8s.namespace.labels.kubernetes.io/metadata.name=netsec","k8s:io.cilium.k8s.namespace.labels.kustomize.toolkit.fluxcd.io/name=apps","k8s:io.cilium.k8s.namespace.labels.kustomize.toolkit.fluxcd.io/namespace=flux-system","k8s:io.cilium.k8s.policy.cluster=default","k8s:io.cilium.k8s.policy.serviceaccount=default","k8s:io.kubernetes.pod.namespace=netsec"]},"destination":{"labels":["reserved:unknown"]},"Type":"L3_L4","node_name":"siriussec","node_labels":["beta.kubernetes.io/arch=amd64","beta.kubernetes.io/os=linux","gateway=true","kubernetes.io/arch=amd64","kubernetes.io/hostname=siriussec","kubernetes.io/os=linux","node-role.kubernetes.io/control-plane=","node-role.kubernetes.io/gateway=true","node-role.kubernetes.io/worker=","node.kubernetes.io/exclude-from-external-load-balancers="],"event_type":{"type":1,"sub_type":139},"traffic_direction":"INGRESS","file":{"name":"bpf_lxc.c","line":1843},"drop_reason_desc":"UNSUPPORTED_L3_PROTOCOL","Summary":"ICMPv6 RouterSolicitation"},"node_name":"siriussec","time":"2026-11-27T05:04:00.745057200Z"}
|
||||
{"flow":{"time":"2026-11-27T05:04:00.908567453Z","uuid":"ba375649-89be-43bd-baa8-e7b69c310ff9","emitter":{"name":"Hubble","version":"1.20.1+g7d68cfb3"},"verdict":"DROPPED","drop_reason":139,"ethernet":{"source":"62:52:35:53:a0:e9","destination":"33:33:00:00:00:16"},"IP":{"source":"fe80::6052:35ff:fe53:a0e9","destination":"ff02::16","ipVersion":"IPv6"},"l4":{"ICMPv6":{"type":143}},"source":{"identity":18533,"cluster_name":"default","labels":["k8s:app.kubernetes.io/name=hubble-flow-collector","k8s:app.kubernetes.io/part-of=netsec","k8s:io.cilium.k8s.namespace.labels.app.kubernetes.io/part-of=netsec","k8s:io.cilium.k8s.namespace.labels.kubernetes.io/metadata.name=netsec","k8s:io.cilium.k8s.namespace.labels.kustomize.toolkit.fluxcd.io/name=apps","k8s:io.cilium.k8s.namespace.labels.kustomize.toolkit.fluxcd.io/namespace=flux-system","k8s:io.cilium.k8s.policy.cluster=default","k8s:io.cilium.k8s.policy.serviceaccount=default","k8s:io.kubernetes.pod.namespace=netsec"]},"destination":{"labels":["reserved:unknown"]},"Type":"L3_L4","node_name":"siriussec","node_labels":["beta.kubernetes.io/arch=amd64","beta.kubernetes.io/os=linux","gateway=true","kubernetes.io/arch=amd64","kubernetes.io/hostname=siriussec","kubernetes.io/os=linux","node-role.kubernetes.io/control-plane=","node-role.kubernetes.io/gateway=true","node-role.kubernetes.io/worker=","node.kubernetes.io/exclude-from-external-load-balancers="],"event_type":{"type":1,"sub_type":139},"traffic_direction":"INGRESS","file":{"name":"bpf_lxc.c","line":1843},"drop_reason_desc":"UNSUPPORTED_L3_PROTOCOL","Summary":"ICMPv6 143(0)"},"node_name":"siriussec","time":"2026-11-27T05:04:00.908567453Z"}
|
||||
51
tests/helpers.py
Normal file
51
tests/helpers.py
Normal file
|
|
@ -0,0 +1,51 @@
|
|||
"""Shared helpers for the tests: a fake Prometheus and fixture loading."""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import json
|
||||
from pathlib import Path
|
||||
from typing import Dict, List, Tuple
|
||||
|
||||
FIXTURES = Path(__file__).parent / "fixtures"
|
||||
|
||||
|
||||
def fixture_lines(name: str) -> List[str]:
|
||||
return [ln for ln in (FIXTURES / name).read_text().splitlines() if ln.strip()]
|
||||
|
||||
|
||||
def fixture_flows(name: str):
|
||||
from netsec_scan.flows import parse_flow
|
||||
|
||||
return [parse_flow(json.loads(ln)) for ln in fixture_lines(name)]
|
||||
|
||||
|
||||
class FakeProm:
|
||||
"""Substring-matched query/scalar responses; no network, no kubectl.
|
||||
|
||||
Keys are matched by `key in expr`, so the tests assert *which* rule query
|
||||
ran without pinning the exact PromQL text.
|
||||
"""
|
||||
|
||||
def __init__(self, scalars: Dict[str, float] = None,
|
||||
vectors: Dict[str, List[Tuple[dict, float]]] = None):
|
||||
self.scalars = scalars or {}
|
||||
self.vectors = vectors or {}
|
||||
self.queries: List[str] = []
|
||||
|
||||
def _lookup(self, table, expr: str):
|
||||
# Longest matching key wins, so `...[5m]))[6h:5m]` beats `...[5m]`
|
||||
# when both are substrings of a 6h subquery expression.
|
||||
hits = [(key, value) for key, value in table.items() if key in expr]
|
||||
if not hits:
|
||||
return None
|
||||
return max(hits, key=lambda kv: len(kv[0]))[1]
|
||||
|
||||
def query(self, expr: str):
|
||||
self.queries.append(expr)
|
||||
value = self._lookup(self.vectors, expr)
|
||||
return value if value is not None else []
|
||||
|
||||
def scalar(self, expr: str) -> float:
|
||||
self.queries.append(expr)
|
||||
value = self._lookup(self.scalars, expr)
|
||||
return float(value) if value is not None else 0.0
|
||||
114
tests/test_flows.py
Normal file
114
tests/test_flows.py
Normal file
|
|
@ -0,0 +1,114 @@
|
|||
"""Parser tests: workload attribution, egress classification, chunk handling."""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import json
|
||||
import unittest
|
||||
|
||||
from helpers import fixture_flows, fixture_lines
|
||||
|
||||
from netsec_scan.flows import (
|
||||
RemoteFlowStore,
|
||||
is_external,
|
||||
iter_lines,
|
||||
parse_flow,
|
||||
workload_name,
|
||||
)
|
||||
|
||||
|
||||
class TestIterLines(unittest.TestCase):
|
||||
def test_partial_tail_is_carried_not_consumed(self):
|
||||
lines, partial = iter_lines(b'{"a":1}\n{"b":2}\n{"c":')
|
||||
self.assertEqual(lines, ['{"a":1}', '{"b":2}'])
|
||||
self.assertEqual(partial, b'{"c":')
|
||||
|
||||
def test_no_newline_yet(self):
|
||||
lines, partial = iter_lines(b'{"a":1}')
|
||||
self.assertEqual(lines, [])
|
||||
self.assertEqual(partial, b'{"a":1}')
|
||||
|
||||
def test_empty(self):
|
||||
self.assertEqual(iter_lines(b""), ([], b""))
|
||||
|
||||
|
||||
class TestEgressClassification(unittest.TestCase):
|
||||
def test_external_only_global_unicast(self):
|
||||
for ip in ("203.0.113.9", "172.67.209.185", "2606:4700::1111"):
|
||||
self.assertTrue(is_external(ip), ip)
|
||||
for ip in ("10.244.0.5", "10.10.0.2", "192.168.1.179", "127.0.0.1",
|
||||
"fe80::1", "ff02::2", "100.100.100.100", "10.96.0.1"):
|
||||
self.assertFalse(is_external(ip), ip)
|
||||
|
||||
def test_no_ip_is_not_external(self):
|
||||
self.assertFalse(is_external(None))
|
||||
self.assertFalse(is_external(""))
|
||||
|
||||
|
||||
class TestWorkloadAttribution(unittest.TestCase):
|
||||
def test_reserved_identity_has_no_workload(self):
|
||||
self.assertIsNone(workload_name({"identity": 1, "labels": ["reserved:host"]}))
|
||||
self.assertIsNone(workload_name(None))
|
||||
|
||||
def test_pod_name_change_does_not_change_identity(self):
|
||||
a = {"namespace": "osint",
|
||||
"pod_name": "osint-app-7d9f8c6b5-abcde",
|
||||
"labels": ["k8s:app=osint-app"]}
|
||||
b = {"namespace": "osint",
|
||||
"pod_name": "osint-app-5bb4d7f9c-xyzwq",
|
||||
"labels": ["k8s:app=osint-app"]}
|
||||
self.assertEqual(workload_name(a), "osint/osint-app")
|
||||
self.assertEqual(workload_name(a), workload_name(b))
|
||||
|
||||
def test_deployment_workload_wins_over_label(self):
|
||||
peer = {"namespace": "flux-system", "pod_name": "source-controller-abc12-def34",
|
||||
"labels": ["k8s:app=source-controller"],
|
||||
"workloads": [{"name": "source-controller", "kind": "Deployment"}]}
|
||||
self.assertEqual(workload_name(peer), "flux-system/source-controller")
|
||||
|
||||
def test_pod_name_fallback_strips_hashes(self):
|
||||
peer = {"namespace": "x", "pod_name": "web-7d9f8c6b5-abcde"}
|
||||
self.assertEqual(workload_name(peer), "x/web")
|
||||
|
||||
|
||||
class TestRealFixtures(unittest.TestCase):
|
||||
def test_egress_fixture_parses_and_keeps_only_workload_egress(self):
|
||||
flows = fixture_flows("egress-sample.jsonl")
|
||||
self.assertGreaterEqual(len(flows), 5)
|
||||
external = [f for f in flows if f.src_workload and is_external(f.dst_ip)]
|
||||
# 4 workload->public 443 lines + 1 :80 line; the reserved:host and LAN
|
||||
# lines must not qualify.
|
||||
self.assertGreaterEqual(len(external), 4)
|
||||
self.assertTrue(all(f.dst_port for f in external))
|
||||
self.assertTrue(all(f.src_workload for f in external))
|
||||
|
||||
def test_reserved_host_egress_is_not_attributed_to_a_workload(self):
|
||||
flows = fixture_flows("egress-sample.jsonl")
|
||||
host_flows = [f for f in flows if not f.src_workload and is_external(f.dst_ip)]
|
||||
self.assertTrue(host_flows, "fixture should contain a reserved:host to-world flow")
|
||||
|
||||
def test_l7_and_drop_fixture_parses(self):
|
||||
flows = fixture_flows("l7-and-drop.jsonl")
|
||||
self.assertTrue(any(f.type == "L7" for f in flows))
|
||||
self.assertTrue(any(f.verdict == "DROPPED" for f in flows))
|
||||
|
||||
def test_garbage_line_is_skipped(self):
|
||||
self.assertIsNone(parse_flow({"flow": None}))
|
||||
self.assertIsNone(parse_flow({}))
|
||||
self.assertIsNone(parse_flow({"flow": {"Type": "L3_L4"}}))
|
||||
|
||||
|
||||
class TestRemoteStoreCommand(unittest.TestCase):
|
||||
def test_list_command_does_not_quote_the_glob(self):
|
||||
"""A quoted glob is literal, and stat then fails with 'No such file'."""
|
||||
cmd = "sudo -n find %s -maxdepth 1 -type f -name %s -printf '%%f %%s\\n'" % (
|
||||
"'/var/log/netsec'", "'flows-*.jsonl'")
|
||||
self.assertIn("flows-*.jsonl", cmd)
|
||||
self.assertNotIn("'/var/log/netsec/flows-*.jsonl'", cmd)
|
||||
|
||||
def test_remote_store_defaults(self):
|
||||
store = RemoteFlowStore()
|
||||
self.assertIn("@", store.host)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
181
tests/test_rules.py
Normal file
181
tests/test_rules.py
Normal file
|
|
@ -0,0 +1,181 @@
|
|||
"""Rule tests: novelty, dedupe semantics, ratios, thresholds and line shape."""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import unittest
|
||||
from datetime import datetime, timedelta, timezone
|
||||
|
||||
from helpers import FakeProm, fixture_flows
|
||||
|
||||
from netsec_scan import config, rules
|
||||
from netsec_scan.rules import Finding
|
||||
|
||||
|
||||
def utc(*args):
|
||||
return datetime(*args, tzinfo=timezone.utc)
|
||||
|
||||
|
||||
class TestFirstSeenEgress(unittest.TestCase):
|
||||
def test_same_tuple_fires_once(self):
|
||||
flows = fixture_flows("egress-sample.jsonl")
|
||||
seen = {}
|
||||
now = utc(2026, 11, 27, 5, 20)
|
||||
first = rules.rule_egress_first_seen(flows, seen, now)
|
||||
self.assertTrue(first)
|
||||
self.assertTrue(all(f.rule == "egress-new-dst" for f in first))
|
||||
# second evaluation over the same flows must be silent
|
||||
second = rules.rule_egress_first_seen(flows, seen, now)
|
||||
self.assertEqual(second, [])
|
||||
|
||||
def test_union_semantics_keeps_history(self):
|
||||
flows = fixture_flows("egress-sample.jsonl")
|
||||
seen = {}
|
||||
rules.rule_egress_first_seen(flows, seen, utc(2026, 11, 27, 5, 20))
|
||||
before = dict(seen)
|
||||
# a later, unrelated evaluation must not shrink the seen-set
|
||||
rules.rule_egress_first_seen([], seen, utc(2026, 11, 27, 5, 25))
|
||||
self.assertEqual(seen, before)
|
||||
|
||||
def test_fingerprint_is_stable_across_runs(self):
|
||||
flows = fixture_flows("egress-sample.jsonl")
|
||||
a = rules.rule_egress_first_seen(flows, {}, utc(2026, 11, 27, 5, 20))
|
||||
b = rules.rule_egress_first_seen(flows, {}, utc(2027, 1, 2, 9, 0))
|
||||
self.assertEqual([f.fingerprint for f in a], [f.fingerprint for f in b])
|
||||
|
||||
def test_severity_by_port(self):
|
||||
flows = fixture_flows("egress-sample.jsonl")
|
||||
findings = rules.rule_egress_first_seen(flows, {}, utc(2026, 11, 27, 5, 20))
|
||||
for f in findings:
|
||||
port = int(f.entity.rsplit(":", 1)[1].split("/")[0])
|
||||
want = "MEDIUM" if port in config.WEB_PORTS else "HIGH"
|
||||
self.assertEqual(f.severity, want, f.entity)
|
||||
|
||||
def test_nonexternal_and_reserved_are_ignored(self):
|
||||
flows = fixture_flows("egress-sample.jsonl")
|
||||
findings = rules.rule_egress_first_seen(flows, {}, utc(2026, 11, 27, 5, 20))
|
||||
for f in findings:
|
||||
self.assertNotIn("reserved:", f.entity)
|
||||
self.assertNotIn("192.168.", f.entity)
|
||||
|
||||
|
||||
class TestBeacon(unittest.TestCase):
|
||||
def setUp(self):
|
||||
self.now = utc(2026, 11, 27, 5, 0).timestamp()
|
||||
|
||||
def test_regular_beacon_fires(self):
|
||||
flows = fixture_flows("beacon-shaped.jsonl")
|
||||
findings = rules.rule_beacon(flows, {}, self.now)
|
||||
self.assertEqual(len(findings), 1)
|
||||
self.assertEqual(findings[0].rule, "beacon-shape")
|
||||
self.assertEqual(findings[0].severity, "HIGH")
|
||||
self.assertIn("jitter 0.0", findings[0].detail)
|
||||
|
||||
def test_irregular_traffic_does_not_fire(self):
|
||||
flows = fixture_flows("beacon-shaped.jsonl")
|
||||
# stretch the gaps so the inter-arrival spread is not periodic
|
||||
for i, flow in enumerate(flows):
|
||||
flow.time = flows[0].time + timedelta(seconds=(i * i * 7) + i * 3)
|
||||
findings = rules.rule_beacon(flows, {}, self.now)
|
||||
self.assertEqual(findings, [])
|
||||
|
||||
def test_too_few_connections_do_not_fire(self):
|
||||
flows = fixture_flows("beacon-shaped.jsonl")[: config.BEACON_MIN_CONNS - 1]
|
||||
self.assertEqual(rules.rule_beacon(flows, {}, self.now), [])
|
||||
|
||||
def test_same_socket_is_one_connection(self):
|
||||
"""Many packets on one long-lived connection must not count as many conns."""
|
||||
flows = fixture_flows("beacon-shaped.jsonl")
|
||||
for flow in flows:
|
||||
flow.src_port = 40000
|
||||
self.assertEqual(rules.rule_beacon(flows, {}, self.now), [])
|
||||
|
||||
|
||||
class TestPromRules(unittest.TestCase):
|
||||
def test_lost_events_per_node(self):
|
||||
prom = FakeProm(vectors={ # noqa: E501
|
||||
"hubble_lost_events_total":
|
||||
[({"node": "siriussec"}, 0.60), ({"node": "rpi"}, 0.0)]})
|
||||
findings = rules.rule_lost_events(prom)
|
||||
self.assertEqual(len(findings), 1)
|
||||
self.assertEqual(findings[0].entity, "node=siriussec")
|
||||
self.assertEqual(findings[0].severity, "HIGH")
|
||||
|
||||
def test_drop_spike_needs_floor_and_ratio(self):
|
||||
quiet = FakeProm(scalars={"hubble_drop_total": 0.02})
|
||||
self.assertEqual(rules.rule_drop_spike(quiet), [])
|
||||
# same absolute rate, 10x baseline: floor still blocks it
|
||||
below_floor = FakeProm(scalars={"hubble_drop_total{protocol!=\"ICMPv6\"}[5m]": 0.02,
|
||||
"hubble_drop_total{protocol!=\"ICMPv6\"}[1h] offset 5m": 0.0})
|
||||
self.assertEqual(rules.rule_drop_spike(below_floor), [])
|
||||
fired = FakeProm(scalars={
|
||||
"hubble_drop_total{protocol!=\"ICMPv6\"}[1h] offset 5m": 0.01,
|
||||
"hubble_drop_total{protocol!=\"ICMPv6\"}[5m]": 0.30,
|
||||
"hubble_drop_total{protocol!=\"ICMPv6\"}": 0.30,
|
||||
})
|
||||
out = rules.rule_drop_spike(fired)
|
||||
self.assertTrue(out)
|
||||
self.assertIn("vs 1h baseline 0.01/s", out[0].detail)
|
||||
# and when the baseline is genuinely zero the detail must say so
|
||||
no_base = FakeProm(scalars={
|
||||
"hubble_drop_total{protocol!=\"ICMPv6\"}[1h] offset 5m": 0.0,
|
||||
"hubble_drop_total{protocol!=\"ICMPv6\"}[5m]": 0.30,
|
||||
})
|
||||
self.assertIn("no 1h baseline", rules.rule_drop_spike(no_base)[0].detail)
|
||||
|
||||
def test_syn_sweep_ratio_and_floor(self):
|
||||
normal = FakeProm(scalars={'hubble_tcp_flags_total{flag="SYN"}[5m]': 10.6,
|
||||
'hubble_tcp_flags_total{flag="SYN-ACK"}[5m]': 6.7})
|
||||
self.assertEqual(rules.rule_syn_sweep(normal), [])
|
||||
sweep = FakeProm(scalars={'hubble_tcp_flags_total{flag="SYN"}[5m]': 40.0,
|
||||
'hubble_tcp_flags_total{flag="SYN-ACK"}[5m]': 2.0})
|
||||
self.assertTrue(rules.rule_syn_sweep(sweep))
|
||||
|
||||
def test_rst_storm_ratio(self):
|
||||
calm = FakeProm(scalars={'hubble_tcp_flags_total{flag="RST"}[5m]': 2.5,
|
||||
'hubble_tcp_flags_total{flag="RST"}[5m]))[6h:5m]': 2.4})
|
||||
self.assertEqual(rules.rule_rst_storm(calm), [])
|
||||
storm = FakeProm(scalars={'hubble_tcp_flags_total{flag="RST"}[5m]': 60.0,
|
||||
'hubble_tcp_flags_total{flag="RST"}[5m]))[6h:5m]': 2.4})
|
||||
self.assertTrue(rules.rule_rst_storm(storm))
|
||||
|
||||
def test_new_port_ignores_ephemeral_ports(self):
|
||||
prom = FakeProm(vectors={"hubble_port_distribution_total": [
|
||||
({"port": "3100"}, 3.0), ({"port": "54321"}, 1.0), ({"port": "0"}, 3.0)]})
|
||||
findings = rules.rule_new_port(prom)
|
||||
self.assertEqual([f.entity for f in findings], ["port=3100"])
|
||||
self.assertEqual(findings[0].severity, "LOW")
|
||||
|
||||
def test_http_error_ratio_needs_traffic_floor(self):
|
||||
quiet = FakeProm(scalars={"sum(rate(hubble_http_requests_total[15m]))": 0.2,
|
||||
'status=~"4..|5.."': 0.2})
|
||||
self.assertEqual(rules.rule_http_errors(quiet), [])
|
||||
busy = FakeProm(scalars={"sum(rate(hubble_http_requests_total[15m]))": 4.0,
|
||||
'status=~"4..|5.."': 3.0})
|
||||
self.assertTrue(rules.rule_http_errors(busy))
|
||||
|
||||
|
||||
class TestOutputShape(unittest.TestCase):
|
||||
def test_render_is_bounded_and_starts_with_severity_and_fingerprint(self):
|
||||
from netsec_scan.__main__ import render
|
||||
|
||||
finding = Finding(rule="egress-new-dst", kind="novelty", severity="HIGH",
|
||||
entity="osint/osint-app->203.0.113.9:4444/tcp",
|
||||
detail="x" * 400)
|
||||
line = render(finding)
|
||||
self.assertLessEqual(len(line), config.MAX_LINE)
|
||||
self.assertTrue(line.startswith("HIGH "))
|
||||
self.assertEqual(line.split(" ")[1], finding.fingerprint)
|
||||
|
||||
def test_fingerprint_ignores_counts_and_time(self):
|
||||
a = Finding(rule="drop-spike", kind="state", severity="MEDIUM",
|
||||
entity="cluster", detail="3 drops")
|
||||
b = Finding(rule="drop-spike", kind="state", severity="MEDIUM",
|
||||
entity="cluster", detail="300 drops at 09:00Z")
|
||||
self.assertEqual(a.fingerprint, b.fingerprint)
|
||||
c = Finding(rule="drop-spike", kind="state", severity="MEDIUM",
|
||||
entity="cluster=other", detail="3 drops")
|
||||
self.assertNotEqual(a.fingerprint, c.fingerprint)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
92
tests/test_state.py
Normal file
92
tests/test_state.py
Normal file
|
|
@ -0,0 +1,92 @@
|
|||
"""State-file semantics: union, atomic write, rollover, bounds, corruption."""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import json
|
||||
import os
|
||||
import tempfile
|
||||
import time
|
||||
import unittest
|
||||
from pathlib import Path
|
||||
|
||||
from netsec_scan import config, state as state_mod
|
||||
from netsec_scan.prom import SensorError
|
||||
|
||||
|
||||
class TestStateFile(unittest.TestCase):
|
||||
def setUp(self):
|
||||
self.tmp = tempfile.TemporaryDirectory()
|
||||
self.path = Path(self.tmp.name) / "state.json"
|
||||
|
||||
def tearDown(self):
|
||||
self.tmp.cleanup()
|
||||
|
||||
def test_missing_file_is_a_fresh_state(self):
|
||||
st = state_mod.load(self.path)
|
||||
self.assertFalse(st["seeded"])
|
||||
self.assertEqual(st["seen"], {})
|
||||
self.assertEqual(st["files"], {})
|
||||
|
||||
def test_roundtrip_and_mode(self):
|
||||
st = state_mod.load(self.path)
|
||||
st["seen"]["abc"] = {"rule": "x", "kind": "state", "entity": "e",
|
||||
"severity": "LOW", "first": "2026-11-27T00:00:00+00:00",
|
||||
"last_alert": "2026-11-27T00:00:00+00:00"}
|
||||
state_mod.save(self.path, st)
|
||||
again = state_mod.load(self.path)
|
||||
self.assertIn("abc", again["seen"])
|
||||
self.assertEqual(os.stat(self.path).st_mode & 0o777, 0o600)
|
||||
|
||||
def test_corrupt_file_raises_instead_of_resetting(self):
|
||||
self.path.write_text("{not json")
|
||||
with self.assertRaises(SensorError) as ctx:
|
||||
state_mod.load(self.path)
|
||||
self.assertEqual(ctx.exception.cls, "state-corrupt")
|
||||
|
||||
def test_missing_key_is_added_not_replaced(self):
|
||||
st = state_mod.load(self.path)
|
||||
st["egress"]["a->1.2.3.4:443/tcp"] = "2026-11-27T00:00:00+00:00"
|
||||
state_mod.save(self.path, st)
|
||||
again = state_mod.load(self.path)
|
||||
again["egress"]["b->5.6.7.8:80/tcp"] = "2026-11-27T00:01:00+00:00"
|
||||
state_mod.save(self.path, again)
|
||||
final = json.loads(self.path.read_text())
|
||||
self.assertEqual(len(final["egress"]), 2)
|
||||
|
||||
def test_prune_bounds_the_seen_set(self):
|
||||
st = state_mod.load(self.path)
|
||||
for i in range(config.MAX_SEEN + 500):
|
||||
st["seen"][f"fp{i}"] = {"first": "2026-11-27T00:00:%02d+00:00" % (i % 60)}
|
||||
state_mod.prune(st)
|
||||
self.assertLessEqual(len(st["seen"]), config.MAX_SEEN)
|
||||
|
||||
def test_day_rolls_over(self):
|
||||
st = state_mod.load(self.path)
|
||||
st["day"] = {"date": "1999-01-01", "flows": 42, "rules": {"x": 1},
|
||||
"egress": [], "new_dsts": []}
|
||||
state_mod.roll_day(st)
|
||||
self.assertNotEqual(st["day"]["date"], "1999-01-01")
|
||||
self.assertEqual(st["day"]["flows"], 0)
|
||||
|
||||
def test_day_kept_within_same_day(self):
|
||||
st = state_mod.load(self.path)
|
||||
today = st["day"]["date"]
|
||||
st["day"]["flows"] = 7
|
||||
state_mod.roll_day(st)
|
||||
self.assertEqual(st["day"]["date"], today)
|
||||
self.assertEqual(st["day"]["flows"], 7)
|
||||
|
||||
|
||||
class TestDegradeMemo(unittest.TestCase):
|
||||
def test_memo_window(self):
|
||||
memo = {}
|
||||
state_mod.note_degraded({"degraded": memo}, "timeout")
|
||||
now = time.time()
|
||||
self.assertTrue(state_mod.degraded_memo({"degraded": memo}, "timeout", now))
|
||||
self.assertFalse(state_mod.degraded_memo({"degraded": memo}, "other", now))
|
||||
later = now + config.DEGRADED_MEMO + 1
|
||||
self.assertFalse(state_mod.degraded_memo({"degraded": memo}, "timeout", later))
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
Loading…
Reference in a new issue