diff --git a/README.md b/README.md index d22ac3da..98319e29 100644 --- a/README.md +++ b/README.md @@ -101,7 +101,7 @@ documents for different readers. can't run an agent (firewall, switch, UPS, iLO). One agent config, deployed identically everywhere. [How](docs/architecture.md#observability-data-flow) - **Dashboards and alerting as code.** 8 provisioned dashboards, 156 panels, and - 182 alert rules — 161 metric-based in Prometheus, 21 log-based in Loki — sharing + 183 alert rules — 161 metric-based in Prometheus, 22 log-based in Loki — sharing one Alertmanager routing tree. No dashboard exists only in a database. - **Secrets encrypted in-repo with SOPS + age.** Per-device credentials, decrypted at deploy time into gitignored paths, with `git log` showing which @@ -209,7 +209,7 @@ inbound passes may still reach it. Data flow and the maintained Mermaid topology │ ├── observability/ # the estate's stack on prometheus — ten services │ │ ├── prometheus/ # config, file_sd targets, 161 alert rules │ │ ├── alertmanager/ # routing and inhibition -│ │ ├── loki/ # single-binary config + 21 LogQL rules +│ │ ├── loki/ # single-binary config + 22 LogQL rules │ │ ├── alloy/ # the agent config directory, shipped to every host │ │ ├── snmp-exporter/ # generator.yaml is the source of truth │ │ └── grafana/ # provisioning + 8 dashboards diff --git a/docs/changelog.md b/docs/changelog.md index 61192a4b..fb94ad9f 100644 --- a/docs/changelog.md +++ b/docs/changelog.md @@ -46,6 +46,27 @@ docstring gives: it is a record, not a claim about now. the operator to *Configuration → UPS → General*, which does not have it. §3.8 and §6.5 send you back to 0.2, so the one fix corrects all three. +- **The SSD wear fix of 2026-11-13 did not fix it.** This corrects that day's + entry for the `prometheus` audit, which said a raw value outside 0–100 now + falls back to the normalised column. That change was deployed, and on + 2026-11-22 the collector still rendered `-78` for the Apple SSD SM256E. Its + figure therefore comes from `Wear_Leveling_Count` or + `Media_Wearout_Indicator`, whose normalised column was not range-checked + either. All three ATA wear spellings now drop a life-left value outside + 0–100. Which attribute the drive reports was not read, because `smartctl` + needs root. Until it is, the drive has no wear series and + `SmartDriveWearHigh` cannot fire for it. NVMe's `percentage_used` keeps its + meaning, which can exceed 100. +- **`SystemdUnitFailed`: a system unit failing twice in 48 hours now + warns.** A re-audit of `prometheus` found `logrotate` failing every night + since 2026-10-16 on both `prometheus` and `oracle`, seen by nothing. The + `cloud-init` and `cloud-init-base` packages each ship a rotation for the + same log. The audit of 2026-11-13 had read `systemctl --failed` as empty + minutes after a reboot, which clears that state. The rule reads PID 1's own + journal line, like `UnitOomKilled`. Run against the live store, it returned + exactly those two units. The duplicate config itself is fixed on each host, + not here. + ## 2026-11-22 - **The range on `gandalf` is built diff --git a/docs/observability.md b/docs/observability.md index 7f227af1..193825f3 100644 --- a/docs/observability.md +++ b/docs/observability.md @@ -352,7 +352,7 @@ separates a quiet stream from a stopped one. ## Alerting -182 rules in total: 161 metric-based in `prometheus/rules/`, and 21 log-based in +183 rules in total: 161 metric-based in `prometheus/rules/`, and 22 log-based in `loki/rules/`. ### Log-based (Loki ruler) @@ -363,6 +363,16 @@ covers SSH brute force, SSH accepted from outside VLAN 50/99, repeated sudo failures, user/group creation, kernel OOM kills, read-only remounts and disk I/O errors. +**`SystemdUnitFailed`** reads the same systemd verdict as `UnitOomKilled` +below, for any result but `oom-kill`, from PID 1's own stream. It fires when a +system unit fails at least twice in 48 hours. A single failure is not enough, +because most single failures are shutdown noise, which a log rule cannot tell +apart. `homelab-*` units are left to `ScheduledJobFailed`. It exists because +only `heimdall` exports `node_systemd_unit_state`, and nothing alerts on that +series anyway. On the hosts that ship their journal, a failing unit was seen by +nothing: `logrotate` failed nightly on `prometheus` and `oracle` from +2026-10-16 until the 2026-11-23 re-audit found it. + **OOM kills have four owners** ([#903](https://github.com/Gerrrt/HomeLab/issues/903), [#1095](https://github.com/Gerrrt/HomeLab/issues/1095)): - `KernelOomKill`: the machine-wide killer, read from the kernel's line. diff --git a/docs/security.md b/docs/security.md index f1bd74bd..3f45e6ba 100644 --- a/docs/security.md +++ b/docs/security.md @@ -33,7 +33,7 @@ What this network is actually built to survive: | A rooted range target reaching `gandalf` itself | **Dropped at `vmbr1`, before the host firewall, once applied.** The host has no address on the range bridge, but Linux answers ARP for its addresses on any interface and accepts a packet for them on any interface. So a target that adds an on-link route to `10.0.30.30` was reaching the host, and only the Proxmox firewall dropped it. Nothing watches that firewall on `gandalf`. A netdev `ingress` table on `vmbr1` now drops every frame the bridge passes up to the host, ARP included, without touching guest-to-guest traffic ([`build-the-playground.md`](runbooks/build-the-playground.md) §2, proved by §8 check four). Behind it, `gandalf` holds no estate credential, no GitHub login, no personal tooling and no third-party apt repository (§4, *Nothing else on `gandalf`*), so the host gives nothing beyond itself. The audits of 2026-11-13 and 2026-11-22 found credentials, then tooling and two third-party repositories. The credentials were gone by 2026-11-22. **The table and the tooling removal are not yet applied** | | Someone on Winterfell or Hicks logging in to `trinity` | **Key-only `sshd` since 2026-11-20; no host firewall by decision.** `trinity` holds the household's data and the sensitive tier's age key, and its `sshd` answers Hicks (by [ADR-0031](adr/0031-narrow-hicks-to-a-named-list-on-winterfell-and-leave-the-lab-open.md)'s list) and every host on VLAN 99, between which pfSense never filters. [`build-the-sensitive-tier-host.md`](runbooks/build-the-sensitive-tier-host.md) §3 now makes `sshd` key-only through a drop-in that outranks cloud-init's, refuses root and X11 forwarding, and keeps `authorized_keys` to `prometheus`'s key and Hicks's. The audit of 2026-11-13 found it taking passwords, with X11 forwarding on and 17 keys imported from GitHub. The step was applied on 2026-11-20: a password-only login is refused with `Permission denied (publickey)`, and three keys remain, `prometheus`'s, Hicks's and the operator's laptop, the last kept by decision. Agent sessions run on `trinity` as the operator, by decision ([ADR-0123](adr/0123-keep-agent-sessions-on-trinity.md)). `ufw` is installed and stays disabled, unlike `phoenix`'s ([ADR-0117](adr/0117-give-phoenix-a-key-only-sshd-and-a-default-deny-inbound-policy.md)): the other two ports `trinity` answers, `443` and `53`, are published by Docker, whose rules run ahead of `ufw`'s, so a policy would govern `22` alone, which the drop-in already closes to anything without a key. Nothing routes through `trinity`, and as the spare firewall a host policy is one more thing to get in the way the day it stands in for `morpheus`. What reaches `443` and `53` is set by pfSense and by the stack's bind addresses | | Someone with the trusted Wi-Fi key quietly joining | Kea's lease log reaches Loki; `UnknownDeviceOnTrustedSegment` fires the first time a MAC appears on VLAN 50 in seven days ([ADR-0019](adr/0019-read-device-joins-from-the-dhcp-server.md)) | -| Losing visibility of a failure | 182 alert rules, 30 days of metrics and logs | +| Losing visibility of a failure | 183 alert rules, 30 days of metrics and logs | | Someone on a reachable VLAN silencing an alert to hide a failure | Alertmanager binds to `127.0.0.1`; silences go through authenticated Grafana | | Mains power loss | **The rack, yes; the monitoring path, yes — on two laptop cells that were measured for the first time on 2026-09-12.** A pack fitted to `mjolnir` on 2026-08-28 passed its self-test; the TP-Link carrying `prometheus` and `oracle` has been on UPS power since 2026-09-08 ([#110](https://github.com/Gerrrt/HomeLab/issues/110)); the laptops ride a cut out on their own batteries, which `HostBatteryHealthLow` in `host.rules.yaml` now reads — `prometheus`'s cell was replaced on 2026-09-18 and reads 101 % of design, `oracle`'s was replaced on 2026-09-29 and reads 100 %, its design figure rather than a learned one ([#531](https://github.com/Gerrrt/HomeLab/issues/531)) — and **each runtime was measured once: `prometheus`'s on 2026-09-19, about 2.5 hours from full at the stack's load, and `oracle`'s on 2026-09-29, about 5.2 hours**; since the same day the projection is recorded on every cut and pages under thirty minutes (`HostBatteryRuntimeLow`, [#532](https://github.com/Gerrrt/HomeLab/issues/532)), but neither pack reports a moving cell temperature, so this row is answered for both hosts' runtime and for neither's cell temperature — see below. **What happens when the cut outlasts the pack is configured and accepted without a live test.** Since 2026-09-23 the firewall's NUT server reads `mjolnir`, and `Saruman` and `smaug` subscribe to it on their own gateway addresses, so a real cut would now try to run the sequence [ADR-0049](adr/0049-shut-down-on-the-ups-from-a-nut-server-on-the-firewall.md) decides: `Saruman` and `smaug` halt first and `morpheus` last. Since the move into the 32U rack on 2026-11-06 the PDU also carries `trinity`, `gandalf` (off until its build) and the console, with `smaug` racked and on the PDU directly rather than by its old long cord to the media room. [ADR-0107](adr/0107-subscribe-trinity-to-the-ups-and-bound-saruman-s-guest-stop.md) makes `trinity` a third subscriber and bounds `Saruman`'s guest stop. `Saruman`'s half was applied on 2026-11-13 (`down=90` on the four ordered guests, and its monitor stays logged in until they are down); `trinity`'s subscription, `HOSTSYNC 600` on `morpheus` and the card's 16-minute threshold followed on 2026-11-20, so all three subscribers would now halt before the pack empties; `gandalf`, the console and `neo` are left to the pack by decision. The pack itself is unmeasured: about 47 minutes at 21 % load is the card's own estimate. Neither the forced-shutdown proof nor a mains pull will be run ([ADR-0121](adr/0121-accept-the-ups-shutdown-without-a-live-test.md)) | | The estate being down while the person who runs it is unavailable | **Documentation, yes; data, no copy outside the house, by decision.** ADR-0011 puts the emergency tier on paper; [ADR-0023](adr/0023-keep-the-household-recovery-path-outside-the-estate.md) extends the same reasoning to the sensitive tier's data. That tier has held real photographs since 2026-09-28. [ADR-0122](adr/0122-drop-the-household-copy.md) dropped their copy outside the estate, so a loss of the house loses them — see below | diff --git a/scripts/collect-smart-state.sh b/scripts/collect-smart-state.sh index fbb6a4e3..2331a98e 100755 --- a/scripts/collect-smart-state.sh +++ b/scripts/collect-smart-state.sh @@ -403,6 +403,14 @@ for d in docs: # column, which starts at 100 and falls on every drive here that # carries it; if that is not a percent either, render nothing # rather than a number the rule would misread. + # + # That fix was not enough: on 2026-11-22 the same drive still + # rendered -78 from a collector that carried it, so its figure + # comes from one of the two branches below, whose normalised + # column is not range-checked either. Every ATA branch now drops a + # life-left outside 0-100 (the 2026-11-23 re-audit). Which + # attribute the Apple drive reports was not read: smartctl needs + # root. Until someone reads it, that drive has no wear series. life_left = None if raw is not None and 0 <= int(raw) <= 100: life_left = int(raw) @@ -418,8 +426,10 @@ for d in docs: # 100 and falls — and the raw column is not defined for it, unlike # the two spellings above. Same inversion, same metric, so # SmartDriveWearHigh reads this drive too (#483). + # Only a value in 0-100 is life left; see the note above + # percent_lifetime_remain. value = attr.get("value") - if value is not None: + if value is not None and 0 <= int(value) <= 100: add("homelab_smart_percentage_used", "Vendor estimate of endurance consumed, percent. 100 means the rated life is used.", plain, 100 - int(value)) @@ -435,8 +445,10 @@ for d in docs: # P440ar gave both SM863a a wear series from 177 — 6 % used on # cciss,2 and 4 % on cciss,3 — so the attribute does reach the # host through the controller. + # Only a value in 0-100 is life left; see the note above + # percent_lifetime_remain. value = attr.get("value") - if value is not None: + if value is not None and 0 <= int(value) <= 100: add("homelab_smart_percentage_used", "Vendor estimate of endurance consumed, percent. 100 means the rated life is used.", plain, 100 - int(value)) @@ -558,6 +570,16 @@ if ((SELF_TEST)); then check "no column in 0-100: no wear series, never a negative one" \ 0 '^homelab_smart_percentage_used' + # 3c. The same guard on the two normalised-column spellings. Whichever of + # them prometheus's Apple drive uses, a normalised 178 must render + # nothing, never -78. + for attr in Media_Wearout_Indicator Wear_Leveling_Count; do + payload='[{"device":{"name":"/dev/sda"},"model_name":"APPLE SSD SM256E","smart_status":{"passed":true},"ata_smart_attributes":{"table":[{"id":177,"name":"'"${attr}"'","value":178,"raw":{"value":0}}]}}]' + out="$(emit)" + check "${attr} out of 0-100: no wear series, never a negative one" \ + 0 '^homelab_smart_percentage_used' + done + # 4. morpheus's NVMe, the other vocabulary entirely. payload='[{"device":{"name":"/dev/nvme0"},"model_name":"NVME DRIVE","smart_status":{"passed":true},"temperature":{"current":62},"nvme_smart_health_information_log":{"percentage_used":3,"available_spare":100,"available_spare_threshold":10,"media_errors":0,"unsafe_shutdowns":41,"critical_warning":0}}]' out="$(emit)" diff --git a/stacks/observability/README.md b/stacks/observability/README.md index 40a594e1..ad059c3a 100644 --- a/stacks/observability/README.md +++ b/stacks/observability/README.md @@ -61,7 +61,7 @@ alertmanager/ alertmanager.yaml severity + category routing, inhibition loki/ loki-config.yaml single-binary, filesystem, 30-day retention - rules/*.rules.yaml 21 LogQL rules, security and watchdog, evaluated by Loki's ruler + rules/*.rules.yaml 22 LogQL rules, security and watchdog, evaluated by Loki's ruler alloy/ the agent config — Alloy loads the directory config.alloy every monitored host docker.alloy hosts with a Docker socket diff --git a/stacks/observability/loki/rules/security.rules.yaml b/stacks/observability/loki/rules/security.rules.yaml index 843b7c35..862313b4 100644 --- a/stacks/observability/loki/rules/security.rules.yaml +++ b/stacks/observability/loki/rules/security.rules.yaml @@ -337,6 +337,58 @@ groups: KernelOomKill also fired on this host, the whole machine ran out, not just the unit. + - alert: SystemdUnitFailed + # A system unit that keeps failing, on any host that ships its journal. + # Nothing else here saw one: only heimdall exports node_systemd_unit_state, + # and turning that collector on for the Alloy hosts would hand each + # Alloy container the system D-Bus socket. So logrotate failed every + # night on prometheus and oracle from 2026-10-16 to the 2026-11-23 + # re-audit, 36 runs, with no alert (cloud-init and cloud-init-base both + # ship a rotation for the same log). + # + # The line is UnitOomKilled's, from the same source and for the same + # reasons: PID 1 writes ": Failed with result ''." on the + # journal's native transport, so `logger` and a service's stdout cannot + # raise it. Unlike that rule, this one reads system units only, not a + # user's manager. + # + # TWICE IN 48 HOURS, NOT ONCE. Over the 14 days to 2026-11-23 most + # single failures were shutdown noise: snap mounts, apparmor, + # cryptsetup, finalrd and livepatch failing while a host went down. + # A log rule cannot tell a shutdown from normal running, and every + # real fault in that window repeated: logrotate daily, nut-monitor on + # trinity, suricata on oracle. So it fires when a unit fails at least + # twice in 48h. A daily job then fires within a day of its second + # failure. A service that dies once and stays down is missed; that is + # what EndpointUnreachable and the job alerts are for. + # + # LEFT TO OTHER RULES. 'oom-kill' is UnitOomKilled's. homelab-* units + # are the scheduled jobs, and ScheduledJobFailed already names them. + expr: | + sum by (host, failed_unit) ( + count_over_time( + {log_type="journal", transport="journal", unit="init.scope"} + |= "Failed with result" + !~ "^homelab-" + !~ "'oom-kill'" + | regexp "^(?P[^ :]+): Failed with result" + [48h] + ) + ) >= 2 + labels: + component: logs + severity: warning + category: correctness + annotations: + summary: "{{ $labels.host }}: {{ $labels.failed_unit }} failed {{ $value }} times in 48h" + description: >- + systemd reports that {{ $labels.failed_unit }} failed at least + twice in two days. `systemctl status {{ $labels.failed_unit }}` and + `journalctl -u {{ $labels.failed_unit }} -b` on {{ $labels.host }} + say why. If the unit comes from a package rather than this + repository, fix it on the host. If it is the repository's, fix it + through a PR. The alert clears 48h after the second-last failure. + - alert: FilesystemRemountedReadOnly expr: | sum by (host) ( diff --git a/stacks/observability/loki/tests/security.test.yaml b/stacks/observability/loki/tests/security.test.yaml index 0462f1d8..e214fe51 100644 --- a/stacks/observability/loki/tests/security.test.yaml +++ b/stacks/observability/loki/tests/security.test.yaml @@ -664,6 +664,73 @@ tests: shmem-rss:0kB, UID:1000 pgtables:1200kB oom_score_adj:0 expect: [] + # --- SystemdUnitFailed ------------------------------------------------------ + # The 2026-11-23 re-audit: logrotate failed every night on prometheus and + # oracle and nothing fired. The lines are the shape journalctl shows there. + # The rule looks back 48h, past the runner's gap, and three 48h windows + # would overrun what Loki accepts. So, like the new-device rules' MACs, each + # case uses unit names no other case in this file does. + # For the same reason the lines are hours old, not days: the 48h edge is + # Loki's range arithmetic, not this rule's, and is not tested here. + - alert: SystemdUnitFailed + name: a unit that fails twice in 48h fires, named from the line + isolated_by: failed_unit + streams: + - labels: {log_type: journal, host: prometheus, unit: init.scope, transport: journal} + entries: + - before: 3h + line: "logrotate.service: Failed with result 'exit-code'." + - before: 1h + line: "logrotate.service: Failed with result 'exit-code'." + expect: + - {host: prometheus, failed_unit: logrotate.service} + + - alert: SystemdUnitFailed + name: one failure, as at a shutdown, does not + isolated_by: failed_unit + streams: + - labels: {log_type: journal, host: trinity, unit: init.scope, transport: journal} + entries: + - before: 2h + line: "finalrd.service: Failed with result 'exit-code'." + - before: 2h + line: "systemd-cryptsetup@immich.service: Failed with result 'exit-code'." + expect: [] + + - alert: SystemdUnitFailed + name: scheduled jobs, OOM kills and other sources do not + isolated_by: failed_unit + streams: + # ScheduledJobFailed's. + - labels: {log_type: journal, host: prometheus, unit: init.scope, transport: journal} + entries: + - before: 3h + line: "homelab-silence-state.service: Failed with result 'exit-code'." + - before: 2h + line: "homelab-silence-state.service: Failed with result 'exit-code'." + # UnitOomKilled's. + - labels: {log_type: journal, host: oracle, unit: init.scope, transport: journal} + entries: + - before: 3h + line: "suricata.service: Failed with result 'oom-kill'." + - before: 2h + line: "suricata.service: Failed with result 'oom-kill'." + # `logger` from a login shell. + - labels: {log_type: journal, host: trinity, unit: session-4.scope, transport: syslog} + entries: + - before: 3h + line: "nut-monitor.service: Failed with result 'exit-code'." + - before: 2h + line: "nut-monitor.service: Failed with result 'exit-code'." + # A user's manager: system units only. + - labels: {log_type: journal, host: trinity, unit: user@1000.service, transport: journal} + entries: + - before: 3h + line: "run-p1.service: Failed with result 'exit-code'." + - before: 2h + line: "run-p1.service: Failed with result 'exit-code'." + expect: [] + # --- IoTAttemptedLateralMovement: more than 20 blocked IoT->internal in 10m - - alert: IoTAttemptedLateralMovement name: 21 blocked attempts from IoT to management fire