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
@@ -24,7 +24,7 @@ func enforceRig(t *testing.T, share bool) (http.Handler, *enforce.Engine, string
|
||||
st.SetIngestHook(e.Observe)
|
||||
SetEnforce(e)
|
||||
t.Cleanup(func() { SetEnforce(nil) })
|
||||
return New(Options{Token: userTok, PeerTokens: []string{peerTok}, Version: "t", Store: st}), e, log
|
||||
return New(Options{Token: userTok, Version: "t", Store: st}), e, log
|
||||
}
|
||||
|
||||
func TestEnforceAPI(t *testing.T) {
|
||||
@@ -66,9 +66,6 @@ func TestEnforceAPI(t *testing.T) {
|
||||
if w := do(h, "GET", "/api/v1/enforce?range=24h", nil, nil); w.Code != 401 {
|
||||
t.Fatalf("anonymous %d", w.Code)
|
||||
}
|
||||
if w := do(h, "GET", "/api/v1/enforce?range=24h", map[string]string{"Authorization": "Bearer " + peerTok}, nil); w.Code != 403 {
|
||||
t.Fatalf("peer token %d", w.Code)
|
||||
}
|
||||
if w := do(h, "GET", "/api/v1/enforce?range=bad", cloneHdr(auth), nil); w.Code != 400 {
|
||||
t.Fatalf("bad range %d", w.Code)
|
||||
}
|
||||
@@ -96,69 +93,6 @@ func post(h http.Handler, path, tok, body string) *httptest.ResponseRecorder {
|
||||
return w
|
||||
}
|
||||
|
||||
func TestPeerDecisionsEndpoints(t *testing.T) {
|
||||
h, e, log := enforceRig(t, true)
|
||||
good := `{"decisions":[{"t":` + strconv.FormatInt(time.Now().Unix(), 10) + `,"ip":"203.0.114.9","reason":"sqli","score":80,"ttl":3600},` +
|
||||
`{"t":1,"ip":"203.0.114.10","reason":"x\ny","score":80,"ttl":3600},{"ip":"10.0.0.1","reason":"rce","ttl":60}]}`
|
||||
p := "/api/v1/peer/decisions?from=hostinger"
|
||||
for _, tok := range []string{"", "wrong-token-0123456789-abcdefghijklmnopqrs", userTok} {
|
||||
if w := post(h, p, tok, good); w.Code != 401 && w.Code != 403 {
|
||||
t.Fatalf("token %q: %d", tok, w.Code)
|
||||
}
|
||||
if w := do(h, "GET", "/api/v1/peer/decisions", map[string]string{"Authorization": "Bearer " + tok}, nil); w.Code != 401 && w.Code != 403 {
|
||||
t.Fatalf("GET token %q: %d", tok, w.Code)
|
||||
}
|
||||
}
|
||||
if w := post(h, p, peerTok, strings.Repeat(" ", 70<<10)); w.Code != 413 {
|
||||
t.Fatalf("big body: %d", w.Code)
|
||||
}
|
||||
if w := post(h, p, peerTok, "{nope"); w.Code != 400 {
|
||||
t.Fatalf("bad json: %d", w.Code)
|
||||
}
|
||||
var many strings.Builder
|
||||
many.WriteString(`{"decisions":[`)
|
||||
for i := 0; i < 501; i++ {
|
||||
if i > 0 {
|
||||
many.WriteString(",")
|
||||
}
|
||||
many.WriteString(`{"ip":"1.1.1.1"}`)
|
||||
}
|
||||
many.WriteString(`]}`)
|
||||
if w := post(h, p, peerTok, many.String()); w.Code != 413 {
|
||||
t.Fatalf("501 items: %d", w.Code)
|
||||
}
|
||||
ctx, cancel := context.WithCancel(context.Background())
|
||||
defer cancel()
|
||||
go e.Run(ctx)
|
||||
e.Observe(core.Event{Time: time.Now(), IP: "203.0.114.9", Cat: core.Scanner, Source: "traefik", Method: "GET", Path: "/x", Status: 404, UA: "x"}, "")
|
||||
for i := 0; i < 200 && e.Report(0).Coverage.AttackIPs == 0; i++ {
|
||||
time.Sleep(10 * time.Millisecond)
|
||||
}
|
||||
w := post(h, p, peerTok, good)
|
||||
if w.Code != 200 || !strings.Contains(w.Body.String(), `"accepted":1`) || !strings.Contains(w.Body.String(), `"invalid":2`) {
|
||||
t.Fatalf("%d %s", w.Code, w.Body)
|
||||
}
|
||||
b, _ := os.ReadFile(log)
|
||||
if strings.Count(string(b), "\n") != 1 || !strings.Contains(string(b), "ip=203.0.114.9 reason=sqli") || !strings.Contains(string(b), "src=peer:hostinger") {
|
||||
t.Fatalf("log %q", b)
|
||||
}
|
||||
// GET returns local decisions only
|
||||
if len(e.LocalSince(0)) != 0 {
|
||||
t.Fatal("peer decision leaked into the local list")
|
||||
}
|
||||
rr := do(h, "GET", "/api/v1/peer/decisions?since=0", map[string]string{"Authorization": "Bearer " + peerTok}, nil)
|
||||
if rr.Code != 200 || !strings.Contains(rr.Body.String(), `"decisions":[]`) {
|
||||
t.Fatalf("%d %s", rr.Code, rr.Body)
|
||||
}
|
||||
}
|
||||
|
||||
func TestPeerDecisionsShareOff(t *testing.T) {
|
||||
h, _, _ := enforceRig(t, false)
|
||||
if w := post(h, "/api/v1/peer/decisions", peerTok, `{"decisions":[]}`); w.Code != 404 {
|
||||
t.Fatalf("share off: %d", w.Code)
|
||||
}
|
||||
}
|
||||
|
||||
func TestEnforceFromStoreHook(t *testing.T) {
|
||||
log := filepath.Join(t.TempDir(), "d.log")
|
||||
st := store.New(store.Config{Name: "oracle", Version: "t", Retention: 720 * time.Hour})
|
||||
|
||||
Reference in new issue
Block a user