Hub v0.149.0: clamp a future deliberate-off time; hold a customer only when all its hosts are off (R-998)
gates / gates (push) Successful in 6m27s
gates / gates (push) Successful in 6m27s
Security review of 50e47e29: requested_at is the box's clock — a future value is cut to the hub's
now; CustomerDeliberatelyOff now needs every host of the customer held (one machine of two no
longer silences the other), and fails closed on a read error or no host. Both red-proofed.
This commit is contained in:
1 parent
50e47e29af
commit
a6acb0f762
5 files changed
+64
-14
No files matched your search
@@ -24,6 +24,12 @@ func (h *Handler) checkDeliberateOff(hostID, custID string, rep *hostReportPaylo
|
||||
return
|
||||
}
|
||||
t = t.UTC()
|
||||
// The time is the BOX's clock (security review 2026-10-13): a future value would stretch the hold past 14
|
||||
// days, so it is cut to the hub's own now. An earlier value only shortens the hold — the safe direction.
|
||||
if now := time.Now().UTC().Truncate(time.Second); t.After(now) {
|
||||
h.logger.Printf("[WARN] host-report from %s: deliberate_off.requested_at %s is in the future — using the hub's time", hostID, t.Format(time.RFC3339))
|
||||
t = now
|
||||
}
|
||||
at = &t
|
||||
}
|
||||
prev, err := h.store.SetHostDeliberateOff(hostID, at)
|
||||
|
||||
@@ -15,7 +15,8 @@ func TestHostReport_DeliberateOffSetThenCleared(t *testing.T) {
|
||||
h, st, _ := newTestHandler(t)
|
||||
st.SaveCustomerConfig(&store.CustomerConfig{CustomerID: "c1", APIKey: "ckey", RetrievalPassword: "p"})
|
||||
st.UpsertHost(&store.Host{HostID: "h1", CustomerID: "c1", APIKey: "HKEY"})
|
||||
withOff := strings.TrimSuffix(validReportBody("h1"), "}") + `,"deliberate_off":{"requested_at":"2026-10-13T18:00:00Z"}}`
|
||||
when := time.Now().UTC().Add(-time.Hour).Truncate(time.Second)
|
||||
withOff := strings.TrimSuffix(validReportBody("h1"), "}") + `,"deliberate_off":{"requested_at":"` + when.Format(time.RFC3339) + `"}}`
|
||||
|
||||
for i := 0; i < 2; i++ { // the field rides every report until the box is down; the second must not re-record
|
||||
if rr := do(h, http.MethodPost, "/host-report", "HKEY", withOff); rr.Code != 200 {
|
||||
@@ -23,8 +24,8 @@ func TestHostReport_DeliberateOffSetThenCleared(t *testing.T) {
|
||||
}
|
||||
}
|
||||
at := st.HostDeliberateOffAt("h1")
|
||||
if at == nil || !at.Equal(time.Date(2026, 10, 13, 18, 0, 0, 0, time.UTC)) {
|
||||
t.Fatalf("hold = %v, want 2026-10-13 18:00 UTC", at)
|
||||
if at == nil || !at.Equal(when) {
|
||||
t.Fatalf("hold = %v, want %v", at, when)
|
||||
}
|
||||
evs, _ := st.GetEventsByType("c1", eventHostDeliberateOff, time.Now().Add(-time.Hour))
|
||||
if len(evs) != 1 || evs[0].Severity != "info" {
|
||||
@@ -42,3 +43,18 @@ func TestHostReport_DeliberateOffSetThenCleared(t *testing.T) {
|
||||
t.Fatalf("ended events = %d, want 1", len(ended))
|
||||
}
|
||||
}
|
||||
|
||||
// A future requested_at (the box's clock) must not stretch the hold: it is cut to the hub's now.
|
||||
func TestHostReport_DeliberateOffFutureTimeClamped(t *testing.T) {
|
||||
h, st, _ := newTestHandler(t)
|
||||
st.SaveCustomerConfig(&store.CustomerConfig{CustomerID: "c1", APIKey: "ckey", RetrievalPassword: "p"})
|
||||
st.UpsertHost(&store.Host{HostID: "h1", CustomerID: "c1", APIKey: "HKEY"})
|
||||
body := strings.TrimSuffix(validReportBody("h1"), "}") + `,"deliberate_off":{"requested_at":"2099-01-01T00:00:00Z"}}`
|
||||
if rr := do(h, http.MethodPost, "/host-report", "HKEY", body); rr.Code != 200 {
|
||||
t.Fatalf("report: %d", rr.Code)
|
||||
}
|
||||
at := st.HostDeliberateOffAt("h1")
|
||||
if at == nil || at.After(time.Now().Add(time.Minute)) {
|
||||
t.Fatalf("hold anchored at %v — a future box time must be cut to the hub's now", at)
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user