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>
71 lines
2.5 KiB
Go
71 lines
2.5 KiB
Go
package server
|
|
|
|
import (
|
|
"net/netip"
|
|
"strconv"
|
|
"testing"
|
|
"time"
|
|
|
|
"git.lucasrguerra.dev.br/ciberfauna/urutau/internal/egress"
|
|
"git.lucasrguerra.dev.br/ciberfauna/urutau/internal/store"
|
|
)
|
|
|
|
func TestEgressAPI(t *testing.T) {
|
|
st := store.New(store.Config{Name: "oracle", Version: "t", Retention: 720 * time.Hour})
|
|
h := New(Options{Token: userTok, Version: "t", Store: st})
|
|
auth := map[string]string{"Authorization": "Bearer " + userTok}
|
|
|
|
SetEgress(nil)
|
|
d := getJSON(t, h, "/api/v1/egress?range=24h", auth)
|
|
if d["enabled"] != false || d["findings"] == nil || d["top_dst"] == nil {
|
|
t.Fatalf("disabled: %v", d)
|
|
}
|
|
|
|
e, err := egress.New(egress.Config{Workloads: "ciberlab=10.0.5.0/24:scanner"})
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
SetEgress(e)
|
|
defer SetEgress(nil)
|
|
now := time.Now()
|
|
ev := func(at time.Time, src, dst string, port uint16) egress.Event {
|
|
return egress.Event{Time: at, Src: netip.MustParseAddr(src), Dst: netip.MustParseAddr(dst), Proto: "tcp", DPort: port, In: "br-1"}
|
|
}
|
|
e.IngestEvent(ev(now.Add(-time.Hour), "10.0.3.5", "203.0.113.3", 6667))
|
|
e.IngestEvent(ev(now.Add(-time.Hour), "10.0.3.5", "203.0.113.4", 443))
|
|
for i := 0; i < 80; i++ {
|
|
e.IngestEvent(ev(now.Add(-30*time.Minute+time.Duration(i)*time.Second), "10.0.5.2", "198.18.0."+strconv.Itoa(i+1), 80))
|
|
}
|
|
d = getJSON(t, h, "/api/v1/egress?range=24h", auth)
|
|
if d["enabled"] != true || d["source"].(map[string]any)["state"] == nil {
|
|
t.Fatalf("enabled: %v", d)
|
|
}
|
|
var port map[string]any
|
|
for _, f := range d["findings"].([]any) {
|
|
if m := f.(map[string]any); m["kind"] == "port" {
|
|
port = m
|
|
}
|
|
}
|
|
if port == nil || port["severity"] != "medium" || port["dport"].(float64) != 6667 || port["workload"] != "container 10.0.3.5" {
|
|
t.Fatalf("findings: %v", d["findings"])
|
|
}
|
|
if len(d["scanner"].(map[string]any)["bursts"].([]any)) != 1 || len(d["workloads"].([]any)) != 2 {
|
|
t.Fatalf("scanner/workloads: %v", d)
|
|
}
|
|
if tl := d["timeline"].(map[string]any); tl["step"].(float64) != 3600 || len(tl["series"].(map[string]any)) != 2 {
|
|
t.Fatalf("timeline: %v", tl)
|
|
}
|
|
if w := do(h, "GET", "/api/v1/egress?range=bogus", cloneHdr(auth), nil); w.Code != 400 {
|
|
t.Fatalf("range: %d", w.Code)
|
|
}
|
|
if w := do(h, "GET", "/api/v1/egress?host=nope", cloneHdr(auth), nil); w.Code != 404 {
|
|
t.Fatalf("host: %d", w.Code)
|
|
}
|
|
if w := do(h, "GET", "/api/v1/egress?range=24h", nil, nil); w.Code != 401 {
|
|
t.Fatalf("auth: %d", w.Code)
|
|
}
|
|
if w := do(h, "GET", "/api/v1/egress?range=24h", map[string]string{"Authorization": "Bearer peer-secret"}, nil); w.Code == 200 {
|
|
t.Fatalf("peer token must not open the user route")
|
|
}
|
|
}
|