A Go HTTP service that takes security events from your servers, matches them against regex rules and per-IP time-window rules, and can block the source IP with iptables or ufw.
A single VPS exposed to the internet gets SSH brute force, SQL injection probes and request floods every day. The logs show it, but nobody reads them in time, and a full SIEM stack is far too heavy for one or two machines. I wanted something small that answers "which IPs are attacking this box right now" from the events I already have, and that can act on it.
The Go module holds two programs that share a domain model but run independently:
mini-siem-api/ |
cmd/server-analyst |
|
|---|---|---|
| Input | events pushed over POST /events |
log lines replayed from a file via CLI |
| Detection | DB-stored regex rules + per-IP time-window correlation | regex rules from config/rules.yml, built-in patterns (SQLi, XSS, traversal, scanners, gambling spam) and thresholds (SSH failures, HTTP 401s, requests per IP) |
| Action | optional auto-block (iptables / ufw) | manual block via admin API (nftables, falls back to ufw) |
| Storage | SQLite (default) or Postgres, optional MinIO archive | Postgres, MinIO with an on-disk spool when MinIO is down |
mini-siem-api is the one I'd run today. server-analyst came first; parts of it are not wired up yet (see Limitations).
flowchart LR
C[client / log shipper] -->|POST /events| RL[rate limiter]
RL --> EN[threat intel<br/>AbuseIPDB, OTX]
EN --> DB[(events)]
DB --> RE[regex rules]
DB --> CO[per-IP correlation]
RE --> DET[(detections)]
CO --> DET
DET -->|high / critical| BL[auto-block<br/>iptables or ufw]
Each event goes through the same steps in infra/services/event_service.go: enrich, save, archive to MinIO (if configured), evaluate regex rules, evaluate correlation rules, save detections, then try to auto-block.
Correlation rules are fixed in code (infra/correlation/correlation.go) and keyed by source IP:
| Rule | Matches | Threshold | Severity |
|---|---|---|---|
| Brute force | message contains failed login, failed password, authentication failed, ... |
5 in 5 min | high |
| Port scan | connection attempt, port scan, syn scan, probe |
10 in 2 min | medium |
| HTTP flood | any event with source web, nginx or apache |
50 in 1 min | critical |
| SQL injection | union select, information_schema, or 1=1, ... |
3 in 10 min | high |
Regex rules have no defaults; you create them through the admin API and they are matched against the event message.
Two kinds of detection, stored in different places. Regex rules live in the database so I can add or disable one with an API call, without a deploy. Correlation needs counters per IP over a sliding window, so that state lives in memory. The trade-off is that correlation state is lost on restart and is not shared, so this only works as a single instance.
Blocking is opt-in and narrow. Auto-block is off by default, and when it is on, dry-run is on by default. It only fires for high or critical detections and never for loopback or private addresses, so a misconfigured rule can't lock out the internal network. The cost is that a detection from a private range is never acted on, even when it is real.
Threat intel is best-effort but inline. If AbuseIPDB or OTX keys are set, each event's IP is looked up (10s timeout, 15-minute in-memory cache) before the event is saved, and a reputation score of 75 or more raises the event's severity. A failed lookup never fails the ingest. The trade-off: the lookup runs inside the POST /events request, so an uncached IP can add up to 10 seconds of latency.
SQLite by default, Postgres by config. One binary with no external services is enough to try it; set MINI_SIEM_DB_DRIVER=postgres for real use. Tables are created with GORM AutoMigrate, which is convenient but leaves no migration history.
Go 1.24+. From the repo root:
MINI_SIEM_ADMIN_API_KEY=devkey \
MINI_SIEM_THREAT_INTEL_ENABLED=false \
go run ./mini-siem-api/cmd/mini-siem-apiIt listens on :8085 and creates mini_siem.db in the current directory. Swagger UI is at http://localhost:8085/swagger/index.html, Prometheus metrics at /metrics.
Create a rule, send five failed logins from one IP, and look at the detections:
curl -s -X POST localhost:8085/rules \
-H 'Content-Type: application/json' -H 'X-API-Key: devkey' \
-d '{"name":"ssh-failed","pattern":"Failed password","severity":"high"}'
for i in 1 2 3 4 5; do
curl -s -o /dev/null -X POST localhost:8085/events \
-H 'Content-Type: application/json' \
-d '{"source":"ssh","ip":"203.0.113.9","message":"Failed password for root from 203.0.113.9"}'
done
curl -s localhost:8085/detectionsYou get one regex detection per event plus a Brute Force Attack: 5 events from 203.0.113.9 in 5m0s correlation detection on the fifth.
Endpoints: GET /health, POST /events (single event or batch, rate-limited), GET /events, GET /events/{id}, GET /detections, GET /detections/{id}. Admin, with X-API-Key: GET|POST /rules, PATCH /rules/{id}, GET|POST /decisions.
Configuration is environment-only (mini-siem-api/config/config.go). The ones you're most likely to change:
| Variable | Default |
|---|---|
MINI_SIEM_ADDRESS |
:8085 |
MINI_SIEM_ADMIN_API_KEY |
empty (see Limitations) |
MINI_SIEM_DB_DRIVER / MINI_SIEM_DB_DSN |
sqlite / mini_siem.db |
MINI_SIEM_INGEST_RATE / MINI_SIEM_INGEST_BURST |
5 / 10 per client |
MINI_SIEM_ABUSEIPDB_API_KEY, MINI_SIEM_ALIENVAULT_API_KEY |
empty |
MINI_SIEM_AUTO_BLOCK_ENABLED / _DRY_RUN / _METHOD |
false / true / iptables |
MINI_SIEM_MINIO_ENDPOINT, _ACCESS_KEY, _SECRET_KEY, _BUCKET |
empty (archive off) |
A log-oriented version: it reads lines, runs them through config/rules.yml plus built-in detectors, saves detections and decisions to Postgres, sends Slack or Telegram notifications, and uploads exports to MinIO. If MinIO is unreachable, uploads go to a disk spool and a background loop retries them. The rules file is reloaded every 15 seconds when it changes.
It needs Postgres and a config file. To try it locally:
docker run -d --rm --name sa-pg -e POSTGRES_USER=analyst -e POSTGRES_PASSWORD=analyst \
-e POSTGRES_DB=analyst -p 55432:5432 postgres:16-alpine
cat > dev.yaml <<'EOF'
server: {http_addr: "127.0.0.1:8080", api_key: "devkey", dry_run: true}
storage:
db: {driver: postgres, dsn: "postgres://analyst:analyst@127.0.0.1:55432/analyst?sslmode=disable"}
minio: {endpoint: "127.0.0.1:9000", access_key: x, secret_key: y, bucket: sa, spool_dir: "./spool"}
rules: {file: "config/rules.yml", judol_keywords: "config/keywords_judol.yml"}
EOF
go run ./cmd/server-analyst -config dev.yaml # HTTP API on :8080
go run ./cmd/server-analyst -config dev.yaml replay -file some.log # feed lines through detection
curl -s localhost:8080/detectionsgo vet ./...
go test -race ./...Tests cover the server-analyst detector and the MinIO cold store's spool fallback. mini-siem-api has no tests yet; I've checked it with the curl flow above. CI runs vet, build and tests on every push.
- Admin routes are open if
MINI_SIEM_ADMIN_API_KEYis empty. The middleware skips the check instead of refusing. It should refuse to start without a key. - Dry-run is not fully dry for iptables. With auto-block enabled and method
iptables, startup still creates theMINI_SIEM_BLOCKchain and inserts it intoINPUT, even withMINI_SIEM_AUTO_BLOCK_DRY_RUN=true. Run as non-root while testing. - The ingest rate limit trusts
X-Forwarded-For, so a client can rotate that header to bypass it. It should only be trusted behind a known proxy. - Correlation windows are pruned by the event's own timestamp, which the client can set, so backdated events never count toward a threshold.
- Blocked IPs are kept only in memory;
POST /decisionswith actionblockonly records the decision, it does not call the firewall. - No allowlist of trusted IPs beyond the private-range check.
- server-analyst: the journald and file tailers in
internal/infrastructure/logsourceare not started bymain, so the only ingest path isreplay. Thestorage.db.driversetting is ignored (always Postgres). Fail2ban and nginx blocklist adapters exist but aren't wired. Decisions are saved but not applied automatically. - Both Dockerfiles are broken:
mini-siem-api/Dockerfilecopies ago.modthat is not in its build context, anddocker/docker-compose.ymlpoints at a path that doesn't exist. - Next: tests for the correlation engine and the blocker, persisted correlation state (Redis) so it can run as more than one instance, and wiring the server-analyst tailers so it doesn't need a separate shipper.
MIT