feat!: Urutau 2.0.0, ultralight probes and a single analysis hub
Each server runs an ultralight probe (scratch image, ~7 MiB RSS) that tails the logs, ships raw lines to the hub over HTTPS with an on-disk spool, and applies enforce decisions locally. The hub keeps one node per probe (primary node = the 1.x data dir, unchanged), does all analysis and serves the UI. Peer federation is removed. 'urutau import' brings 1.x data dirs in with hash and count verification. UI: probes page, host qualified incidents, IPs never wrap, egress heatmap labels, live and replay globes no longer auto-rotate, replay repeat, live traffic metrics. BREAKING CHANGE: URUTAU_PEERS, URUTAU_PEER_* and /api/v1/peer/* are gone; log path variables move from the hub to the probe. See docs/migration-2.0.md. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
23a7a5963a
commit
8546d14cef
130 files changed
+9396
-3311
No files matched your search
+61
-29
@@ -2,11 +2,11 @@
|
||||
|
||||
# Architecture
|
||||
|
||||
Urutau is one Go binary with no third-party dependency. Everything runs in one process.
|
||||
Urutau is one Go binary with no third-party dependency. It runs in two roles: the **hub**, which holds the data and serves the dashboard and the API, and the **probe**, a tiny process on each monitored server that only reads log files and sends them to the hub. The same binary does both (`urutau serve` and `urutau probe`); a separate scratch image carries the probe.
|
||||
|
||||
```
|
||||
cmd/urutau entry point: serve, doctor, healthcheck, version
|
||||
internal/app flags, wiring, the log runner, probe source, Tor lists, enforce and egress wiring, doctor
|
||||
cmd/urutau entry point: serve (hub), probe, probes, import, doctor, healthcheck, version
|
||||
internal/app flags, wiring, the log runner (fed by the probes), probe-log parser, Tor lists, enforce and egress wiring, import, doctor
|
||||
internal/tail rotation-aware file follower and rotated-file reader
|
||||
internal/core event model, parsers (Traefik JSON and text, sshd, fail2ban), classifier, error classes
|
||||
internal/store in-memory state, summaries, merge, snapshot, analytics, services, defense, roster
|
||||
@@ -18,7 +18,10 @@ internal/ua User-Agent parser (browser, system, device, bot, attack to
|
||||
internal/enforce second firewall: ban decisions, decision file, unban requests, operator allowances
|
||||
internal/egress outbound connection analysis: workloads, findings (beacon, C2, mining, scan...)
|
||||
internal/incidents tickets opened from egress findings or by hand, stored in incidents.json
|
||||
internal/fed hub that polls peers, live relay, study merge, decision and egress exchange
|
||||
internal/hub one node per probe: ingestion, commands queue, probe registry (probes.json)
|
||||
internal/wire probe-hub protocol: messages, limits, command-line validation
|
||||
internal/probeagent the probe: tailers, spool, client, command application
|
||||
internal/fed in-process aggregation of the nodes (summaries, IP tables, live, study, geography)
|
||||
internal/server HTTP handler, auth, API routes, HTML report, embedded dashboard (web/)
|
||||
deploy/host host kit: nftables table, rsyslog, logrotate, container map, fail2ban jail, installer
|
||||
```
|
||||
@@ -28,9 +31,17 @@ The only dependency is the Go standard library.
|
||||
## Data flow
|
||||
|
||||
```
|
||||
Traefik access.log auth.log fail2ban.log probe.log (nft, closed ports)
|
||||
│ │ │ │
|
||||
└──── tail.Follower (one goroutine per source) ┘
|
||||
── on each monitored server: the probe (urutau probe) ──────────────────────
|
||||
Traefik access.log auth.log fail2ban.log probe.log egress.log
|
||||
│ │ │ │ │
|
||||
└──── tail.Follower (one goroutine per source, rotation-aware) ┘
|
||||
containers.map and resolv.conf: whole file when it changes (sha256)
|
||||
▼
|
||||
batch (up to 5000 lines / 1 MiB / 1 s) ──► disk spool ──► HTTPS push
|
||||
│
|
||||
── on the hub (urutau serve) ───────────────────────────────────────▼─────
|
||||
one node per probe (own store, evlog, incidents, enforce, egress)
|
||||
offset check (inode or end > saved offset) ──► duplicate lines dropped
|
||||
▼
|
||||
parse (core.ParseTraefik / ParseAuth / ParseFail2ban / probe parser) → Event
|
||||
▼
|
||||
@@ -43,21 +54,23 @@ The only dependency is the Go standard library.
|
||||
intel (computed on demand): family, MITRE, network type, cadence, sessions,
|
||||
campaigns, verdict ──► dashboard, API, STIX, blocklist, HTML report
|
||||
▼
|
||||
enforce (optional): decision per attacking IP ──► decisions.log
|
||||
enforce (optional): decision per attacking IP ──► command queue of the node
|
||||
▼
|
||||
probe long-poll receives it, validates the line, appends to decisions.log
|
||||
▼
|
||||
host fail2ban jail "urutau" reads decisions.log and bans in the firewall
|
||||
▼
|
||||
fail2ban.log "Ban urutau" returns as an event (not counted as evidence)
|
||||
|
||||
egress.log (nft, new outbound connections) ──► egress.Source ──► findings
|
||||
egress lines ──► egress.Source ──► findings
|
||||
findings ──► incidents (tickets INC-n, suppression) ──► API and report
|
||||
```
|
||||
|
||||
Snapshot every 60 s: `state` ◄──► summaries, IP table, SSE. The second firewall never gains privileges: it only appends lines to a file that a jail on the host reads.
|
||||
Snapshot every 60 s: `state` ◄──► summaries, IP table, SSE. Neither the hub nor the probe gains privileges: the probe only appends lines to a file that a jail on the host reads, and only after validating that each line has exactly the shape the hub's ban code produces.
|
||||
|
||||
## Sources
|
||||
|
||||
Each source is followed by its own goroutine and reports a state: `following`, `waiting` (the file does not exist yet), `backfill` (first start, reading rotated copies), `degraded` (more than 20% of the last 1000 lines are unreadable, with at least 50 samples) or `error`. A line larger than 64 KiB is dropped and counted as malformed. On the first start without a snapshot, the rotated copies (`path.1`, `path.N.gz` up to 9) are read oldest first so the window is not empty.
|
||||
Each source is followed by its own goroutine **in the probe** and the hub reports its state: `following`, `waiting` (the file does not exist yet), `backfill` (first start, reading rotated copies), `degraded` (more than 20% of the last 1000 lines are unreadable, with at least 50 samples) or `error`. A line larger than 64 KiB is dropped and counted as malformed. On the first start without a snapshot, the rotated copies (`path.1`, `path.N.gz` up to 9) are read oldest first so the window is not empty.
|
||||
|
||||
Lines are decoded as follows:
|
||||
|
||||
@@ -66,7 +79,7 @@ Lines are decoded as follows:
|
||||
- **probe:** the `URUTAU-PROBE:` lines that the host kit logs for inbound connections to ports nobody listens on (`--probe-log`). Each becomes a `scanner` event with source `probe` (MITRE T1046), at most one per address, port and protocol per minute.
|
||||
- **fail2ban:** `Ban`, `Unban` and `Restore Ban` lines. A restored ban (replayed after a fail2ban restart) updates the ban state and is not scored.
|
||||
|
||||
The egress log (`--egress-log`) has its own source, described in the egress section. Log file paths are never exposed: neither the dashboard nor a peer export shows where a source reads from, only its name and state.
|
||||
The egress log (`--egress-log`) has its own source, described in the egress section. Log file paths never leave the probe, and the hub never shows them: the dashboard shows only the name and state of a source. The hub reads no log file at all.
|
||||
|
||||
Lines that are valid but carry nothing to record are ignored silently; lines that cannot be parsed are counted as malformed and shown per source in the dashboard.
|
||||
|
||||
@@ -152,7 +165,7 @@ This is why the number differs from Coolify's analytics, which counts every dist
|
||||
|
||||
`<data-dir>/events/` holds one JSON line per event, in the same format as the live stream, one file per UTC day. The current day is appended to and synced every 2 seconds; older days are gzip compressed. Files older than the retention are deleted, and the total is capped by `--events-max` (512 MB by default, `0` disables the registry). A day holds at most 200,000 lines; beyond that, events are only counted.
|
||||
|
||||
What enters: malicious events (scanner, exploit, bruteforce, ssh-fail, ssh-probe), ban and unban, successful SSH logins, a 404 answered to an attack tool, and `ok` or `notfound` answers only for addresses that are already suspicious or hostile (to show what they got). Never a legitimate visitor. Events relayed from peers are registered with the peer name as host.
|
||||
What enters: malicious events (scanner, exploit, bruteforce, ssh-fail, ssh-probe), ban and unban, successful SSH logins, a 404 answered to an attack tool, and `ok` or `notfound` answers only for addresses that are already suspicious or hostile (to show what they got). Never a legitimate visitor. Each event is registered with the name of the probe that sent it as host.
|
||||
|
||||
Failure behavior: a full disk, the size cap or the day cap drop events (counted, logged at most once in a while, never fatal); a corrupted line is skipped when reading; a partial line left by an earlier failure is terminated before the next write.
|
||||
|
||||
@@ -211,7 +224,7 @@ Rules (the first that matches, per address):
|
||||
|
||||
A sweep every 10 minutes, and after the start-up backfill, applies the same rules to the addresses active in the last 24 hours that nothing blocks yet. At most `--enforce-max-per-min` decisions are written per minute (default 60); the excess is dropped and counted. The advisory TTL grows with the number of earlier bans: 1 h, 6 h, 24 h, 7 d.
|
||||
|
||||
Never banned: private and reserved ranges, `--trusted`, the Cloudflare ranges, well known public resolvers, the peers and the server's own addresses, a verified crawler, an address with a legitimate visit in the last 24 hours, and an operator allowance (below). Each skip is counted by reason.
|
||||
Never banned: private and reserved ranges, `--trusted`, the Cloudflare ranges, well known public resolvers, the addresses of the probes and the servers' own addresses, a verified crawler, an address with a legitimate visit in the last 24 hours, and an operator allowance (below). Each skip is counted by reason.
|
||||
|
||||
Decision file, one line per ban (`MaxLogBytes` 20 MB, then rotated to `.1`):
|
||||
|
||||
@@ -223,7 +236,7 @@ Nothing the attacker controls enters the line: the address is re-formatted, the
|
||||
|
||||
Unban: `POST /api/v1/enforce/unban` appends `<time> urutau unban ip=<ip> allow=<seconds>` to the unban file (`--enforce-unban-log`, by default `unban.log` next to the decision file); a systemd path unit of the host kit lifts the fail2ban block. With `allow` above zero the engine does not ban the address again for that long (at most 30 days); `DELETE /api/v1/enforce/allow` ends the allowance.
|
||||
|
||||
Sharing (`--enforce-share=on`): hub and peers exchange decisions through `GET` and `POST /api/v1/peer/decisions` and unbans through `POST /api/v1/peer/unban`. Each side applies its own exclusions, accepts only the fixed reason slugs, caps the TTL at 6 hours, and bans on a peer's word only an address it also saw attacking in the last 7 days (otherwise the skip is `peer_unconfirmed`).
|
||||
Sharing (`--enforce-share=on`): a decision taken by the node of one probe is also queued for the nodes of the others. Each node applies its own exclusions, accepts only the fixed reason slugs, caps the TTL at 6 hours, and bans on another node's word only an address it also saw attacking in the last 7 days (otherwise the skip is `peer_unconfirmed`).
|
||||
|
||||
## Egress analysis
|
||||
|
||||
@@ -244,7 +257,7 @@ Findings (`kind`, severity):
|
||||
| `scan` | fan-out of more than 50 destinations or 100 ports in 10 minutes, outside `scanner` workloads |
|
||||
| `new_geo` | first contact with a country after the workload's learning time (24 h) |
|
||||
|
||||
Destinations of peers, trusted addresses and the server's own public addresses never raise findings, and regular connections to large CDNs and clouds are low severity unless the destination attacked the server. Limits: 50,000 pairs and destinations, 2,000 findings, 720 hourly buckets. `GET /api/v1/egress` returns the findings, workloads, countries and an hourly timeline; a hub also merges the `GET /api/v1/peer/egress` answer of each peer.
|
||||
Destinations of the probes, trusted addresses and the server's own public addresses never raise findings, and regular connections to large CDNs and clouds are low severity unless the destination attacked the server. Limits: 50,000 pairs and destinations, 2,000 findings, 720 hourly buckets. `GET /api/v1/egress` returns the findings, workloads, countries and an hourly timeline; the hub merges the egress report of every node. The egress settings (workloads, resolvers, allowed destinations) are kept per probe on the hub, in `probes.json`.
|
||||
|
||||
## Incidents
|
||||
|
||||
@@ -256,23 +269,39 @@ Destinations of peers, trusted addresses and the server's own public addresses n
|
||||
|
||||
## State and persistence
|
||||
|
||||
The state lives in memory: minute buckets for the latest 48 hours and hourly data up to 30 days, hourly top lists (paths, domains, User-Agents, users), a table of up to 20,000 IPs (when full, the 10% with the lowest score are evicted; banned IPs are kept), a feed of the latest 500 events and the active bans. `--retention` (1h to 720h) bounds how long IPs are kept; old IPs are pruned every 10 minutes.
|
||||
Each node (one per probe) keeps its own state in memory: minute buckets for the latest 48 hours and hourly data up to 30 days, hourly top lists (paths, domains, User-Agents, users), a table of up to 20,000 IPs (when full, the 10% with the lowest score are evicted; banned IPs are kept), a feed of the latest 500 events and the active bans. `--retention` (1h to 720h) bounds how long IPs are kept; old IPs are pruned every 10 minutes.
|
||||
|
||||
Every 60 seconds, and on shutdown, the state is written to `urutau-state.gob` in the data directory together with the inode and offset of every source. On start it is restored and each source resumes exactly where it stopped, so a restart never counts a log twice. A snapshot is skipped while a backfill runs. An unreadable snapshot is moved to `urutau-state.gob.corrupt` and the service starts empty, reading the logs again (including the rotated copies).
|
||||
Every 60 seconds, and on shutdown, each node writes its state to `urutau-state.gob` together with the inode and offset of every source. The primary node (the probe whose name equals `URUTAU_NAME`) uses the data-dir root, exactly the 1.x layout; the others use `<data-dir>/probes/<name>/`. On start the state is restored and the hub tells each probe, in the `hello`, the offsets it has, so a restart of either side never counts a line twice and never loses one. A snapshot is skipped while a backfill runs. An unreadable snapshot is moved to `urutau-state.gob.corrupt` and the service starts empty, reading the logs again (including the rotated copies).
|
||||
|
||||
The process sets a soft memory limit of 256 MiB unless `GOMEMLIMIT` is set. The worst case measured is about 54 MiB of heap and a snapshot of about 27 MB.
|
||||
|
||||
## Federation
|
||||
## Probes and the hub
|
||||
|
||||
A hub is an ordinary instance started with `--peer name=https://url`, and it needs `URUTAU_PEER_TOKEN`. Every 15 seconds it calls each peer's `GET /api/v1/peer/export?range=...` (for the background ranges `1h`, `24h`, `7d` and `30d`; any other range or custom period is fetched on demand) with the peer token and keeps the latest answer. The export is `{"v":1,"summary":...,"traffic":{...}}` with the top 500 IPs and their detail, cached for 5 seconds on the peer. The peer token opens only the federation routes: the export, the live stream, `GET /api/v1/peer/period` (the study of sessions, campaigns and metrics the hub merges for a period or an IP; a peer runs at most two at once), `GET /api/v1/peer/egress` (the egress report) and, with `--enforce-share`, `GET` and `POST /api/v1/peer/decisions` and `POST /api/v1/peer/unban`. The hub never follows redirects, requires `https` outside loopback, uses a 4 second timeout, caps the body at 8 MB and sanitizes and caps whatever a peer sends. A peer that fails is marked offline and the others carry on. The dashboard host selector then offers `all`, the hub itself and each peer; summaries, traffic and IP tables are merged, and every row carries the host it came from.
|
||||
The probe is a client of the hub: it opens no port. Plain HTTPS, no WebSocket, so any reverse proxy or CDN works (requests are short; the long-poll lasts at most 25 s). Authentication is `Authorization: Bearer urp_...` plus `X-Urutau-Probe: <name>`. The hub keeps only the SHA-256 of each token (`probes.json`) and compares in constant time; a wrong token is a bare 401 under the same attempt limiter as the login. Plain `http://` is accepted only for loopback or private addresses (for example `http://urutau:8790` on the `urutau-edge` network).
|
||||
|
||||
### Live relay
|
||||
| Route | Purpose |
|
||||
|---|---|
|
||||
| `POST /api/v1/probe/hello` | start of every session: protocol version in, the offsets the hub holds out (a probe without local state starts from them). 409 on an incompatible version |
|
||||
| `POST /api/v1/probe/push` | one batch (`seq`, up to 5000 lines, optional gzip, 2 MiB on the wire and 8 MiB inflated, a line of 64 KiB at most) and the probe status. The hub applies the whole batch to the node, then answers `ack = seq`; a repeated `seq` is answered without being applied again. 503 with `Retry-After` while the node loads or its queue is full, 429 for a second concurrent push |
|
||||
| `GET /api/v1/probe/commands?after=<seq>&wait=<s>` | long-poll (at most 25 s) for ban and unban lines; answers at once when the queue has a command newer than `after` |
|
||||
|
||||
Besides the export, a hub keeps one `GET /api/v1/peer/stream` connection open per peer (a subscription per peer, with the peer's own token) and relays the live malicious events to its dashboard. What comes from a peer is bounded and sanitized: at most about 50 events per second per peer, lines of at most 16 KB, a buffer of the latest 500 relayed events (served by `/api/v1/live/recent`), and reconnection with backoff from 1 s up to 60 s. A peer serves at most 10 stream connections.
|
||||
**Spool.** Before sending, the probe writes each batch to `<state-dir>/spool/NNNNNNNNNNNN.json` and sends them in order, so a hub outage loses nothing. The spool is capped by `URUTAU_PROBE_SPOOL_MAX` (64 MiB by default); beyond it the oldest batch is deleted and its lines are added to the `dropped` counter of the probe status, which the Sources page shows. `state.json` records the batch sequence, the last command applied and the read position of every source, written atomically after each ack. After an error the probe reconnects with exponential backoff from 1 s to 60 s with a 20% jitter.
|
||||
|
||||
**Offsets.** The hub is the authority: it keeps the offset of each source in the snapshot of the node and accepts a line only if its inode differs from the saved one or its end offset is past it. Replaying a spool, or importing a 1.x data directory (`urutau import`), therefore neither duplicates nor skips lines.
|
||||
|
||||
**Liveness.** With nothing to send, the probe pushes an empty batch with its status every 15 s; the hub marks it offline after 45 s without a push.
|
||||
|
||||
**Commands.** The hub queues up to 10,000 commands per node (`commands.json`); the oldest are dropped and counted. The probe accepts a command only if `wire.ValidCmdLine` passes (the exact format of a ban or unban line, with a valid address, reason slug and TTL), appends it with `O_APPEND` and `fsync`, and records the sequence so that a repeated command is not written twice. An invalid line is counted in `cmd_errors` and never written. A probe whose `URUTAU_ENFORCE_LOG` is empty ignores ban commands and counts the error.
|
||||
|
||||
**Footprint.** The probe never calls geolocation, intelligence or the store; its memory target is under 20 MB of RSS, checked by a test, and its image is under 15 MB.
|
||||
|
||||
### Aggregation across probes
|
||||
|
||||
`internal/fed` joins the nodes in the process (no HTTP any more): the dashboard host selector offers `all` and each probe; summaries, traffic, IP tables, studies and the live feed merge the nodes and every row carries the host it came from. An incident is identified as `host/INC-n` (each node numbers its own); a bare `INC-n` means the primary node.
|
||||
|
||||
### Geography aggregation
|
||||
|
||||
`GET /api/v1/geo` is computed from the IP table (local and the peers' exports) joined with the geolocation databases: countries first, then, for one country, its regions, cities and top IPs. Results are cached for 5 seconds, in a cache of at most 256 keys.
|
||||
`GET /api/v1/geo` is computed from the IP table (of every node) joined with the geolocation databases: countries first, then, for one country, its regions, cities and top IPs. Results are cached for 5 seconds, in a cache of at most 256 keys.
|
||||
|
||||
## HTTP layer
|
||||
|
||||
@@ -280,7 +309,7 @@ The server sets read, write and idle timeouts, `MaxHeaderBytes` of 16 KB, caps `
|
||||
|
||||
## API routes
|
||||
|
||||
All `/api/v1/*` routes except the federation ones need `URUTAU_TOKEN` (bearer) or a session cookie; the peer token gets 403 on them. Analysis routes live in `internal/server/api_<name>.go` files and register themselves with `registerUserRoute`. Routes that take a range accept `range`, or `from` and `to`.
|
||||
The user routes under `/api/v1/*` need `URUTAU_TOKEN` (bearer) or a session cookie; the `/api/v1/probe/*` routes need a probe token and nothing else opens them. The 1.x `/api/v1/peer/*` routes no longer exist (404). Analysis routes live in `internal/server/api_<name>.go` files and register themselves with `registerUserRoute`. Routes that take a range accept `range`, or `from` and `to`.
|
||||
|
||||
| Route | Purpose |
|
||||
|---|---|
|
||||
@@ -299,8 +328,8 @@ All `/api/v1/*` routes except the federation ones need `URUTAU_TOKEN` (bearer) o
|
||||
| `GET /api/v1/egress` | outbound findings |
|
||||
| `GET /api/v1/incidents`, `/incidents/export.csv`, `/incidents/{id}`, `POST /incidents`, `PATCH /incidents/{id}`, `POST /incidents/{id}/comments` | tickets |
|
||||
| `GET /api/v1/report` | report as JSON or HTML (`?format=`) |
|
||||
| `GET /api/v1/peer/export`, `/peer/stream`, `/peer/period`, `/peer/egress` | federation, peer token only |
|
||||
| `GET`, `POST /api/v1/peer/decisions`, `POST /api/v1/peer/unban` | decision sharing, peer token only, `--enforce-share` |
|
||||
| `GET /api/v1/probes`, `POST /probes`, `PUT /probes/{name}`, `DELETE /probes/{name}` | probe registry behind the Sources page: list with status, create (the token is shown once), edit location and egress settings, revoke (the data is kept) |
|
||||
| `POST /api/v1/probe/hello`, `/probe/push`, `GET /probe/commands` | probe protocol, probe token only |
|
||||
|
||||
List endpoints (IPs, sessions, campaigns, events of an address) are paginated by the backend; event search pages by cursor.
|
||||
|
||||
@@ -308,11 +337,14 @@ List endpoints (IPs, sessions, campaigns, events of an address) are paginated by
|
||||
|
||||
| Where | What |
|
||||
|---|---|
|
||||
| `<data-dir>/urutau-state.gob` | state snapshot with the offset of every source (`.corrupt` when unreadable) |
|
||||
| `<data-dir>/urutau-state.gob` | snapshot of the primary node with the offset of every source (`.corrupt` when unreadable) |
|
||||
| `<data-dir>/probes/<name>/` | the same layout (snapshot, `events/`, `incidents.json`, `enforce.json`, `commands.json`) for every other probe |
|
||||
| `<data-dir>/probes.json` | registry of probes: name, SHA-256 of the token, location, egress settings (never the token) |
|
||||
| `<data-dir>/events/YYYY-MM-DD.jsonl[.gz]` | event registry, one JSON line per event |
|
||||
| `<data-dir>/geo/` | DB-IP Lite city and ASN databases |
|
||||
| `<data-dir>/tor/` | cache of the Tor exit and relay lists |
|
||||
| `<data-dir>/enforce.json` | state of the second firewall |
|
||||
| `<data-dir>/incidents.json` | tickets |
|
||||
| `--enforce-log`, `unban.log` | decision file read by the host jail and unban requests read by the host |
|
||||
| `--probe-log`, `--egress-log`, `--egress-containers` | kernel logs and container map written by the host kit in `deploy/host` |
|
||||
| `<state-dir>/spool/`, `<state-dir>/state.json` | **on the probe:** pending batches, sequence, read positions, last command |
|
||||
| `URUTAU_ENFORCE_LOG`, `URUTAU_ENFORCE_UNBAN_LOG` | **on the probe:** decision file read by the host jail and unban requests read by the host |
|
||||
| `URUTAU_PROBE_LOG`, `URUTAU_EGRESS_LOG`, `URUTAU_EGRESS_CONTAINERS` | **on the probe:** kernel logs and container map written by the host kit in `deploy/host` |
|
||||
Reference in new issue
Block a user