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>
36 lines
1.1 KiB
Go
36 lines
1.1 KiB
Go
package app
|
|
|
|
import (
|
|
"log/slog"
|
|
"path/filepath"
|
|
"strconv"
|
|
|
|
"git.lucasrguerra.dev.br/ciberfauna/urutau/internal/ingress"
|
|
"git.lucasrguerra.dev.br/ciberfauna/urutau/internal/store"
|
|
)
|
|
|
|
// IngressPath is the aggregate of the firewall telemetry inside a node directory.
|
|
func IngressPath(dir string) string { return filepath.Join(dir, "ingress.json") }
|
|
|
|
// newIngress builds the firewall telemetry aggregate of one node. A source
|
|
// address is "banned" by the node's own ban state (the jails it has read from
|
|
// fail2ban.log, the urutau jail included). The aggregate only reads that state:
|
|
// it has no way to write an event, a score or a decision, so attempts from a
|
|
// banned address never become evidence.
|
|
func newIngress(st *store.Store, dir string, log *slog.Logger) *ingress.Agg {
|
|
a := ingress.New()
|
|
a.Banned = st.Banned
|
|
a.Geo = func(ip string) (string, string, string) {
|
|
g := st.GeoOf(ip)
|
|
asn := ""
|
|
if g.ASN != 0 {
|
|
asn = "AS" + strconv.FormatUint(uint64(g.ASN), 10)
|
|
}
|
|
return g.CC, asn, g.ASOrg
|
|
}
|
|
if err := a.Load(IngressPath(dir)); err != nil {
|
|
log.Warn("ingress state ignored", "dir", dir, "err", err)
|
|
}
|
|
return a
|
|
}
|