diff --git a/docs/changelog.md b/docs/changelog.md index a285f55c..52ad2cc4 100644 --- a/docs/changelog.md +++ b/docs/changelog.md @@ -19,6 +19,35 @@ 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 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 + 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. 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 + 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. - **The wall says when the dogs are due.** The last of the wall's five steps. - `wall_dogs.yaml` makes `sensor.wall_dogs`: when the dogs were last 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..9e1779cb 100644 --- a/stacks/lab/prometheus/rules/lab.rules.yaml +++ b/stacks/lab/prometheus/rules/lab.rules.yaml @@ -260,7 +260,14 @@ 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. 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 @@ -271,7 +278,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..e7a50f59 100644 --- a/stacks/observability/prometheus/rules/host.rules.yaml +++ b/stacks/observability/prometheus/rules/host.rules.yaml @@ -302,8 +302,25 @@ 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. + # + # 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[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 +331,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 +1018,12 @@ 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 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[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 +1034,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..b9cdb11c 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,12 +1842,41 @@ 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, and gone after two weeks - + # PatchStateStopped's long-gap case: with [1d] this cleared itself about + # 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"}' + 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 + 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. # Zero is a sample; absence is not.