feat!: Urutau 2.0.0, ultralight probes and a single analysis hub
CI / Format and vet (pull_request) Failing after 53s
CI / Dependency audit (pull_request) Successful in 33s
CI / Tests (Linux, race detector) (pull_request) Successful in 2m1s
CI / Docker images (build and smoke test) (pull_request) Failing after 47s

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:
Lucas RayanandClaude Opus 5.5 committed 2026-11-15 22:14:50 -03:00
1 parent 23a7a5963a
commit 8546d14cef
130 files changed
+9396 -3311

No files matched your search

+162 -3
View File
@@ -14,6 +14,7 @@ import (
"git.lucasrguerra.dev.br/ciberfauna/urutau/internal/core"
"git.lucasrguerra.dev.br/ciberfauna/urutau/internal/store"
"git.lucasrguerra.dev.br/ciberfauna/urutau/internal/tail"
"git.lucasrguerra.dev.br/ciberfauna/urutau/internal/wire"
)
const maxLine = 64 * 1024
@@ -112,8 +113,16 @@ type Runner struct {
Sources []*source
DataDir string
Log *slog.Logger
// EgressFeed receives the "egress" lines of a probe (nil: they are only counted).
EgressFeed func(line []byte)
mu sync.Mutex // commit mutex: held while a line is applied and by snapshots
remote map[string]store.Offset // hub-committed offsets of the sources fed by a probe
isRemote bool
rstatus atomic.Pointer[wire.Status]
connected atomic.Bool
egLines atomic.Uint64
}
// NewRunner builds the runner for the enabled sources.
@@ -143,10 +152,157 @@ func NewRunner(c Config, st *store.Store, log *slog.Logger) (*Runner, error) {
return r, nil
}
func (r *Runner) statuses() []store.SourceStatus {
out := make([]store.SourceStatus, 0, len(r.Sources))
// NewRemoteRunner builds the runner of a node whose sources are fed by a probe
// through Feed: the four parsed sources exist, none follows a file.
func NewRemoteRunner(c Config, st *store.Store, log *slog.Logger, dataDir string) (*Runner, error) {
c.TraefikLog, c.AuthLog, c.Fail2banLog, c.ProbeLog = "", "", "", ""
r, err := NewRunner(c, st, log)
if err != nil {
return nil, err
}
r.DataDir, r.isRemote, r.remote = dataDir, true, map[string]store.Offset{}
for _, name := range []string{"traefik", "ssh", "fail2ban", "probe"} {
parse := map[string]func([]byte) (core.Event, error){"traefik": traefikParse, "ssh": authParse, "fail2ban": f2bParse, "probe": newProbeParser().parse}[name]
r.Sources = append(r.Sources, &source{name: name, parse: parse})
}
return r, nil
}
// runnerSource maps a wire source name to the runner's (and snapshot's) name.
func runnerSource(src string) string {
if src == wire.SrcAuth {
return "ssh"
}
return src
}
// wireSource is the inverse of runnerSource.
func wireSource(name string) string {
if name == "ssh" {
return wire.SrcAuth
}
return name
}
func (r *Runner) find(name string) *source {
for _, s := range r.Sources {
out = append(out, s.status())
if s.name == name {
return s
}
}
return nil
}
// StartRemote sets the committed offsets of a probe-fed runner (from the
// snapshot); there are no followers to start.
func (r *Runner) StartRemote(ctx context.Context, offsets map[string]store.Offset) {
r.mu.Lock()
defer r.mu.Unlock()
for k, v := range offsets {
r.remote[k] = v
}
}
// RemoteOffsets returns the committed positions keyed by wire source name.
func (r *Runner) RemoteOffsets() map[string]wire.Pos {
r.mu.Lock()
defer r.mu.Unlock()
out := map[string]wire.Pos{}
for k, v := range r.remote {
out[wireSource(k)] = wire.Pos{Inode: v.Inode, Offset: v.Offset, FP: v.FP, FPLen: v.FPLen}
}
return out
}
// Feed applies one line of a probe (src is a wire source name): it is dropped
// when its end position is not past the committed one in the same file, else
// handled and committed. It reports whether the line was new.
func (r *Runner) Feed(src string, text []byte, end store.Offset) bool {
r.mu.Lock()
defer r.mu.Unlock()
return r.feedLocked(src, text, end)
}
func (r *Runner) feedLocked(src string, text []byte, end store.Offset) bool {
name := runnerSource(src)
if saved, ok := r.remote[name]; ok && end.Inode == saved.Inode && end.Offset <= saved.Offset {
return false
}
if src == wire.SrcEgress {
r.egLines.Add(1)
if r.EgressFeed != nil {
func() {
defer func() { recover() }() // one hostile line must never take the node down
r.EgressFeed(text)
}()
}
} else if s := r.find(name); s != nil {
r.handle(s)(text)
}
r.remote[name] = end
return true
}
// ApplyBatch applies the lines of a batch under the commit mutex.
func (r *Runner) ApplyBatch(lines []wire.Line) (accepted, dup int) {
r.mu.Lock()
defer r.mu.Unlock()
for _, l := range lines {
if r.feedLocked(l.Src, []byte(l.Text), store.Offset{Inode: l.End.Inode, Offset: l.End.Offset, FP: l.End.FP, FPLen: l.End.FPLen}) {
accepted++
} else {
dup++
}
}
return accepted, dup
}
// SetRemoteStatus stores the last status reported by the probe.
func (r *Runner) SetRemoteStatus(st wire.Status, connected bool) {
r.rstatus.Store(&st)
r.connected.Store(connected)
}
func (r *Runner) remoteStatuses() []store.SourceStatus {
ws := r.rstatus.Load()
var out []store.SourceStatus
seen := map[string]bool{}
if ws != nil {
for _, w := range ws.Sources {
name := runnerSource(w.Src)
seen[name] = true
row := store.SourceStatus{Name: name, State: w.State, Error: w.Error, Lines: w.Lines, Malformed: w.Oversize, LastEvent: w.LastLine}
if s := r.find(name); s != nil {
row.Lines, row.Malformed = max(row.Lines, s.lines.Load()), max(w.Oversize, s.malformed.Load())
if row.LastEvent == 0 {
row.LastEvent = s.lastEvent.Load()
}
if row.State == "following" && s.win.degraded() {
row.State, row.Error = "degraded", degradedMsg
}
}
out = append(out, row)
}
}
for _, s := range r.Sources { // sources the probe has not reported
if !seen[s.name] {
if ws == nil {
out = append(out, store.SourceStatus{Name: s.name, State: "waiting", Lines: s.lines.Load(), Malformed: s.malformed.Load(), LastEvent: s.lastEvent.Load()})
}
}
}
return out
}
func (r *Runner) statuses() []store.SourceStatus {
var out []store.SourceStatus
if r.isRemote {
out = r.remoteStatuses()
} else {
out = make([]store.SourceStatus, 0, len(r.Sources))
for _, s := range r.Sources {
out = append(out, s.status())
}
}
if r.Extra != nil {
out = append(out, r.Extra()...)
@@ -297,6 +453,9 @@ func (r *Runner) Save() error {
r.mu.Lock()
defer r.mu.Unlock()
offs := map[string]store.Offset{}
for k, v := range r.remote {
offs[k] = v
}
for _, s := range r.Sources {
if f := s.fol.Load(); f != nil {
p := f.Pos()