hub (unreleased): a give-up mark keeps its slot for a week after the box stops listing the guest (the commit's security review); docs for the CA copy's changeover
gates / gates (push) Successful in 2m10s

Claude-Session: https://claude.ai/code/session_0159rPz1ZhFKsS53msqPYxtS
This commit is contained in:
admin committed 2026-11-14 19:20:46 +01:00
1 parent 78c08dc909
commit d2683b28d3
7 files changed
+82 -12

No files matched your search

+10 -5
View File
@@ -3313,6 +3313,9 @@ const guestPowerMaxEntries = 16
// guestPowerMaxMarks bounds how many give-up marks ONE box can hold in the hub's settings at a time.
const guestPowerMaxMarks = 8
// guestPowerMarkKeep: how long the mark of a guest the box stopped listing keeps its slot.
const guestPowerMarkKeep = 7 * 24 * time.Hour
func (h *Handler) noteSignedJobOutcome(hostID, jobID, outcome, reason, op string) {
switch outcome {
case "rejected", "failed", "malformed":
@@ -3380,20 +3383,22 @@ func (h *Handler) checkGuestPowerGaveUp(hostID, custID string, gave []hostGuestP
prefix := fmt.Sprintf("guest_power:%s:", hostID)
key := func(vmid int) string { return prefix + strconv.Itoa(vmid) }
// The marks this box has now. The report's own guest list is the BOX's word too, so „the report lists the guest”
// bounds nothing by itself (review, 2026-11-14): the number of marks per box is capped, and a mark for a guest the
// box no longer lists is dropped — a destroyed guest must not hold a mark, or a slot, for ever.
// bounds nothing by itself (review, 2026-11-14): one box holds at most guestPowerMaxMarks marks, and a mark for a
// guest the box no longer lists keeps its slot for guestPowerMarkKeep before it is dropped. So a box that invents
// new guests at every report gets guestPowerMaxMarks alarms in that time, not that many per report — each alarm
// is mailed (the mail cooldown is per guest). A destroyed guest's mark still goes, a week later.
raised := map[int]bool{}
for _, k := range h.store.OSAlarmKeys(prefix) {
vmid, err := strconv.Atoi(strings.TrimPrefix(k, prefix))
if err != nil {
continue
}
if !known[vmid] {
if !known[vmid] && time.Since(h.store.OSAlarmRaised(k)) > guestPowerMarkKeep {
_ = h.store.SetOSAlarmRaised(k, time.Time{})
h.logger.Printf("[INFO] host %s: guest %d is no longer reported — its give-up mark is dropped", hostID, vmid)
h.logger.Printf("[INFO] host %s: guest %d has not been reported for %s — its give-up mark is dropped", hostID, vmid, guestPowerMarkKeep)
continue
}
raised[vmid] = true
raised[vmid] = true // also a guest the box stopped listing, for guestPowerMarkKeep: its mark keeps its slot
}
for _, g := range gave {
if g.VMID <= 0 || !known[g.VMID] || running[g.VMID] || raised[g.VMID] {
+14 -4
View File
@@ -63,13 +63,23 @@ func TestGuestPowerGaveUp_ABoxCannotFillTheSettings(t *testing.T) {
t.Fatalf("round %d: %d give-up marks for one box, want at most %d", round, m, guestPowerMaxMarks)
}
}
if n := len(r1383Events(t, st, eventGuestPowerGaveUp)); n > 5*guestPowerMaxMarks {
t.Fatalf("%d events for five reports", n)
// five reports with 80 invented guests: at most guestPowerMaxMarks ALARMS in all — not that many per report. A box
// that drops a guest from its list does not get the slot back at once.
if n := len(r1383Events(t, st, eventGuestPowerGaveUp)); n > guestPowerMaxMarks {
t.Fatalf("%d alarms for five reports of invented guests, want at most %d", n, guestPowerMaxMarks)
}
// the box now reports only its real guest: the invented marks keep their slots for a week …
h.checkGuestPowerGaveUp("h1", "c1", nil, map[int]bool{100: true}, map[int]bool{100: true})
if marks() != guestPowerMaxMarks {
t.Fatalf("marks right after the box stopped listing the guests: %d, want %d (kept for %s)", marks(), guestPowerMaxMarks, guestPowerMarkKeep)
}
// … and are gone after it, rows and all
for _, k := range st.OSAlarmKeys("guest_power:h1:") {
_ = st.SetOSAlarmRaised(k, time.Now().Add(-guestPowerMarkKeep-time.Hour))
}
// the box now reports only its real guest: every invented mark is gone, and so is its row
h.checkGuestPowerGaveUp("h1", "c1", nil, map[int]bool{100: true}, map[int]bool{100: true})
if marks() != 0 || rows() != 0 {
t.Fatalf("marks for guests the box no longer lists: %d (rows %d), want 0", marks(), rows())
t.Fatalf("marks for guests the box has not listed for a week: %d (rows %d), want 0", marks(), rows())
}
// a cleared mark leaves no row at all
_ = st.SetOSAlarmRaised("probe:x", time.Now())