carlos / platform Public

Edge protection: the probe-burst rule blocks by default (#491)

The burst rule watched from release (v0.33.5) so its trips could be
calibrated before anything was refused. This moves edgeguard.BurstRule
from watch to block, as 378646f1c did for the hard tier: in the default
mode a client in a cool-down is refused (429, Retry-After, reference
code) the catalogue paths an app is not known to serve, on the app that
tripped it and, through the signed mesh notices, on every app on every
platform edge. Ordinary pages, a static site's own files and fleet apps
are unchanged; an app's record-only switch still turns it off for that
app. Pending Paul's approval on the calibration evidence on #491.

Tests that assumed the burst rule only watches now name watch mode or
demote the rule; new witness TestBurstCatalogueRefusesByDefault, and
TestBurstNoticeAppliesOnThePeer runs in the default mode as well as
block mode.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
claude agent, operated by paul@keymail.dev 0fb7bfdb9f8c4820e52156bbf087bfab302cd461 parent 4c64167
6 files changed, +111 −39
  • internal/edge/burst_edge_test.go +88 −31
  • internal/edge/burst_notice_test.go +13 −2
  • internal/edge/edge.go +1 −1
  • internal/edge/guard.go +3 −2
  • internal/edgeguard/catalogue.go +5 −2
  • internal/edgeguard/catalogue_test.go +1 −1
diff --git a/internal/edge/burst_edge_test.go b/internal/edge/burst_edge_test.go
index eed075b06..816f7187d 100644
--- a/internal/edge/burst_edge_test.go
+++ b/internal/edge/burst_edge_test.go
@@ -220,11 +220,11 @@ func (g *burstRig) wantRefused(t *testing.T, w *httptest.ResponseRecorder, until
return code
}
-// The scanner's 60th not-found trips it. In the default (watch) mode its
-// 61st catalogue request still reaches the app, and is recorded as the
-// refusal it would have been, saying the cool-down started on this app.
+// The scanner's 60th not-found trips it. In watch mode its 61st catalogue
+// request still reaches the app, and is recorded as the refusal it would
+// have been, saying the cool-down started on this app.
func TestBurstTripsAndRecordsWouldRefuse(t *testing.T) {
- g := newBurstRig(t, "")
+ g := newBurstRig(t, "watch")
until := g.trip(t, burstHost)
tr := g.rec.trips[0]
ref, err := reqrec.ParseRef(tr.Ref, g.key)
@@ -263,6 +263,51 @@ func TestBurstRefusesInBlockMode(t *testing.T) {
}
}
+// The promotion (#491): in the default mode the burst rule refuses. After
+// the trip the cooling client's next catalogue request is refused on the
+// app it tripped on and on another app, an ordinary page still reaches the
+// app, and the probe rules themselves still only watch for a client that is
+// not cooling. The app's record-only switch turns the refusal off for that
+// app alone.
+func TestBurstCatalogueRefusesByDefault(t *testing.T) {
+ g := newBurstRig(t, "", burstHost+"/about")
+ if g.e.guard != guardCatalogue {
+ t.Fatalf("guard mode %v, want the catalogue's", g.e.guard)
+ }
+ until := g.trip(t, burstHost)
+ n := g.upstream.Load()
+ code := g.wantRefused(t, g.get(burstHost, "/wp-login.php"), until)
+ m := g.lastMatch(t, "/wp-login.php")
+ wantBurstMatch(t, m, reqrec.KindBlock, reqrec.CooldownFromThisApp, until)
+ if m.Ref != code || m.Status != 429 || g.upstream.Load() != n {
+ t.Fatalf("this app: %+v, upstream %d; want the refusal", m, g.upstream.Load()-n)
+ }
+ g.wantRefused(t, g.get(burstOther, "/xmlrpc.php"), until)
+ wantBurstMatch(t, g.lastMatch(t, "/xmlrpc.php"), reqrec.KindBlock, reqrec.CooldownFromOtherApp, until)
+ if w := g.get(burstHost, "/about"); w.Code != 200 || w.Body.String() != "page /about" {
+ t.Fatalf("/about: %d %q, want the page", w.Code, w.Body.String())
+ }
+
+ r := httptest.NewRequest("GET", "http://"+burstHost+"/wp-login.php", nil)
+ r.RemoteAddr = "198.51.100.7:4000"
+ w := httptest.NewRecorder()
+ g.e.ServeHTTP(w, r)
+ if w.Code != 404 || w.Body.String() != "the app's own 404" {
+ t.Fatalf("a client not cooling: %d %q, want the app's answer", w.Code, w.Body.String())
+ }
+ if m := g.lastMatch(t, "/wp-login.php"); m.Kind != reqrec.KindWatch || m.Tier != reqrec.TierProbe {
+ t.Fatalf("a client not cooling: match %+v, want the probe watch", m)
+ }
+
+ g.e.SetProtectionRecordOnly(map[string]bool{"bdk/shop": true})
+ n = g.upstream.Load()
+ if w := g.get(burstHost, "/wp-login.php"); w.Code != 404 || w.Body.String() != "the app's own 404" || g.upstream.Load() != n+1 {
+ t.Fatalf("record only: %d %q, want the app's answer", w.Code, w.Body.String())
+ }
+ wantBurstMatch(t, g.lastMatch(t, "/wp-login.php"), reqrec.KindWatch, reqrec.CooldownFromThisApp, until)
+ g.wantRefused(t, g.get(burstOther, "/wp-login.php"), until)
+}
+
// Review Focus 1: a page that is not in the catalogue is never refused,
// whoever shares the address.
func TestBurstNeverRefusesAnOrdinaryPage(t *testing.T) {
@@ -400,21 +445,31 @@ func TestBurstFleetAppNeverRefused(t *testing.T) {
}
// One request has one verdict, one record and one Protection count, however
-// many rules it meets.
+// many rules it meets. In the default mode that count is a block: the burst
+// rule refuses, and the Protection tab counts a refusal as blocked.
func TestBurstOneVerdictPerRequest(t *testing.T) {
- g := newBurstRig(t, "")
- until := g.trip(t, burstHost)
- g.meter.Drain()
- matches := len(g.rec.match)
- g.get(burstHost, "/wp-login.php")
- if len(g.rec.match) != matches+1 {
- t.Fatalf("%d matches for one request", len(g.rec.match)-matches)
- }
- wantBurstMatch(t, g.lastMatch(t, "/wp-login.php"), reqrec.KindWatch, reqrec.CooldownFromThisApp, until)
- f := g.meter.Drain()
- d, ok := f.Guard[usage.GuardKey(burstHost, "bdk", "shop")]
- if len(f.Guard) != 1 || !ok || d.Checked != 1 || d.Watch != 1 || d.Block != 0 || !maps.Equal(d.Groups, map[string]int64{"burst/probe-burst": 1}) {
- t.Fatalf("guard counts %+v, want one recorded burst/probe-burst", f.Guard)
+ for _, tc := range []struct {
+ protect string
+ kind reqrec.Kind
+ watch, block int64
+ }{
+ {"", reqrec.KindBlock, 0, 1},
+ {"watch", reqrec.KindWatch, 1, 0},
+ } {
+ g := newBurstRig(t, tc.protect)
+ until := g.trip(t, burstHost)
+ g.meter.Drain()
+ matches := len(g.rec.match)
+ g.get(burstHost, "/wp-login.php")
+ if len(g.rec.match) != matches+1 {
+ t.Fatalf("mode %q: %d matches for one request", tc.protect, len(g.rec.match)-matches)
+ }
+ wantBurstMatch(t, g.lastMatch(t, "/wp-login.php"), tc.kind, reqrec.CooldownFromThisApp, until)
+ f := g.meter.Drain()
+ d, ok := f.Guard[usage.GuardKey(burstHost, "bdk", "shop")]
+ if len(f.Guard) != 1 || !ok || d.Checked != 1 || d.Watch != tc.watch || d.Block != tc.block || !maps.Equal(d.Groups, map[string]int64{"burst/probe-burst": 1}) {
+ t.Fatalf("mode %q: guard counts %+v, want one %s burst/probe-burst", tc.protect, f.Guard, tc.kind)
+ }
}
}
@@ -436,9 +491,11 @@ func TestBurstWatchNeverWeakensABlock(t *testing.T) {
}
})
t.Run("static rewrite", func(t *testing.T) {
- // The default mode, where the burst rule watches and the .env rule
- // blocks. The .git rule watches here, so a hard-tier request path
- // whose own verdict does not block still reaches the static handler.
+ // The default mode with the burst rule watching, as an app's own
+ // exemption will make it, and the .env rule blocking. The .git rule
+ // watches here, so a hard-tier request path whose own verdict does
+ // not block still reaches the static handler.
+ demoteBurstRule(t)
g := newBurstStaticRig(t, "", map[string]string{".env": "SECRET=1", "_redirects": "/* /.env 200\n"})
until := g.trip(t, burstHost)
env, ok := edgeguard.RuleByID("hard.secrets.env")
@@ -471,8 +528,8 @@ func TestBurstWatchNeverWeakensABlock(t *testing.T) {
if m := g.lastMatch(t, "/.git/config"); m.Kind != reqrec.KindBlock || m.RuleID != "hard.secrets.env" {
t.Fatalf("/.git/config: match %+v, want the hard block", m)
}
- // Without the promotion the burst watch stands, as the first
- // verdict that does not block.
+ // With the .env rule watching too, the burst watch stands, as the
+ // first verdict that does not block.
env.Mode = edgeguard.ModeWatch
g.get(burstHost, "/wp-login.php")
wantBurstMatch(t, g.lastMatch(t, "/wp-login.php"), reqrec.KindWatch, reqrec.CooldownFromThisApp, until)
@@ -795,13 +852,14 @@ func TestBurstStaleFillCountedOnceAtTheHome(t *testing.T) {
}
}
-// promoteBurstRule sets the burst rule's catalogue mode to block for the
-// test, as the later one-line promotion will: in the default mode the burst
-// rule then refuses while the probe rules still only watch.
-func promoteBurstRule(t *testing.T) {
+// demoteBurstRule sets the burst rule's catalogue mode back to watch for the
+// test, as it was before the promotion (#491): in the default mode the burst
+// rule then only records.
+func demoteBurstRule(t *testing.T) {
t.Helper()
- edgeguard.BurstRule.Mode = edgeguard.ModeBlock
- t.Cleanup(func() { edgeguard.BurstRule.Mode = edgeguard.ModeWatch })
+ mode := edgeguard.BurstRule.Mode
+ edgeguard.BurstRule.Mode = edgeguard.ModeWatch
+ t.Cleanup(func() { edgeguard.BurstRule.Mode = mode })
}
// Fix round 1, finding 2: a static site's own file is never refused by the
@@ -826,8 +884,7 @@ func TestBurstNeverRefusesAnExistingStaticHardFile(t *testing.T) {
}
}
})
- t.Run("burst rule promoted", func(t *testing.T) {
- promoteBurstRule(t)
+ t.Run("default mode", func(t *testing.T) {
// With the .env rule watching (as an app's own allow rule will make
// it), a burst refusal still never takes a file the site has.
env, ok := edgeguard.RuleByID("hard.secrets.env")
diff --git a/internal/edge/burst_notice_test.go b/internal/edge/burst_notice_test.go
index 2f578afae..a57226d55 100644
--- a/internal/edge/burst_notice_test.go
+++ b/internal/edge/burst_notice_test.go
@@ -3,6 +3,7 @@ package edge
import (
"bufio"
"bytes"
+ "cmp"
"context"
"crypto/rand"
"crypto/tls"
@@ -309,9 +310,19 @@ func transmitted(x *noticeEdge) int64 {
}
// A client that trips on annie is refused on betty, on betty's own app,
-// with the record saying the cool-down started on another app.
+// with the record saying the cool-down started on another app: in block
+// mode, and in the default mode since the promotion (#491).
func TestBurstNoticeAppliesOnThePeer(t *testing.T) {
- s := newNoticeScene(t, true)
+ for _, protect := range []string{"block", ""} {
+ t.Run("mode "+cmp.Or(protect, "default"), func(t *testing.T) {
+ s := newNoticeScene(t, true)
+ t.Setenv("CARLOS_EDGE_PROTECT", protect)
+ burstNoticeAppliesOnThePeer(t, s)
+ })
+ }
+}
+
+func burstNoticeAppliesOnThePeer(t *testing.T, s *noticeScene) {
a := s.add(t, "annie", "127.0.0.11", "shop.example.com", "bdk", "shop", true)
b := s.add(t, "betty", "127.0.0.12", "blog.example.com", "bab", "blog", true)
s.publish(t)
diff --git a/internal/edge/edge.go b/internal/edge/edge.go
index 57e8ca19c..d07cca104 100644
--- a/internal/edge/edge.go
+++ b/internal/edge/edge.go
@@ -339,7 +339,7 @@ type Edge struct {
// guard is CARLOS_EDGE_PROTECT, read once in New: what the edge does
// with a request matching a hard or probe rule (guard.go). By default
// each rule's own mode: from catalogue version 2 the hard tier blocks
- // and the probe tier watches.
+ // and the probe tier watches; the probe-burst rule blocks (#491).
guard guardMode
// guardMint is mintRef, bound once in New: a method value taken per
// request would allocate for every guarded request, and most never
diff --git a/internal/edge/guard.go b/internal/edge/guard.go
index 268ec02d7..357acb301 100644
--- a/internal/edge/guard.go
+++ b/internal/edge/guard.go
@@ -23,8 +23,9 @@ type guardMode uint8
const (
// guardCatalogue, the default, does what each rule's own mode says. From
// catalogue version 2 the hard tier blocks; the probe tier watches and
- // the burst rule counts, so their matches are recorded with the app's
- // answer.
+ // its burst-mode rules count, so their matches are recorded with the
+ // app's answer. The probe-burst rule (edgeguard.BurstRule) blocks since
+ // its calibration review (#491): a cooling client is refused.
guardCatalogue guardMode = iota
// guardOff runs no check at all.
guardOff
diff --git a/internal/edgeguard/catalogue.go b/internal/edgeguard/catalogue.go
index 111686ca5..5ade98fec 100644
--- a/internal/edgeguard/catalogue.go
+++ b/internal/edgeguard/catalogue.go
@@ -116,8 +116,11 @@ var (
// it, because the cool-down is about the client, and the edge decides it
// beside Check rather than through it. It is here so a record or a
// reference code that names it is explained like any other rule (RuleByID,
-// RuleByHash). Its mode is watch until blocking is approved.
-var BurstRule = &Rule{ID: reqrec.BurstRuleID, Group: "probe-burst", Tier: reqrec.TierBurst, Mode: ModeWatch}
+// RuleByHash). It blocks: a client in a cool-down is refused the catalogue
+// paths the app is not known to serve, wherever the cool-down started. It
+// watched from release until the calibration review (#491); an app's
+// record-only switch still turns it off for that app.
+var BurstRule = &Rule{ID: reqrec.BurstRuleID, Group: "probe-burst", Tier: reqrec.TierBurst, Mode: ModeBlock}
var burstRuleHash = reqrec.RuleHash(BurstRule.ID)
diff --git a/internal/edgeguard/catalogue_test.go b/internal/edgeguard/catalogue_test.go
index 792703b1d..305f9aee6 100644
--- a/internal/edgeguard/catalogue_test.go
+++ b/internal/edgeguard/catalogue_test.go
@@ -155,7 +155,7 @@ func TestParseAccepts(t *testing.T) {
// ever matches it, because a cool-down is about the client, not the request.
func TestBurstRuleLookups(t *testing.T) {
r := BurstRule
- if r.ID != "burst.probe-burst.cooldown" || r.Group != "probe-burst" || r.Tier != reqrec.TierBurst || r.Mode != ModeWatch {
+ if r.ID != "burst.probe-burst.cooldown" || r.Group != "probe-burst" || r.Tier != reqrec.TierBurst || r.Mode != ModeBlock {
t.Fatalf("BurstRule = %+v", *r)
}
if got, ok := RuleByID(r.ID); !ok || got != r {