From cb17ae5aa95231f3ae7f3f279fb356cb82c77a3c Mon Sep 17 00:00:00 2001 From: Gerrrt Date: Thu, 19 Nov 2026 10:52:38 -0800 Subject: [PATCH 1/2] fix(alerts): stopped-collector rules hold for two weeks, not a day PatchStateStopped (estate and lab) and GuestStateStopped looked back [1d] offset 6h, so about 30 h after the last sample the "was reporting" side emptied and the alert resolved with nothing recovered. They now look back 14 days, inside both Prometheuses' retention. New promtool cases fire at 3 d and 10 d and are quiet at 16 d; with [1d] put back the 3 d and 10 d cases fail. The sensor runbook's sshd step also removes cloud-init's 50-cloud-init.conf, now removed on fenrir. The changelog records both, and that alexander's pending security updates are Ubuntu's phasing. Refs #1580 Co-Authored-By: Claude Opus 5.5 --- docs/changelog.md | 28 +++++++ docs/runbooks/build-the-sensor-guest.md | 11 ++- stacks/lab/prometheus/rules/lab.rules.yaml | 8 +- stacks/lab/prometheus/tests/lab.test.yaml | 48 +++++++++++ .../prometheus/rules/host.rules.yaml | 21 ++++- .../prometheus/tests/host.test.yaml | 80 ++++++++++++++++++- 6 files changed, 186 insertions(+), 10 deletions(-) diff --git a/docs/changelog.md b/docs/changelog.md index 63e93d15..3440ce8c 100644 --- a/docs/changelog.md +++ b/docs/changelog.md @@ -17,6 +17,34 @@ roadmap as it read that day, and the *Done* entries keep the shape they had there. `check_docs.py` does not check this file, for the reason its module docstring gives: it is a record, not a claim about now. +## 2026-11-19 + +- **`PatchStateStopped` and `GuestStateStopped` no longer clear themselves a + day after a collector stops.** Both asked "did this host report in the day + before the last six hours", so about 30 h after the last sample the left + side emptied and the alert resolved with nothing recovered. Review of the + lab's `ApplianceStateStopped` (#1580) found it in that rule, which had + copied the form. Both now look back fourteen days, inside both + Prometheuses' retention (30 d on the estate, 15 d in the lab), so they hold + for two weeks or until the host reports again, and a host that never had + the collector still stays quiet. A host retired on purpose now fires for + those two weeks. New promtool cases fire at 3 d and 10 d and are quiet at + 16 d; with `[1d]` put back, the 3 d and 10 d cases fail. +- **`SecurityUpdatesPending` went pending for `alexander`, and it is Ubuntu's + phasing.** Three security updates appeared at the 08:01 UTC collection: + `cloud-init`, `cloud-init-base` and `libgstreamer1.0-0`. `apt` lists all + three, with Docker's and others, as "deferred due to phasing": + `alexander` is outside the share of machines the rollout has reached, so + unattended-upgrades leaves them, as it should. Nothing was forced. The rule + fires only if they are still pending a week later. +- **`fenrir`'s cloud-init `sshd` drop-in is removed.** + `50-cloud-init.conf`, 27 bytes reading `PasswordAuthentication yes`, had + been overridden since 2026-11-17 by the `10-homelab.conf` drop-in, which + `sshd` reads first. It was still what an audit without sudo would see, so + `build-the-sensor-guest.md` §3 now removes it and checks that only the + `10-` drop-in is left. cloud-init writes it once per instance; on `fenrir` + it had kept its install date across four reboots. + ## 2026-11-18 - **The wall's context card gets its sources.** The third of the wall's diff --git a/docs/runbooks/build-the-sensor-guest.md b/docs/runbooks/build-the-sensor-guest.md index a5bedf01..fa872ade 100644 --- a/docs/runbooks/build-the-sensor-guest.md +++ b/docs/runbooks/build-the-sensor-guest.md @@ -302,7 +302,12 @@ who reaches that port. The installer leaves `/etc/ssh/sshd_config.d/50-cloud-init.conf` behind, and that file can set `PasswordAuthentication yes`. `sshd` keeps the **first** value it reads for each setting, and drop-ins are read in name order, so this file is `10-` -to come before cloud-init's: +to come before cloud-init's. Then remove cloud-init's file as well. The `10-` +drop-in already outranks it, but a 27-byte file that reads +`PasswordAuthentication yes` is what the audit of 2026-11-13 had to guess +from without sudo, and it is the first thing the next one would flag. +cloud-init writes it once per instance, not at each boot: on `fenrir` it kept +its install date across four reboots, so it stays gone. ```bash sudo tee /etc/ssh/sshd_config.d/10-homelab.conf >/dev/null <<'SSHD' @@ -316,11 +321,13 @@ X11Forwarding no AllowUsers atreus SSHD sudo chmod 644 /etc/ssh/sshd_config.d/10-homelab.conf +sudo rm -f /etc/ssh/sshd_config.d/50-cloud-init.conf sudo sshd -t && sudo systemctl reload ssh sudo sshd -T | grep -E '^(passwordauthentication|kbdinteractiveauthentication|permitrootlogin|x11forwarding|allowusers) ' ``` -All five must read `no`, apart from `allowusers atreus`. **Keep the session +All five must read `no`, apart from `allowusers atreus`, and +`ls /etc/ssh/sshd_config.d/` must list only `10-homelab.conf`. **Keep the session you ran this from open**, and log in from a second terminal before you close it. If that login fails, VM 190's console in the Proxmox web UI is the way back in. The VM has no serial port, so `qm terminal 190` is not. diff --git a/stacks/lab/prometheus/rules/lab.rules.yaml b/stacks/lab/prometheus/rules/lab.rules.yaml index 4277dde9..6af74540 100644 --- a/stacks/lab/prometheus/rules/lab.rules.yaml +++ b/stacks/lab/prometheus/rules/lab.rules.yaml @@ -260,7 +260,11 @@ groups: # healthiest. Two ways to stop, so two branches: # # - The series vanished: Alloy or the textfile directory went. Stopped, - # not missing, so a guest without the timer is not an alert. + # not missing, so a guest without the timer is not an alert. Fourteen + # days of memory, not one, inside this Prometheus's 15d retention: with + # [1d] the alert cleared itself about 30h after the last sample, with + # nothing recovered (review of ApplianceStateStopped, #1580). A guest + # retired on purpose fires for two weeks; silence it when it goes. # - The file stopped being rewritten. A collector that dies leaves # apt-patch-state.prom in place and Alloy re-serves its last values on # every scrape, so the series never goes absent and the first branch @@ -271,7 +275,7 @@ groups: - alert: PatchStateStopped expr: >- ( - count by (host) (present_over_time(homelab_apt_upgrades_pending[1d] offset 6h)) + count by (host) (present_over_time(homelab_apt_upgrades_pending[14d] offset 6h)) unless count by (host) (present_over_time(homelab_apt_upgrades_pending[6h])) ) diff --git a/stacks/lab/prometheus/tests/lab.test.yaml b/stacks/lab/prometheus/tests/lab.test.yaml index a2a3dade..30a8e49c 100644 --- a/stacks/lab/prometheus/tests/lab.test.yaml +++ b/stacks/lab/prometheus/tests/lab.test.yaml @@ -875,6 +875,54 @@ tests: /var/lib/node_exporter/textfile_collector/apt-patch-state.prom is being written and is world-readable. + # --- PatchStateStopped: still firing days later, and gone after two weeks - + # Review of #1580: with [1d] this cleared itself about 30h after the + # collector stopped. Twenty hours of reporting, then 15.5 days of gap. + # Still firing at 3d and 10d; quiet at 16d, past the [14d] window and its + # offset, which is the documented end. + - interval: 1h + input_series: + - series: 'homelab_apt_upgrades_pending{host="odin"}' + values: "3x20 _x380" + alert_rule_test: + - eval_time: 3d + alertname: PatchStateStopped + exp_alerts: + - exp_labels: + host: odin + component: host + severity: warning + category: security + exp_annotations: + summary: "odin has stopped reporting patch state" + description: >- + Its patch state has gone absent, or apt-patch-state.prom has not + been rewritten in two days, so SecurityUpdatesPending and + RebootRequired are reading stale or no data for it. Check + `systemctl status homelab-patch-state.timer` on the guest, and that + /var/lib/node_exporter/textfile_collector/apt-patch-state.prom is + being written and is world-readable. + - eval_time: 10d + alertname: PatchStateStopped + exp_alerts: + - exp_labels: + host: odin + component: host + severity: warning + category: security + exp_annotations: + summary: "odin has stopped reporting patch state" + description: >- + Its patch state has gone absent, or apt-patch-state.prom has not + been rewritten in two days, so SecurityUpdatesPending and + RebootRequired are reading stale or no data for it. Check + `systemctl status homelab-patch-state.timer` on the guest, and that + /var/lib/node_exporter/textfile_collector/apt-patch-state.prom is + being written and is world-readable. + - eval_time: 16d + alertname: PatchStateStopped + exp_alerts: [] + # --- PatchStateStopped: quiet for a guest that reports zero ---------------- - interval: 5m input_series: diff --git a/stacks/observability/prometheus/rules/host.rules.yaml b/stacks/observability/prometheus/rules/host.rules.yaml index 7d05b931..793265af 100644 --- a/stacks/observability/prometheus/rules/host.rules.yaml +++ b/stacks/observability/prometheus/rules/host.rules.yaml @@ -302,8 +302,19 @@ groups: # continuously and not once a day. Six hours survives a Prometheus # restart and a host rebooting, which is the same window # deploy.rules.yaml and backup.rules.yaml settled on. + # + # FOURTEEN DAYS OF MEMORY, NOT ONE. With [1d] the left side empties + # about 30h after the last sample, and the alert cleared itself with + # nothing recovered: a host down for a long weekend came back to no + # record that it had gone quiet. Found in review of the lab's + # ApplianceStateStopped (#1580), which had copied this form. Fourteen + # days sits inside both Prometheuses' retention (30d here, 15d in the + # lab), so the alert holds for two weeks or until the host reports + # again. A host retired on purpose fires for those two weeks; silence + # it when it goes. The cost is a 14d range per host each evaluation, + # one series per host, which this estate's handful of hosts can carry. expr: >- - count by (host) (present_over_time(homelab_apt_upgrades_pending[1d] offset 6h)) + count by (host) (present_over_time(homelab_apt_upgrades_pending[14d] offset 6h)) unless count by (host) (present_over_time(homelab_apt_upgrades_pending[6h])) for: 30m @@ -314,7 +325,7 @@ groups: annotations: summary: "{{ $labels.host }} has stopped reporting patch state" description: >- - It reported within the last day and has not in six hours, so + It reported within the last two weeks and has not in six hours, so SecurityUpdatesPending and RebootRequired are both blind to this host until it comes back. Check homelab-patch-state.timer on the host — `systemctl status homelab-patch-state.timer` — and that @@ -1001,8 +1012,10 @@ groups: # # Stopped, not missing: a hypervisor that never had the collector # installed must stay quiet, or every host without it alerts forever. + # Fourteen days of memory, for PatchStateStopped's reason: with [1d] + # the alert cleared itself about 30h after the collector stopped. expr: >- - count by (host) (present_over_time(homelab_guests_total[1d] offset 6h)) + count by (host) (present_over_time(homelab_guests_total[14d] offset 6h)) unless count by (host) (present_over_time(homelab_guests_total[6h])) for: 30m @@ -1013,7 +1026,7 @@ groups: annotations: summary: "{{ $labels.host }} has stopped reporting its guests" description: >- - It reported within the last day and has not in six hours, so + It reported within the last two weeks and has not in six hours, so HypervisorGuestStopped is blind to this hypervisor until it comes back. Check homelab-guest-state.timer on the host and that /var/lib/node_exporter/textfile_collector/guest-state.prom is being diff --git a/stacks/observability/prometheus/tests/host.test.yaml b/stacks/observability/prometheus/tests/host.test.yaml index 261d7207..66a4bf89 100644 --- a/stacks/observability/prometheus/tests/host.test.yaml +++ b/stacks/observability/prometheus/tests/host.test.yaml @@ -716,7 +716,7 @@ tests: exp_annotations: summary: "oracle has stopped reporting patch state" description: >- - It reported within the last day and has not in six hours, so + It reported within the last two weeks and has not in six hours, so SecurityUpdatesPending and RebootRequired are both blind to this host until it comes back. Check homelab-patch-state.timer on the host — `systemctl status homelab-patch-state.timer` — and that @@ -724,6 +724,57 @@ tests: being written and is world-readable. A 0600 file is invisible to the collector and produces exactly this silence. + # --- PatchStateStopped: still firing days later, and gone after two weeks - + # The case review of #1580 found: with [1d] the alert cleared itself about + # 30h after the collector stopped, with nothing recovered. Twenty hours of + # reporting, then 15.5 days of gap (the [14d] window plus its 6h offset and + # a day to spare). Still firing at 3d and 10d; quiet at 16d, once the last + # sample has aged out of the window, which is the documented end. + - interval: 1h + input_series: + - series: 'homelab_apt_upgrades_pending{host="oracle"}' + values: "3x20 _x380" + alert_rule_test: + - eval_time: 3d + alertname: PatchStateStopped + exp_alerts: + - exp_labels: + host: oracle + component: host + severity: warning + category: security + exp_annotations: + summary: "oracle has stopped reporting patch state" + description: >- + It reported within the last two weeks and has not in six hours, so + SecurityUpdatesPending and RebootRequired are both blind to this + host until it comes back. Check homelab-patch-state.timer on the + host — `systemctl status homelab-patch-state.timer` — and that + /var/lib/node_exporter/textfile_collector/apt-patch-state.prom is + being written and is world-readable. A 0600 file is invisible to + the collector and produces exactly this silence. + - eval_time: 10d + alertname: PatchStateStopped + exp_alerts: + - exp_labels: + host: oracle + component: host + severity: warning + category: security + exp_annotations: + summary: "oracle has stopped reporting patch state" + description: >- + It reported within the last two weeks and has not in six hours, so + SecurityUpdatesPending and RebootRequired are both blind to this + host until it comes back. Check homelab-patch-state.timer on the + host — `systemctl status homelab-patch-state.timer` — and that + /var/lib/node_exporter/textfile_collector/apt-patch-state.prom is + being written and is world-readable. A 0600 file is invisible to + the collector and produces exactly this silence. + - eval_time: 16d + alertname: PatchStateStopped + exp_alerts: [] + # --- PatchStateStopped: quiet for a host that reports zero ----------------- # The whole point of the rule. A host with nothing to report and a host whose # collector died look identical in SecurityUpdatesPending and RebootRequired, @@ -1791,7 +1842,32 @@ tests: exp_annotations: summary: "Saruman has stopped reporting its guests" description: >- - It reported within the last day and has not in six hours, so + It reported within the last two weeks and has not in six hours, so + HypervisorGuestStopped is blind to this hypervisor until it + comes back. Check homelab-guest-state.timer on the host and that + /var/lib/node_exporter/textfile_collector/guest-state.prom is + being written and is world-readable. + + # --- GuestStateStopped: still firing days later ------------------------- + # PatchStateStopped's long-gap case: with [1d] this cleared itself about + # 30h after the collector stopped. Still firing at 10d. + - interval: 1h + input_series: + - series: 'homelab_guests_total{host="Saruman"}' + values: "1x20 _x380" + alert_rule_test: + - eval_time: 10d + alertname: GuestStateStopped + exp_alerts: + - exp_labels: + host: Saruman + component: host + severity: warning + category: availability + exp_annotations: + summary: "Saruman has stopped reporting its guests" + description: >- + It reported within the last two weeks and has not in six hours, so HypervisorGuestStopped is blind to this hypervisor until it comes back. Check homelab-guest-state.timer on the host and that /var/lib/node_exporter/textfile_collector/guest-state.prom is From 35dfe41eebd472df58d8386c244e1fa1badd80ba Mon Sep 17 00:00:00 2001 From: Gerrrt Date: Thu, 19 Nov 2026 11:09:15 -0800 Subject: [PATCH 2/2] fix(alerts): say what the 14-day stopped rules cannot see Review on #1585: - The estate's PatchStateStopped and GuestStateStopped see a series vanish, not a timer that stops and leaves its .prom file, which is re-served on every scrape. The rule comments and changelog now say so; the lab's copy has an mtime branch, the estate's do not yet. - The lab has no Alertmanager (ADR-0020), so its rule comment no longer says to silence a retired guest. - GuestStateStopped's long-gap test now also asserts quiet at 16 d. Co-Authored-By: Claude Opus 5.5 --- docs/changelog.md | 8 ++++++-- stacks/lab/prometheus/rules/lab.rules.yaml | 5 ++++- stacks/observability/prometheus/rules/host.rules.yaml | 10 +++++++++- stacks/observability/prometheus/tests/host.test.yaml | 8 ++++++-- 4 files changed, 25 insertions(+), 6 deletions(-) diff --git a/docs/changelog.md b/docs/changelog.md index bc9a8cb9..9e5019b0 100644 --- a/docs/changelog.md +++ b/docs/changelog.md @@ -20,7 +20,7 @@ docstring gives: it is a record, not a claim about now. ## 2026-11-19 - **`PatchStateStopped` and `GuestStateStopped` no longer clear themselves a - day after a collector stops.** Both asked "did this host report in the day + day after a host's series disappears.** Both asked "did this host report in the day before the last six hours", so about 30 h after the last sample the left side emptied and the alert resolved with nothing recovered. Review of the lab's `ApplianceStateStopped` (#1580) found it in that rule, which had @@ -29,7 +29,11 @@ docstring gives: it is a record, not a claim about now. for two weeks or until the host reports again, and a host that never had the collector still stays quiet. A host retired on purpose now fires for those two weeks. New promtool cases fire at 3 d and 10 d and are quiet at - 16 d; with `[1d]` put back, the 3 d and 10 d cases fail. + 16 d; with `[1d]` put back, the 3 d and 10 d cases fail. This covers a + series that vanishes, not a timer that stops: a stopped timer leaves its + `.prom` file, which is re-served on every scrape, so the series stays. The + lab's `PatchStateStopped` has a second branch on the file's age for that; + the two estate rules do not yet. - **`SecurityUpdatesPending` went pending for `alexander`, and it is Ubuntu's phasing.** Three security updates appeared at the 08:01 UTC collection: `cloud-init`, `cloud-init-base` and `libgstreamer1.0-0`. `apt` lists all diff --git a/stacks/lab/prometheus/rules/lab.rules.yaml b/stacks/lab/prometheus/rules/lab.rules.yaml index 6af74540..9e1779cb 100644 --- a/stacks/lab/prometheus/rules/lab.rules.yaml +++ b/stacks/lab/prometheus/rules/lab.rules.yaml @@ -264,7 +264,10 @@ groups: # days of memory, not one, inside this Prometheus's 15d retention: with # [1d] the alert cleared itself about 30h after the last sample, with # nothing recovered (review of ApplianceStateStopped, #1580). A guest - # retired on purpose fires for two weeks; silence it when it goes. + # retired on purpose fires for two weeks. This stack has no + # Alertmanager (ADR-0020), so there is nothing to silence: it shows in + # this Prometheus's /alerts and in Grafana until it ages out, and is + # expected there. # - The file stopped being rewritten. A collector that dies leaves # apt-patch-state.prom in place and Alloy re-serves its last values on # every scrape, so the series never goes absent and the first branch diff --git a/stacks/observability/prometheus/rules/host.rules.yaml b/stacks/observability/prometheus/rules/host.rules.yaml index 793265af..e7a50f59 100644 --- a/stacks/observability/prometheus/rules/host.rules.yaml +++ b/stacks/observability/prometheus/rules/host.rules.yaml @@ -313,6 +313,12 @@ groups: # again. A host retired on purpose fires for those two weeks; silence # it when it goes. The cost is a 14d range per host each evaluation, # one series per host, which this estate's handful of hosts can carry. + # + # WHAT THIS DOES NOT SEE: a timer that stops but leaves its file. The + # file stays in the textfile directory and is re-served on every + # scrape, so the series never goes absent. The lab's copy of this rule + # has a second branch on node_textfile_mtime_seconds for that; this + # one does not yet. expr: >- count by (host) (present_over_time(homelab_apt_upgrades_pending[14d] offset 6h)) unless @@ -1013,7 +1019,9 @@ groups: # Stopped, not missing: a hypervisor that never had the collector # installed must stay quiet, or every host without it alerts forever. # Fourteen days of memory, for PatchStateStopped's reason: with [1d] - # the alert cleared itself about 30h after the collector stopped. + # the alert cleared itself about 30h after the series went. Like + # PatchStateStopped it sees the series vanish, not a timer that stops + # and leaves guest-state.prom in place. expr: >- count by (host) (present_over_time(homelab_guests_total[14d] offset 6h)) unless diff --git a/stacks/observability/prometheus/tests/host.test.yaml b/stacks/observability/prometheus/tests/host.test.yaml index 66a4bf89..b9cdb11c 100644 --- a/stacks/observability/prometheus/tests/host.test.yaml +++ b/stacks/observability/prometheus/tests/host.test.yaml @@ -1848,9 +1848,10 @@ tests: /var/lib/node_exporter/textfile_collector/guest-state.prom is being written and is world-readable. - # --- GuestStateStopped: still firing days later ------------------------- + # --- GuestStateStopped: still firing days later, and gone after two weeks - # PatchStateStopped's long-gap case: with [1d] this cleared itself about - # 30h after the collector stopped. Still firing at 10d. + # 30h after the series went. Still firing at 10d; quiet at 16d, so the + # lookback is bounded and a retired hypervisor stops alerting. - interval: 1h input_series: - series: 'homelab_guests_total{host="Saruman"}' @@ -1872,6 +1873,9 @@ tests: comes back. Check homelab-guest-state.timer on the host and that /var/lib/node_exporter/textfile_collector/guest-state.prom is being written and is world-readable. + - eval_time: 16d + alertname: GuestStateStopped + exp_alerts: [] # --- GuestStateStopped: quiet for a hypervisor reporting zero guests ------ # The case that makes this rule necessary AND the case it must not fire on.