Files
urutau/internal/app/ingress_doctor.go
T
Lucas RayanandClaude Sonnet 5.5 aefdcea8d2 feat(ingress): firewall telemetry of inbound attempts (host kit --ingress)
Observation-only nftables table (prerouting -150, counters and a
rate-limited log, never drops or modifies), a per-minute counters file,
probe sources ingress and ingresscnt, a per-host hourly aggregate in the
hub (exact totals, sampled ports/ASNs/countries, banned share by the
hub's own ban state, no ban feedback loop), GET /api/v1/ingress, a
Defense section, doctor check, docs EN/pt-BR and tests.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-11-23 09:09:16 -03:00

61 lines
1.9 KiB
Go

package app
import (
"fmt"
"os"
"path/filepath"
"sort"
"time"
"git.lucasrguerra.dev.br/ciberfauna/urutau/internal/ingress"
)
// ingressFresh is how old the last counters line may be before the firewall
// telemetry of a host counts as stale: the kit writes one every minute.
const ingressFresh = 5 * time.Minute
// doctorIngress reports, per host that ever sent it, whether the firewall
// telemetry (host kit --ingress) is present and fresh. It reads the saved
// aggregate of each node; no host sending it is "off", not a failure.
func doctorIngress(c Config, add func(name, status, detail string)) {
dirs := map[string]string{c.Name: c.DataDir}
if ents, err := os.ReadDir(filepath.Join(c.DataDir, "probes")); err == nil {
for _, e := range ents {
if e.IsDir() {
dirs[e.Name()] = filepath.Join(c.DataDir, "probes", e.Name())
}
}
}
names := make([]string, 0, len(dirs))
for n := range dirs {
names = append(names, n)
}
sort.Strings(names)
any := false
for _, n := range names {
p := IngressPath(dirs[n])
if _, err := os.Stat(p); err != nil {
continue
}
a := ingress.New()
if err := a.Load(p); err != nil {
add("ingress "+n, "warn", err.Error())
any = true
continue
}
in := a.Info()
any = true
switch {
case in.LastCounters == 0:
add("ingress "+n, "warn", "sampled log seen but no counters yet: check ingress.counters and urutau-ingress-tick.timer")
case time.Since(time.Unix(in.LastCounters, 0)) > ingressFresh:
add("ingress "+n, "warn", fmt.Sprintf("stale: last counters %s ago (is urutau-ingress-tick.timer running?)", time.Since(time.Unix(in.LastCounters, 0)).Round(time.Second)))
default:
add("ingress "+n, "ok", fmt.Sprintf("fresh: counters %s ago, %d sampled lines", time.Since(time.Unix(in.LastCounters, 0)).Round(time.Second), in.Lines))
}
}
if !any {
add("ingress", "off", "no firewall telemetry received (host kit: install.sh --ingress)")
}
}