Architecture¶
System overview¶
flowchart TB
subgraph Server["Vespid Server"]
API["Flask API<br/>ingestion"]
SSE["SSE Manager<br/>(dashboard)"]
FleetSSE["Fleet SSE<br/>(blocks)"]
ConfigSSE["Config SSE<br/>(profiles)"]
IntelDB[("Intel DB<br/>IP reputation")]
DB[("SQLite / MySQL<br/>54 tables")]
AlertEval["Alert Eval<br/>Loop"]
PropEngine["Propagation<br/>Engine"]
API --> DB
API --> IntelDB
SSE --> DB
FleetSSE --> DB
ConfigSSE --> DB
PropEngine --> FleetSSE
AlertEval --> DB
end
Agent1["Vespid Agent<br/>(web server)"]
Agent2["Vespid Agent<br/>(database)"]
Agent3["Vespid Agent<br/>(mail server)"]
Agent1 <-->|HTTPS | Server
Agent2 <-->|HTTPS | Server
Agent3 <-->|HTTPS | Server
Agent internals¶
flowchart LR
subgraph Logs["Log files"]
Secure["/var/log/secure"]
Messages["/var/log/messages"]
Apache["Apache/Nginx/HA"]
Auditd["auditd"]
end
LogProcessor["LogProcessor<br/>(asyncio tailer)"]
AuditdParser["AuditdParser<br/>(process creation)"]
SlidingWindow["SlidingWindowDetector<br/>+ CorrelationDetector"]
HostDetector["HostDetector<br/>(Sigma rules)"]
NftMgr["NFTablesManager<br/>shield_local"]
DataBus["DataBus<br/>(Producer/Consumer)"]
SubMgr["SubscriptionMgr<br/>shield_subscribed"]
Server["spool.jsonl<br/>or POST to server"]
Logs --> LogProcessor
Auditd --> AuditdParser
LogProcessor --> SlidingWindow
AuditdParser --> HostDetector
SlidingWindow --> NftMgr
SlidingWindow --> DataBus
HostDetector --> DataBus
NftMgr --> DataBus
SubMgr --> NftMgr
DataBus --> Server
Agent threading model¶
The agent uses dedicated threads with separate event loops to avoid Python 3.12 asyncio starvation issues.
flowchart TB
subgraph Main["Main Process"]
MainLoop["Main asyncio loop<br/>(log tailing, detection)"]
CtrlSock["Control socket thread<br/>(CLI commands)"]
FleetSub["Fleet subscriber thread<br/>(SSE client)"]
ConfigSub["Config subscriber thread<br/>(SSE client)"]
RuleSub["Rule subscriber thread<br/>(HTTP polling)"]
DataBusW["DataBus worker thread<br/>(batching, shipping)"]
end
See Threading Architecture for details.
Background tasks¶
| Component | Role |
|---|---|
| EnrollmentClient | Auto-enrollment + credential rotation |
| FleetBlockSubscriber | Fleet SSE channel listener |
| RuleSubscriber | Polls /api/v1/rules/distribution |
| ConfigSubscriber | Config SSE (server-managed mode) |
| ControlServer | UNIX socket for CLI |
| Health check | Rebuilds nftables table if missing (every 30s) |
| GC loop | Prunes stale detector/correlation/recidive data (every 10 min) |
| Expiry reaper | Removes expired in-memory blocks (every 60s) |
| Fleet queue drainer | Retries offline block reports with exponential backoff |
| Activity tracker | Logs 24h activity summaries |
Server internals¶
flowchart TB
subgraph Server["Flask + Gevent"]
Ingestion["Event Ingestion<br/>POST /api/v1/events"]
Heartbeat["Heartbeat<br/>POST /api/v1/heartbeat"]
IntelIngest["Intel Ingestion<br/>POST /api/v1/intel/*"]
HostIngest["Host Event Ingest<br/>POST /api/v1/host-events"]
MetricsIngest["Metrics Ingest<br/>POST /api/v1/metrics/write"]
PropEngine["Propagation Engine<br/>(corroboration, rate limits)"]
AlertLoop["Alert Eval Loop<br/>(APScheduler, DB lock)"]
IntelScore["Intel Scoring<br/>(6-signal reputation)"]
NoiseFilter["Noise Suppression<br/>(26 rules)"]
DashSSE["Dashboard SSE"]
FleetSSE["Fleet SSE"]
ConfigSSE["Config SSE"]
DB[("Database<br/>54 tables")]
VM["VictoriaMetrics<br/>(optional)"]
end
Ingestion --> DB
Ingestion --> PropEngine
Ingestion --> IntelIngest
Heartbeat --> DB
HostIngest --> NoiseFilter
NoiseFilter --> DB
MetricsIngest --> VM
PropEngine --> FleetSSE
AlertLoop --> DB
IntelIngest --> IntelScore
SSE channels¶
The server runs three independent SSE managers, each with its own fan-out and reconnection buffer:
| Channel | Path | Auth | Purpose | Buffer |
|---|---|---|---|---|
| Dashboard | /api/v1/events/stream |
Session | Live event feed for web UI | 500 |
| Fleet | /api/v1/fleet/blocks/stream |
Bearer | Block propagation to agents | 1000 |
| Config | /api/v1/config/stream |
Bearer | Profile push to managed agents | 1000 |
For multi-worker Gunicorn deployments, a Redis-backed SSE implementation ensures fan-out across all workers.
Data flow: detection¶
- Log line arrives → LogProcessor parses it into a
ParsedLine ParsedLinefed toSlidingWindowDetectorandCorrelationDetector- On threshold breach →
Detectionevent published to DataBus - DataBus publishes to NFTablesManager (apply block) and server (telemetry)
- If fleet-enabled, block report sent to server for corroboration
- Server's Propagation Engine evaluates → approved blocks published via Fleet SSE
- Subscribed agents apply fleet blocks to local nftables
Data flow: host threat detection¶
- auditd emits SYSCALL/EXECVE/PROCTITLE records to
/var/log/audit/audit.log - AuditdParser assembles multi-line records into
HostEventobjects - HostDetector matches against 115 Sigma-derived rules
- Matches are scored per-host with exponential time decay
- Events shipped to server via DataBus
- Server stores events, computes scores, renders Kill Chain Timeline
Data flow: intelligence pipeline¶
- Block/sighting events arrive from agents
- Intel service creates or updates
ip_intelrecord - Scoring engine computes reputation (6 weighted signals + multi-vector bonus)
- Search and analytics available via dashboard and CLI
Data flow: server-managed config¶
- Admin updates config profile in dashboard
- Server creates a rollout (immediate, canary, or staged)
- Managed agents connected to Config SSE receive the update
- Agent applies config atomically with rollback on failure
- Agent reports health status on next check-in
Data flow: rule distribution¶
- Admin enables/disables rules on server
- Revision counter increments
- Agents poll
GET /api/v1/rules/distributionwithIf-None-Match - Server returns 304 (no change) or full rule set with per-node filtering
- Agent merges with local config and hot-reloads detector
Data flow: alerting¶
- Timer triggers eval loop every 60 seconds (multi-worker safe via DB lock)
- Eval loop acquires DB-based singleton lock (multi-worker safe)
- Each enabled rule evaluated against PromQL or check_result data
- State transitions (OK → firing, firing → OK) trigger notifications
- Notifications dispatched via configured channels (Slack, email, webhook, PagerDuty)
- Cooldown and debounce prevent flapping
Key design decisions¶
| Decision | Rationale |
|---|---|
| Flask + HTMX + SQLite | No JS build tooling; zero-config database |
| Gevent workers | Thousands of idle SSE connections on one OS thread |
| nftables (not iptables) | Modern Linux firewall; per-element TTL in kernel |
| Sliding-window detection | O(1) amortized per event; handles both fast and slow attacks |
| Correlation detection | Catches multi-vector recon below individual thresholds |
| Dedicated SSE channels | Isolated fan-out for dashboard, fleet, and config |
| Fleet-wide recidive | Server escalates fleet block TTL for repeat offenders using Intel DB counters |
| Migration-based schema | Incremental ALTER TABLE on startup; never breaks existing DBs |
| DB abstraction layer | Same queries work on SQLite and MySQL transparently |
| Per-node rule filtering | Nodes only receive rules for parsers they actually monitor |
| Dedicated threads | Avoids Python 3.12 asyncio starvation with call_soon_threadsafe |
| DB-based eval lock | Alert eval loop safe across multiple Gunicorn workers |
| On-disk fleet queue | Block reports survive agent restarts when server is unreachable |