From 7b79bec4d1f0ddb4853fdde3672b3b2d2a4c1ca2 Mon Sep 17 00:00:00 2001 From: scanner <280983584+hivecommons-hive[bot]@users.noreply.github.com> Date: Mon, 16 Nov 2026 11:47:42 -0500 Subject: [PATCH] [scanner] fix: throttle proxy-proof rejection WARN Co-Authored-By: Claude Sonnet 5.5 Signed-off-by: scanner <280983584+hivecommons-hive[bot]@users.noreply.github.com> --- .../fixed-18377-proxy-proof-warn-throttle.md | 1 + src/pkg/dashboard/proxy_proof_warn_gate.go | 45 +++++++++++++++++++ .../dashboard/proxy_proof_warn_gate_test.go | 26 +++++++++++ src/pkg/dashboard/server.go | 6 ++- 4 files changed, 76 insertions(+), 2 deletions(-) create mode 100644 changelog.d/fixed-18377-proxy-proof-warn-throttle.md create mode 100644 src/pkg/dashboard/proxy_proof_warn_gate.go create mode 100644 src/pkg/dashboard/proxy_proof_warn_gate_test.go diff --git a/changelog.d/fixed-18377-proxy-proof-warn-throttle.md b/changelog.d/fixed-18377-proxy-proof-warn-throttle.md new file mode 100644 index 0000000000..ded34149de --- /dev/null +++ b/changelog.d/fixed-18377-proxy-proof-warn-throttle.md @@ -0,0 +1 @@ +- Dashboard: the "rejected hub-proxied request with unverified proxy proof" warning is now logged at most once a minute per reason and path (with a suppressed count) instead of once per request; the request is still rejected with 403 (#18377). diff --git a/src/pkg/dashboard/proxy_proof_warn_gate.go b/src/pkg/dashboard/proxy_proof_warn_gate.go new file mode 100644 index 0000000000..457dc39885 --- /dev/null +++ b/src/pkg/dashboard/proxy_proof_warn_gate.go @@ -0,0 +1,45 @@ +package dashboard + +import ( + "sync" + "time" +) + +// proxyProofWarnInterval is the minimum gap between WARN logs for the same +// rejection reason and path. A hub/spoke token mismatch rejects every request +// the hub proxies, which flooded the log (99 in 10m, #18377). +const proxyProofWarnInterval = time.Minute + +// proxyProofWarnGate dedupes the proxy-proof rejection WARN. The 403 itself is +// never throttled; only the log line is. +var proxyProofWarnGate = &warnGate{interval: proxyProofWarnInterval} + +type warnGate struct { + mu sync.Mutex + interval time.Duration + last map[string]time.Time + suppressed map[string]int +} + +// allow reports whether key may log now, and how many logs for key were +// suppressed since the last allowed one. +func (g *warnGate) allow(key string, now time.Time) (suppressed int, ok bool) { + g.mu.Lock() + defer g.mu.Unlock() + if g.last == nil { + g.last = map[string]time.Time{} + g.suppressed = map[string]int{} + } + if t, seen := g.last[key]; seen && now.Sub(t) < g.interval { + g.suppressed[key]++ + return 0, false + } + if len(g.last) >= 256 { // bound memory against forged paths + g.last = map[string]time.Time{} + g.suppressed = map[string]int{} + } + n := g.suppressed[key] + delete(g.suppressed, key) + g.last[key] = now + return n, true +} diff --git a/src/pkg/dashboard/proxy_proof_warn_gate_test.go b/src/pkg/dashboard/proxy_proof_warn_gate_test.go new file mode 100644 index 0000000000..668ca34ba8 --- /dev/null +++ b/src/pkg/dashboard/proxy_proof_warn_gate_test.go @@ -0,0 +1,26 @@ +package dashboard + +import ( + "testing" + "time" +) + +func TestWarnGateDedupesWithinInterval(t *testing.T) { + g := &warnGate{interval: time.Minute} + t0 := time.Unix(1000, 0) + if _, ok := g.allow("k", t0); !ok { + t.Fatal("first call must log") + } + for i := 0; i < 5; i++ { + if _, ok := g.allow("k", t0.Add(time.Second)); ok { + t.Fatal("repeat within interval must be suppressed") + } + } + if _, ok := g.allow("other", t0); !ok { + t.Fatal("distinct key must log") + } + n, ok := g.allow("k", t0.Add(2*time.Minute)) + if !ok || n != 5 { + t.Fatalf("got n=%d ok=%v, want 5 true", n, ok) + } +} diff --git a/src/pkg/dashboard/server.go b/src/pkg/dashboard/server.go index c2676bc7a1..02c1061bf6 100644 --- a/src/pkg/dashboard/server.go +++ b/src/pkg/dashboard/server.go @@ -2089,8 +2089,10 @@ func (s *Server) securityHeaders(next http.Handler) http.Handler { // auth-signin redirect, which is how #9785 looped. The page names the cause so // the hive's operator can act on it instead of seeing a browser error. func writeProxyProofRejected(w http.ResponseWriter, r *http.Request, reason string) { - slog.Warn("dashboard: rejected hub-proxied request with unverified proxy proof; hub and spoke dashboard tokens disagree or hub omitted the proof", - "reason", reason, "path", r.URL.Path, "user", r.Header.Get("X-Hive-User")) + if n, ok := proxyProofWarnGate.allow(reason+"|"+r.URL.Path, time.Now()); ok { + slog.Warn("dashboard: rejected hub-proxied request with unverified proxy proof; hub and spoke dashboard tokens disagree or hub omitted the proof", + "reason", reason, "path", r.URL.Path, "user", r.Header.Get("X-Hive-User"), "suppressed", n) + } w.Header().Set("Cache-Control", "no-store") if strings.HasPrefix(r.URL.Path, "/api/") { jsonStatusResponse(w, http.StatusForbidden, map[string]string{"error": reason})