carlos / platform Public

edge: write body-read refusals as constants; re-pin two guard censuses

readBoundedBody took its unreadable status as an int parameter, which
the #421 guard refuses as a status written from a variable. A login
bool now picks between constant 413 and 408 writes; same answers.

The record-write census gains a sec-h5-edge-availability layer
re-pinning Edge.maybeStore (Vary on the forwarded proof; still
nonrecord / sel:Put). The group-name producer inventory re-pins
Edge.Reload (replicaBodyProxy wrap; no name class).
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
claude agent, operated by paul@keymail.dev pushed by paul@keymail.dev 5a598b235073b5fe6f77eac43ce2847d439fb1f3 parent 2d49523
4 files changed, +50 −11
  • internal/edge/edge.go +12 −9
  • internal/host/group_names_test.go +6 −1
  • internal/provision/plan9_b8_census_test.go +1 −1
  • internal/provision/sec_h5_edge_availability_census_test.go +31 −0
diff --git a/internal/edge/edge.go b/internal/edge/edge.go
index 012562f86..ec59c6987 100644
--- a/internal/edge/edge.go
+++ b/internal/edge/edge.go
@@ -4292,8 +4292,9 @@ func isLoginPost(r *http.Request) bool {
// from Content-Length, which is only the client's claim (O4 round 1).
//
// It reads the body or answers on w and reports false. A body that did not
-// arrive whole in time, or broke off, is answered unreadable (413 for a
-// login, as every unreadable login body has been; 408 for the rest). Its
+// arrive whole in time, or broke off, is answered unreadable: 413 for a
+// login (login true), as every unreadable login body has been; 408 for the
+// rest. Its
// callers are readLoginBody, which ServeHTTP judges a login by, and
// bufferBody, which every hand-on that buffers goes through: a backhaul, a
// path hop, both HA forwards and a replica set. Nothing else in this
@@ -4314,7 +4315,7 @@ func isLoginPost(r *http.Request) bool {
// in the past: net/http tries to drain an unread body before it writes the
// answer, and that drain must fail at once rather than wait on the client
// again. The connection is closed after the answer.
-func (e *Edge) readBoundedBody(w http.ResponseWriter, r *http.Request, limit int64, unreadable int) ([]byte, bool) {
+func (e *Edge) readBoundedBody(w http.ResponseWriter, r *http.Request, limit int64, login bool) ([]byte, bool) {
rc := http.NewResponseController(w)
key := bodyClientKey(r)
if key != "" {
@@ -4335,12 +4336,14 @@ func (e *Edge) readBoundedBody(w http.ResponseWriter, r *http.Request, limit int
if err != nil {
_ = rc.SetReadDeadline(time.Now())
w.Header().Set("Connection", "close")
- status := unreadable
+ // Each answer is written with its constant code, so the #421
+ // guard sees every status this read can write (none is a 503).
var tooLarge *http.MaxBytesError
- if errors.As(err, &tooLarge) {
- status = http.StatusRequestEntityTooLarge
+ if login || errors.As(err, &tooLarge) {
+ http.Error(w, http.StatusText(http.StatusRequestEntityTooLarge), http.StatusRequestEntityTooLarge)
+ } else {
+ http.Error(w, http.StatusText(http.StatusRequestTimeout), http.StatusRequestTimeout)
}
- http.Error(w, http.StatusText(status), status)
return nil, false
}
if bounded {
@@ -4352,7 +4355,7 @@ func (e *Edge) readBoundedBody(w http.ResponseWriter, r *http.Request, limit int
// readLoginBody is readBoundedBody for a login POST's form, which ServeHTTP
// judges: at most gate.MaxFormBody, and 413 for any body it cannot read.
func (e *Edge) readLoginBody(w http.ResponseWriter, r *http.Request) ([]byte, bool) {
- return e.readBoundedBody(w, r, gate.MaxFormBody, http.StatusRequestEntityTooLarge)
+ return e.readBoundedBody(w, r, gate.MaxFormBody, true)
}
// bufferBody is the body admission of every request this edge hands to
@@ -4393,7 +4396,7 @@ func (e *Edge) bufferBody(w http.ResponseWriter, r *http.Request, replay bool) (
return &wholeBody{}, true
default:
var ok bool
- if b, ok = e.readBoundedBody(w, r, r.ContentLength, http.StatusRequestTimeout); !ok {
+ if b, ok = e.readBoundedBody(w, r, r.ContentLength, false); !ok {
return nil, false
}
if int64(len(b)) < r.ContentLength {
diff --git a/internal/host/group_names_test.go b/internal/host/group_names_test.go
index f1ebefda8..109922428 100644
--- a/internal/host/group_names_test.go
+++ b/internal/host/group_names_test.go
@@ -551,7 +551,12 @@ var groupNameProducerInventory = map[string]string{
// serve build the remote path map (buildRemotePaths), published with
// the hosts map as one routeTable; no entry is added to the hosts map,
// no name is derived or published; no name class (see above).
- "../edge/edge.go:*Edge.Reload": "ee8af16c5b4f89e6c41312796e76c4769118e68bc219b2ad77aa77007388b81b",
+ // sec-h5-edge-availability (H5-M5): an ArmReplica entry's proxy is
+ // wrapped in replicaBodyProxy, which takes a replayable request body
+ // whole under bufferBody's bounds before the same replica transport;
+ // the entry's host, arm and channel are unchanged, and no name is
+ // derived, published, renamed or routed anew; no name class.
+ "../edge/edge.go:*Edge.Reload": "677b36482f2a3118491db4be46ed11793e0f2809873ec476545eea3857fc0d16",
// Edge page cache slice 1: routeScope builds an in-memory upstream only to
// read the route's page scope (account, app, primary host). It publishes,
// registers and routes no name; no name class.
diff --git a/internal/provision/plan9_b8_census_test.go b/internal/provision/plan9_b8_census_test.go
index 504fc4c7e..436f64939 100644
--- a/internal/provision/plan9_b8_census_test.go
+++ b/internal/provision/plan9_b8_census_test.go
@@ -366,7 +366,7 @@ func TestPlan9B8RecordWriteCensus(t *testing.T) {
if len(got) < 100 {
t.Fatalf("census found only %d units under %s; the walk is broken", len(got), root)
}
- inventory := fleetFirstReconcileSpeed5WriteCensusInventory()
+ inventory := secH5EdgeAvailabilityWriteCensusInventory()
problems := append(censusDiff(inventory, got), censusPolicy(inventory)...)
if len(problems) > 0 {
t.Fatalf("record-write census rejected %d site(s); update the explicit inventory only after reviewing the source:\n %s", len(problems), strings.Join(problems, "\n "))
diff --git a/internal/provision/sec_h5_edge_availability_census_test.go b/internal/provision/sec_h5_edge_availability_census_test.go
new file mode 100644
index 000000000..a684d927d
--- /dev/null
+++ b/internal/provision/sec_h5_edge_availability_census_test.go
@@ -0,0 +1,31 @@
+package provision
+
+// secH5EdgeAvailabilityWriteCensusInventory is the record-write census for
+// branch sec-h5-edge-availability, layered on
+// fleetFirstReconcileSpeed5WriteCensusInventory (the inventory
+// TestPlan9B8RecordWriteCensus used before this branch). No record write is
+// added, moved or reclassified; one unit only re-digests:
+//
+// - internal/edge Edge.maybeStore: also returns early, storing nothing,
+// when the response varies on the forwarded proof header
+// (edgeproof.Header), which the edge signs afresh for every request, as
+// it already does for Vary: Cookie and Vary: *. Its one Put is still
+// e.cache.Put, the edge's in-memory response cache. nonrecord /
+// sel:Put, as before.
+func secH5EdgeAvailabilityWriteCensusInventory() []censusEntry {
+ entries := append([]censusEntry(nil), fleetFirstReconcileSpeed5WriteCensusInventory()...)
+ found := false
+ for i, e := range entries {
+ if e.File == "internal/edge/edge.go" && e.Unit == "Edge.maybeStore" {
+ if e.Class != "nonrecord" || e.Kinds != "sel:Put" {
+ panic("sec-h5-edge-availability re-pin changes the class or kinds of Edge.maybeStore")
+ }
+ entries[i].Digest = "f6a8b6bf4fe10586e573a190352dc88787bab6e780fa16ceb26181f6d6fe77a3"
+ found = true
+ }
+ }
+ if !found {
+ panic("sec-h5-edge-availability re-pin of an unlisted unit internal/edge/edge.go:Edge.maybeStore")
+ }
+ return entries
+}