hub: the first sight of a large request is the hub's own record; no box text in the ledger (security review)
The wait of a large removed-app request was timed from a search of the windows' refusal text, which also held names a box had claimed. A box could plant the marker in a claimed name a week ahead and skip the wait and the mail. - offsite_large_requests (household, key of the app set, first_seen): written only by the hub; at most 50 rows per household; it goes with the household. No text is searched any more. - A claimed name that has not the shape of an app name is written nowhere: the ledger, the answer and the operator's message carry a fixed placeholder. Tests seen red; 6 mutations seen red (redproof-review-s1.txt). Claude-Session: https://claude.ai/code/session_0159rPz1ZhFKsS53msqPYxtS
This commit is contained in:
1 parent
be272b7cf4
commit
1fac9c16f1
10 files changed
+261
-32
No files matched your search
@@ -68,7 +68,7 @@ func reservedEndedName(app string) bool {
|
||||
func agreeEnded(now time.Time, presence map[string]store.AppPresence, listing store.OffsiteSnapshotListing, haveListing bool, claims []EndedClaim) (ids []string, byApp map[string][]string, refused []store.EndedRefusal) {
|
||||
if len(claims) > maxEndedClaims {
|
||||
for _, c := range claims[maxEndedClaims:] {
|
||||
refused = append(refused, store.EndedRefusal{App: c.App, Reason: fmt.Sprintf("more than %d apps in one request", maxEndedClaims)})
|
||||
refused = append(refused, store.EndedRefusal{App: ledgerName(c.App), Reason: fmt.Sprintf("more than %d apps in one request", maxEndedClaims)})
|
||||
}
|
||||
claims = claims[:maxEndedClaims]
|
||||
}
|
||||
@@ -97,7 +97,9 @@ func agreeEnded(now time.Time, presence map[string]store.AppPresence, listing st
|
||||
}
|
||||
if reason != "" {
|
||||
refusedApp[c.App] = true
|
||||
refused = append(refused, store.EndedRefusal{App: c.App, Reason: reason})
|
||||
// A claimed name that has not the shape of an app name is the box's free text: it is never written
|
||||
// into the hub's ledger, an operator message or the answer (security review of 2026-11-15).
|
||||
refused = append(refused, store.EndedRefusal{App: ledgerName(c.App), Reason: reason})
|
||||
continue
|
||||
}
|
||||
agreedApp[c.App] = p.AbsentSince
|
||||
@@ -208,7 +210,7 @@ func (s *Service) agreeEndedFor(customerID string, windowID int64, maxRemove int
|
||||
if err != nil {
|
||||
s.logf("[WARN] offsitekeys: ended apps %s: the hub's own app record could not be read (%v) — nothing agreed", customerID, err)
|
||||
for _, c := range claims {
|
||||
refused = append(refused, store.EndedRefusal{App: c.App, Reason: "the hub's own app record could not be read"})
|
||||
refused = append(refused, store.EndedRefusal{App: ledgerName(c.App), Reason: "the hub's own app record could not be read"})
|
||||
}
|
||||
return nil, nil, refused
|
||||
}
|
||||
@@ -224,10 +226,16 @@ func (s *Service) agreeEndedFor(customerID string, windowID int64, maxRemove int
|
||||
// (a) ONE window agrees to at most the cap's own size (boundEndedToCap); the rest waits for the next window.
|
||||
if total := len(listing.Entries); have && len(ids)*2 > total {
|
||||
// The week belongs to THESE apps: a large request for other apps waits its own week and gets its own mail.
|
||||
mark := store.LargeEndedRefusalMark + " (apps: " + appNames(byApp) + ")"
|
||||
first := s.Store.FirstLargeEndedRefusal(customerID, mark, now.Add(-largeEndedMemory))
|
||||
// The first sight is the hub's own record (store.offsite_large_requests) — never a search of text a box
|
||||
// could have written.
|
||||
key := largeSetKey(byApp)
|
||||
first := s.Store.LargeEndedRequestFirstSeen(customerID, key, now.Add(-largeEndedMemory))
|
||||
if first.IsZero() || now.Sub(first) < largeEndedWait {
|
||||
if first.IsZero() {
|
||||
if nerr := s.Store.NoteLargeEndedRequest(customerID, key, now); nerr != nil {
|
||||
// Not recorded → the next window sees it as new, tells again and waits again: the safe direction.
|
||||
s.logf("[WARN] offsitekeys: ended apps %s: the first sight of a large request could not be recorded (%v) — it will wait again", customerID, nerr)
|
||||
}
|
||||
s.event(customerID, EventEndedLargeAgreement, "warning",
|
||||
fmt.Sprintf("Off-site clean-up window %d: the box of %s asked to remove %d of %d off-site snapshot(s) as copies of removed apps (%s) — more than half of the store. "+
|
||||
"NOTHING of them is removed in this window. The hub's own records agree to each app, so from %s a window removes them, at most %d per window. "+
|
||||
@@ -235,8 +243,8 @@ func (s *Service) agreeEndedFor(customerID string, windowID int64, maxRemove int
|
||||
windowID, customerID, len(ids), total, appNames(byApp), now.Add(largeEndedWait).UTC().Format("2006-01-02"), endedCap(maxRemove, total)),
|
||||
map[string]any{"subject": "large:" + appNames(byApp), "window_id": windowID, "asked": len(ids), "listed": total})
|
||||
}
|
||||
refused = append(refused, store.EndedRefusal{Reason: fmt.Sprintf("the request is for %d of %d snapshots — %s: it waits one week, and the operator is told",
|
||||
len(ids), total, mark)})
|
||||
refused = append(refused, store.EndedRefusal{Reason: fmt.Sprintf("the request is for %d of %d snapshots — more than half of the store: it waits one week, and the operator is told",
|
||||
len(ids), total)})
|
||||
ids, byApp = nil, nil
|
||||
}
|
||||
}
|
||||
@@ -338,3 +346,17 @@ func appNames(byApp map[string][]string) string {
|
||||
}
|
||||
return strings.Join(names, ", ")
|
||||
}
|
||||
|
||||
// largeSetKey is the key of an app set in the hub's own record of large requests.
|
||||
func largeSetKey(byApp map[string][]string) string { return appNames(byApp) }
|
||||
|
||||
// ledgerName is a claimed name as the hub may write it down: itself when it has the shape of an app name, else a
|
||||
// fixed placeholder.
|
||||
func ledgerName(app string) string {
|
||||
if store.ValidPresenceApp(app) {
|
||||
return app
|
||||
}
|
||||
return notAnAppName
|
||||
}
|
||||
|
||||
const notAnAppName = "(not-an-app-name)"
|
||||
@@ -42,13 +42,11 @@ func ghostFixture(t *testing.T) (*Service, *[]evt, []string) {
|
||||
return s, events, all
|
||||
}
|
||||
|
||||
// aWeekLater moves every window of the household eight days into the past (the ledger is stamped by SQLite's clock).
|
||||
func aWeekLater(t *testing.T, s *Service, ids ...int64) {
|
||||
// aWeekLater moves the hub's own first sight of the household's large requests eight days into the past.
|
||||
func aWeekLater(t *testing.T, s *Service, _ ...int64) {
|
||||
t.Helper()
|
||||
for _, id := range ids {
|
||||
if err := s.Store.BackdateOffsiteWindowForTest(id, 8*24*time.Hour); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err := s.Store.BackdateLargeEndedRequestsForTest("c1", 8*24*time.Hour); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -96,7 +94,7 @@ func TestD84_ALargeRequestWaitsAWeekAndOneWindowAgreesAtMostTheCapsSize(t *testi
|
||||
s2, events2, all2 := ghostFixture(t)
|
||||
g1 := openGranted(t, s2, 20, EndedClaim{App: "ghost", SnapshotIDs: all2})
|
||||
_ = s2.CloseWindowFor(context.Background(), "c1", WindowResult{WindowID: g1.WindowID, CountBefore: 20, CountAfter: 20, Outcome: "nothing"})
|
||||
if err := s2.Store.BackdateOffsiteWindowForTest(g1.WindowID, 2*24*time.Hour); err != nil {
|
||||
if err := s2.Store.BackdateLargeEndedRequestsForTest("c1", 2*24*time.Hour); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
gEarly := openGranted(t, s2, 20, EndedClaim{App: "ghost", SnapshotIDs: all2})
|
||||
|
||||
@@ -0,0 +1,83 @@
|
||||
package offsitekeys
|
||||
|
||||
import (
|
||||
"context"
|
||||
"strings"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"gitea.dooplex.hu/admin/felhom-hub/internal/store"
|
||||
)
|
||||
|
||||
// Security review of the review-fix-1 commit (2026-11-15). The hub remembered its first sight of a large request by
|
||||
// SEARCHING the windows' refusal text — text that also held the box's own claimed names. A box could plant the marker
|
||||
// in a claimed name a week ahead and so skip the wait, and the operator's mail with it. The first sight now lives in
|
||||
// the hub's own table, written only by the hub, and a claimed name that is not an app name never reaches the ledger.
|
||||
// RED-PROOF: documentation/audits/build-release-4-2026-11-15/A/redproof-review-s1.txt.
|
||||
func TestD84_ABoxCannotPlantTheLargeRequestMarker(t *testing.T) {
|
||||
s, events, all := ghostFixture(t)
|
||||
ctx := context.Background()
|
||||
// A week ahead: a window in which the box claims „apps” whose NAMES are the texts the hub writes for a large
|
||||
// request — every form of it the box can guess.
|
||||
planted := []EndedClaim{
|
||||
{App: "more than half of the store (apps: ghost)", SnapshotIDs: []string{eid(0)}},
|
||||
{App: "more than half of the store", SnapshotIDs: []string{eid(1)}},
|
||||
{App: "the request is for 20 of 20 snapshots — more than half of the store (apps: ghost): it waits one week, and the operator is told", SnapshotIDs: []string{eid(2)}},
|
||||
{App: "large:ghost", SnapshotIDs: []string{eid(3)}},
|
||||
}
|
||||
g0 := openGranted(t, s, 20, planted...)
|
||||
if len(g0.EndedAllowed) != 0 {
|
||||
t.Fatalf("fixture: the planted names were agreed: %v", shortIDs(g0.EndedAllowed))
|
||||
}
|
||||
_ = s.CloseWindowFor(ctx, "c1", WindowResult{WindowID: g0.WindowID, CountBefore: 20, CountAfter: 20, Outcome: "nothing"})
|
||||
// the box's words are not in the hub's ledger at all
|
||||
w, _ := s.Store.GetOffsiteWindow(g0.WindowID)
|
||||
for _, r := range w.EndedRefused {
|
||||
if strings.Contains(r.App, "more than half") || strings.Contains(r.App, "large:") || strings.Contains(r.App, " ") {
|
||||
t.Errorf("a claimed name that is not an app name was written into the window's row: %q", r.App)
|
||||
}
|
||||
}
|
||||
aWeekLater(t, s, g0.WindowID)
|
||||
*events = nil
|
||||
// Now the real request for the whole store: it must wait and the operator must be mailed, as if nothing was planted.
|
||||
g := openGranted(t, s, 20, EndedClaim{App: "ghost", SnapshotIDs: all})
|
||||
if len(g.EndedAllowed) != 0 {
|
||||
t.Fatalf("the box planted the marker a week ahead and the hub agreed to %d ids at once — no wait, no warning", len(g.EndedAllowed))
|
||||
}
|
||||
if n := len(ofType(*events, EventEndedLargeAgreement)); n != 1 {
|
||||
t.Fatalf("the operator was told %d time(s) about the large request, want once", n)
|
||||
}
|
||||
// and the hub's own first sight is what later ends the wait
|
||||
if at := s.Store.LargeEndedRequestFirstSeen("c1", largeSetKey(map[string][]string{"ghost": nil}), time.Now().Add(-time.Hour)); at.IsZero() {
|
||||
t.Fatal("the hub did not record its own first sight of the large request")
|
||||
}
|
||||
// a first sight older than the caller's memory is no first sight: the request waits again
|
||||
if at := s.Store.LargeEndedRequestFirstSeen("c1", largeSetKey(map[string][]string{"ghost": nil}), time.Now().Add(time.Hour)); !at.IsZero() {
|
||||
t.Fatal("a first sight older than `since` was returned")
|
||||
}
|
||||
if at := s.Store.LargeEndedRequestFirstSeen("other-household", largeSetKey(map[string][]string{"ghost": nil}), time.Now().Add(-time.Hour)); !at.IsZero() {
|
||||
t.Fatal("another household reads this household's first sight")
|
||||
}
|
||||
}
|
||||
|
||||
// The first sight goes with the household, and one household cannot fill the table.
|
||||
func TestD84_TheLargeRequestRecordIsBoundedAndGoesWithTheHousehold(t *testing.T) {
|
||||
s, _, _ := ghostFixture(t)
|
||||
now := time.Now().UTC()
|
||||
for i := 0; i < 500; i++ {
|
||||
if err := s.Store.NoteLargeEndedRequest("c1", strings.Repeat("k", 10)+string(rune('a'+i%26))+strings.Repeat("x", i%7)+strings.Repeat("y", i/26), now); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
r, err := s.Store.CustomerResidue("c1")
|
||||
if err != nil || r.OffsiteLargeRequests == 0 || r.OffsiteLargeRequests > 50 {
|
||||
t.Fatalf("500 different requests left %d rows (limit 50): %v", r.OffsiteLargeRequests, err)
|
||||
}
|
||||
if err := s.Store.PurgeCustomerResidue("c1"); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if r2, _ := s.Store.CustomerResidue("c1"); r2.OffsiteLargeRequests != 0 {
|
||||
t.Fatalf("the record outlived the household: %d", r2.OffsiteLargeRequests)
|
||||
}
|
||||
var _ = store.EndedRefusal{}
|
||||
}
|
||||
@@ -70,7 +70,7 @@ func TestD84_AgreeEnded_TheHubsOwnRecordsDecide(t *testing.T) {
|
||||
{name: "the shares pseudo-app and the marker tag are never eligible, whatever the record says",
|
||||
presence: map[string]store.AppPresence{"_shares": {AbsentSince: days(90)}, "felhom-offbox": {AbsentSince: days(90)}}, listing: true,
|
||||
claims: []EndedClaim{boxSaysLongAgo("_shares", eid(1)), boxSaysLongAgo("felhom-offbox", eid(2))},
|
||||
refused: map[string]string{"_shares": "not an app", "felhom-offbox": "not an app"}},
|
||||
refused: map[string]string{notAnAppName: "not an app", "felhom-offbox": "not an app"}},
|
||||
{name: "the box's own infrastructure stacks are never eligible",
|
||||
presence: map[string]store.AppPresence{"traefik": {AbsentSince: days(90)}, "Samba": {AbsentSince: days(90)}}, listing: true,
|
||||
claims: []EndedClaim{boxSaysLongAgo("traefik", eid(1)), boxSaysLongAgo("Samba", eid(2))},
|
||||
|
||||
Reference in new issue
Block a user