From bd8bfaa5570e9978af16edd12ecf4fff356cffbe Mon Sep 17 00:00:00 2001 From: Garrett Allen <98648590+Gerrrt@users.noreply.github.com> Date: Mon, 23 Nov 2026 18:32:42 +0000 Subject: [PATCH 1/2] feat(logs): relay neo's log through morpheus, and keep it out of the firewall's alerts (ADR-0127) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit syslog.alloy stores a line as host="neo" only when it arrives on morpheus's pinned connection with hostname neo, and gives it a fixed app="routeros" so no tag on that path reads as filterlog, Suricata or Kea. The firewall's Loki selectors also require host="morpheus". Two rules read the new stream: SwitchLoginFromUnexpectedSource and SwitchLogsStopped, the second against a five-minute heartbeat because Home Assistant's logins came once in four hours. ship-firewall-logs.md §3 now describes the syslog-ng config that runs, whose generated source cannot take flags(no-hostname), and §10 is the neo procedure. restore-the-firewall.md checks both streams come back. ADR-0127 is accepted, and README's ADR count is corrected to 127. Refs #1659 Co-Authored-By: Claude Opus 5.5 --- README.md | 8 +- .../0127-relay-neos-log-through-morpheus.md | 16 +- docs/architecture.md | 6 +- docs/changelog.md | 24 +++ docs/firewall-claims.yaml | 4 +- docs/network.md | 12 +- docs/observability.md | 10 +- docs/runbooks/respond-to-a-security-alert.md | 23 +++ docs/runbooks/restore-the-firewall.md | 18 +++ docs/runbooks/ship-firewall-logs.md | 143 ++++++++++++++++-- docs/security.md | 8 +- scripts/check_syslog_senders.sh | 87 +++++++++-- stacks/observability/README.md | 2 +- stacks/observability/alloy/syslog.alloy | 53 ++++++- .../loki/rules/security.rules.yaml | 111 ++++++++++++-- .../loki/tests/security.test.yaml | 93 +++++++++++- 16 files changed, 547 insertions(+), 71 deletions(-) diff --git a/README.md b/README.md index 70354c69e..4fe24b963 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 - 192 alert rules — 166 metric-based in Prometheus, 26 log-based in Loki — sharing + 194 alert rules — 166 metric-based in Prometheus, 28 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 @@ -136,7 +136,7 @@ documents for different readers. at all. Every pinned digest is also scanned weekly for fixable HIGH and CRITICAL CVEs, and each image with findings has an open issue until a scan finds it clean. -- **Documented decisions and runbooks.** 126 ADRs covering what was chosen +- **Documented decisions and runbooks.** 127 ADRs covering what was chosen and what was rejected — including the costs accepted knowingly; 53 runbooks for the operations that are easy to get wrong at 1am, one of which is the handover page a successor reads first. Every critical alert links to @@ -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, 166 alert rules │ │ ├── alertmanager/ # routing and inhibition -│ │ ├── loki/ # single-binary config + 26 LogQL rules +│ │ ├── loki/ # single-binary config + 28 LogQL rules │ │ ├── alloy/ # the agent config directory, shipped to every host │ │ ├── snmp-exporter/ # generator.yaml is the source of truth │ │ └── grafana/ # provisioning + 8 dashboards @@ -236,7 +236,7 @@ inbound passes may still reach it. Data flow and the maintained Mermaid topology │ ├── architecture.md network.md hardware.md │ ├── observability.md security.md roadmap.md changelog.md │ ├── diagrams/ # the network diagram (SVG) and its predecessors -│ ├── adr/ # 126 ADRs — architecture decision records +│ ├── adr/ # 127 ADRs — architecture decision records │ ├── exercises/ # purple-team exercise records — see its README │ └── runbooks/ # 53 runbooks; successor-handover.md is the front door └── Makefile # make help diff --git a/docs/adr/0127-relay-neos-log-through-morpheus.md b/docs/adr/0127-relay-neos-log-through-morpheus.md index e365f9c00..3cb6c0181 100644 --- a/docs/adr/0127-relay-neos-log-through-morpheus.md +++ b/docs/adr/0127-relay-neos-log-through-morpheus.md @@ -1,6 +1,6 @@ # ADR-0127: Relay `neo`'s log through `morpheus` -**Status:** Proposed · 2026-11 +**Status:** Accepted · 2026-11 ## Context @@ -86,9 +86,11 @@ the cases pass. `syslog.alloy` refuses the message's own hostname, because before #844 any sender could write `host="morpheus"` with it. That reasoning still holds for what senders write. Here the hostname is written by `morpheus`'s syslog-ng, -not by the sender: `flags(no-hostname)` on both sources means syslog-ng never -reads a hostname out of an incoming line, and only the rewrite on the `neo` -path sets one. To get `host="neo"` onto a line, a forger would have to deliver +not by the sender. The `neo` source takes `flags(no-hostname)`, so it never +reads one from an incoming line, and a rewrite sets `neo`. pfSense's own +source is generated by the package and cannot take that flag, so its log path +gets a rewrite of its own that sets `morpheus`. Each path writes its own name, +and only the `neo` path can write `neo`. To get `host="neo"` onto a line, a forger would have to deliver it over the pinned TLS connection, which only `morpheus` holds. ### Why the UDP hop is acceptable @@ -147,8 +149,10 @@ segment the firewall does not stand between. This hop is different: - **Alerting becomes possible, and is a separate change.** The applying PR should add two Loki rules: - an `account` login from anywhere but the switch LAN and desktop-02; - - an absence rule on `host="neo"`. Home Assistant's API logins give the - stream a steady heartbeat, so silence means the path is broken. + - an absence rule on `host="neo"`. Home Assistant's API logins were + expected to give the stream a heartbeat, but on 2026-11-23 they came once + in four hours. So `neo` logs a line every five minutes from a scheduler + entry, and silence means the path is broken. `scripts/check_syslog_senders.sh` gains cases proving that: - a line from `10.0.99.1` with hostname `neo` gets `host="neo"`; diff --git a/docs/architecture.md b/docs/architecture.md index 5e5c2a2eb..761289f6b 100644 --- a/docs/architecture.md +++ b/docs/architecture.md @@ -101,8 +101,10 @@ default deny. IoT, media and guest are terminal — traffic goes out, nothing comes back in. One path the diagram cannot draw: the switch is plumbing here, not a segment, but its management address sits on the untagged LAN (`10.7.7.0/24`). Since 2026-09-02 that interface -blocks every VLAN and passes only DNS, NTP and the internet -([#229](https://github.com/Gerrrt/HomeLab/issues/229)), and since 2026-09-06 +blocks every VLAN and passes only DNS, NTP, the switch's syslog to the +firewall itself, and the internet +([#229](https://github.com/Gerrrt/HomeLab/issues/229), +[ADR-0127](adr/0127-relay-neos-log-through-morpheus.md)), and since 2026-09-06 Winterfell reaches it only through named passes ([ADR-0025](adr/0025-close-the-switch-lan-to-winterfell.md)). IPv6 is the residual: the stock *Default allow LAN IPv6 to any* rule is still there. diff --git a/docs/changelog.md b/docs/changelog.md index 98771ed87..80ae5938f 100644 --- a/docs/changelog.md +++ b/docs/changelog.md @@ -19,6 +19,30 @@ docstring gives: it is a record, not a claim about now. ## 2026-11-23 +- **`neo`'s log leaves the switch + ([ADR-0127](adr/0127-relay-neos-log-through-morpheus.md), accepted).** + The core switch kept its log in RAM, 1,000 lines deep. It now sends + `info`, `warning`, `error` and `critical` over UDP to syslog-ng on + `morpheus`'s switch-LAN address, which relays them over the existing pinned + TLS connection as `host="neo"`. One new pass on `igc0`, *Allow Neo syslog to + Firewall*, to `10.7.7.1:5514` and nothing else. Lines on that path get a fixed + `app="routeros"` in Alloy, and the firewall's Loki rules now require + `host="morpheus"`, so neither guard alone lets a `neo` line raise or silence + a firewall alert. Two new rules, `SwitchLoginFromUnexpectedSource` and + `SwitchLogsStopped`, take the Loki count to 28. Three findings on the way: + - The ADR assumed both syslog-ng sources on `morpheus` set + `flags(no-hostname)`. The live one is generated by the package and cannot, + and `ship-firewall-logs.md` §3 described a `network()` source that was + never what ran. pfSense's path now gets a rewrite that sets `morpheus` + instead, and §3 describes what is on the box. + - Home Assistant's API session logged in once in four hours, so it was no + heartbeat for an absence rule. `neo` now logs one line every five minutes + from a scheduler entry, `log-heartbeat`. + - `ether4`, `mjolnir`'s card, had 48,057 link-downs in 16 days of uptime, + about one every seven seconds by the afternoon: 987 of the 1,000 lines in + the buffer. Nothing saw it, because nothing read the switch's log. Not + fixed here. + README's ADR count also moves to 127: #1659 and #1676 each counted to 126. - **The range host will be monitored now that it stays on ([ADR-0126](adr/0126-monitor-gandalf-now-that-it-stays-on.md), [#1651](https://github.com/Gerrrt/HomeLab/issues/1651)).** ADR-0125 made diff --git a/docs/firewall-claims.yaml b/docs/firewall-claims.yaml index cf3bab0a1..1f5b3832d 100644 --- a/docs/firewall-claims.yaml +++ b/docs/firewall-claims.yaml @@ -35,7 +35,9 @@ interfaces: # The switch management LAN. Default deny since 2026-09-02 (#229) outbound and # 2026-09-06 inbound (ADR-0025); ADR-0013 read it before either and describes - # the wider state. + # the wider state. Its passes to the gateway's own address (DNS, NTP, and + # neo's syslog to 10.7.7.1:5514/udp since ADR-0127) reach no segment, so they + # are not claims this file makes. # # The inet6 row is the residual ADR-0025 and network.md's [^lan] footnote both # record: this interface still carries pfSense's stock *Default allow LAN IPv6 diff --git a/docs/network.md b/docs/network.md index 0e57a6198..ea8806837 100644 --- a/docs/network.md +++ b/docs/network.md @@ -35,7 +35,9 @@ above CasaBonita, which the spectrum does not. Reasoning in LAN to any* until 2026-09-02, when six logged blocks — one per VLAN — were placed above an egress rule renamed *Allow internet*, leaving DNS and NTP to the gateway as the only passes above them - ([#229](https://github.com/Gerrrt/HomeLab/issues/229)). Inbound, nothing on + ([#229](https://github.com/Gerrrt/HomeLab/issues/229)). A third joined + them on 2026-11-23: `neo`'s syslog to the gateway's own `10.7.7.1:5514/udp` + ([ADR-0127](adr/0127-relay-neos-log-through-morpheus.md)). Inbound, nothing on Winterfell can reach it since 2026-09-06: `Gerrrt/Lemmiwinks#177` added a logged block from `10.0.99.0/24`, leaving SNMP as the one pass above that. One residual, in both directions: the stock *Default allow LAN IPv6 to any* @@ -182,6 +184,14 @@ truth for what a box actually does. switch by MAC after a reset, as [`swap-the-switch.md`](runbooks/swap-the-switch.md) does. - NTP comes from `10.7.7.1`. The default `admin` user is disabled. + - The log leaves the switch. Topics `info`, `warning`, `error` and + `critical` go to syslog-ng on `10.7.7.1:5514` over UDP, from + `10.7.7.2`, and morpheus relays them to Loki as `host="neo"`. A + scheduler entry, `log-heartbeat`, logs a line every five minutes so that + silence means the path broke. The `memory` rules stay. + [ADR-0127](adr/0127-relay-neos-log-through-morpheus.md) records why, and + [`ship-firewall-logs.md`](runbooks/ship-firewall-logs.md) §10 is the + procedure. - DHCP disabled. - **`morpheus` pins thirteen reservations in its ARP table, on every segment but Skids and Degens.** Each is a Kea reservation with *Create a diff --git a/docs/observability.md b/docs/observability.md index 825b4033f..65582019c 100644 --- a/docs/observability.md +++ b/docs/observability.md @@ -352,7 +352,7 @@ separates a quiet stream from a stopped one. ## Alerting -192 rules in total: 166 metric-based in `prometheus/rules/`, and 26 log-based in +194 rules in total: 166 metric-based in `prometheus/rules/`, and 28 log-based in `loki/rules/`. ### Log-based (Loki ruler) @@ -363,6 +363,14 @@ 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. +**`SwitchLoginFromUnexpectedSource`** and **`SwitchLogsStopped`** read `neo`'s +log, which morpheus relays to the same syslog listener as its own +([ADR-0127](adr/0127-relay-neos-log-through-morpheus.md)). The first fires on a +login to the core switch from anywhere but the switch LAN, desktop-02, or Home +Assistant's read-only API user. The second fires when 30 minutes pass without a +line, and the switch logs a heartbeat every five minutes so that silence means +the path is broken. + **`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, diff --git a/docs/runbooks/respond-to-a-security-alert.md b/docs/runbooks/respond-to-a-security-alert.md index 850834ff0..1d98e9833 100644 --- a/docs/runbooks/respond-to-a-security-alert.md +++ b/docs/runbooks/respond-to-a-security-alert.md @@ -78,6 +78,29 @@ An SSH login was **accepted** from outside VLAN 50 and VLAN 99. [TerminalSegmentReachedInternalNetwork](#terminalsegmentreachedinternalnetwork) explains how to read it from the firewall. +## SwitchLoginFromUnexpectedSource + +Someone logged in to `neo`, the core switch, from a source other than the +three it expects: the switch LAN, desktop-02 (`10.0.50.90`), or Home +Assistant's read-only `homeassistant` user from `trinity` over the API. +The alert's labels name the user, the source address and the service. + +```logql +{host="neo"} |= " logged in from " +``` + +- **Was it you?** SSH jumped through morpheus arrives as `10.7.7.1` and does + not fire. A login straight from `prometheus` or another Winterfell host does, + because no pass for it is supposed to exist. +- **If it was not you, end the session first.** From the switch LAN or WinBox + by MAC, `/user active print` shows it, and `/user active request-logout` + with its number ends it. Then change that user's password or key, and read + `/log print where topics~"system"` around the login for any change made. +- **Then find the path.** A source outside the switch LAN reached the switch + through a pass on morpheus, or through the switch's own management list + being wider than the firewall. `network.md`'s LAN notes name every pass + that should exist. Anything else on the switch LAN interface is the fault. + ## TerminalSegmentReachedInternalNetwork pfSense **passed** a packet from VLAN 10, 20 or 40 toward VLAN 30, 50 or 99, diff --git a/docs/runbooks/restore-the-firewall.md b/docs/runbooks/restore-the-firewall.md index d89fe9a41..f08f90547 100644 --- a/docs/runbooks/restore-the-firewall.md +++ b/docs/runbooks/restore-the-firewall.md @@ -340,6 +340,24 @@ ssh root@10.0.99.1 'pfctl -sr | grep -c ""' # makes every rule using it match nothing, which reads as "no leaks". ``` +```bash +# 7. Are both log streams back? The syslog-ng package and its objects come back +# with config.xml, including neo's source and the switch-LAN pass +# (ADR-0127), but the TLS files it relays with do not: they sit outside +# config.xml. Copy them back first, as ship-firewall-logs.md §3 step 2 +# says, then restart the service from Status → Services. +ssh admin@10.0.99.1 'ls /usr/local/etc/syslog-ng/tls/; sockstat -4l | grep syslog-ng' +# expect ca.pem, morpheus-key.pem and morpheus.pem, and listeners on +# 127.0.0.1:5140 (pfSense's own log) and 10.7.7.1:5514 (neo's) + +# On prometheus, a few minutes later: +curl -sG http://localhost:3100/loki/api/v1/query \ + --data-urlencode 'query=sum by (host) (count_over_time({source="network"}[10m]))' \ + | jq -r '.data.result[] | "\(.metric.host)\t\(.value[1])"' +# expect a count for both morpheus and neo. Missing both: the TLS files or +# syslog-ng. Missing only neo: the pass on igc0 or the s_neo source. +``` + > [!NOTE] > Step 4 matters more than it looks. A restore that brings back connectivity but > not the rule set leaves the house on a flat network that *appears* to work diff --git a/docs/runbooks/ship-firewall-logs.md b/docs/runbooks/ship-firewall-logs.md index 1cbc44497..758434f30 100644 --- a/docs/runbooks/ship-firewall-logs.md +++ b/docs/runbooks/ship-firewall-logs.md @@ -131,15 +131,17 @@ openssl s_client -connect 10.0.99.20:6514 -CAfile certificates/ca.pem Oct 7 18:00:00 filterlog[4242]: …`), and without the flag syslog-ng - can read the tag as one. `peer-verify(required-trusted)` makes morpheus - check the listener's certificate as well, against the same CA. + The package prints a log object without its name, so the name is only the + form's key. `peer-verify(required-trusted)` makes morpheus check the + listener's certificate as well, against the same CA. + + `r_host_morpheus` is what makes the hostname on this connection mean + something. Alloy stores every line from `10.0.99.1` as `host="morpheus"` + unless its hostname is `neo` (§10). Without the rewrite, syslog-ng would + fill the hostname from the line itself whenever the token after the + timestamp looked like one, so a local process logging with a tag of + `neo something` would be stored as the switch. The generated source cannot + take `flags(no-hostname)`, which would be the other fix, so the hostname is + overwritten on the way out instead. The default file destination keeps + whatever syslog-ng parsed. The loopback hop is UDP, and that is fine: `127.0.0.1` cannot be reached, let alone forged, from another host. The TLS hop is the one that crosses VLAN 99. The certificate files sit outside `config.xml`, so a config restore does not bring them back. After [`restore-the-firewall.md`](restore-the-firewall.md), -repeat step 2. +repeat step 2: its §4 step 7 checks both log streams came back. --- @@ -471,6 +483,111 @@ UDP syslog now. A UDP line sent from `10.0.99.1` itself is not stored, and --- +## 10. Relay `neo`'s log ([ADR-0127](../adr/0127-relay-neos-log-through-morpheus.md)) + +`neo` kept its log in RAM only, 1,000 lines deep. RouterOS sends standard +syslog over UDP only and offers no client certificate, so it cannot meet the +listener in §2. It sends to syslog-ng on morpheus instead, on the switch LAN, +and syslog-ng relays the lines over the same TLS connection, stamped as +`neo`'s: + +```text +neo ──udp──▶ 10.7.7.1:5514 syslog-ng (on morpheus) ──TLS (§3)──▶ 10.0.99.20:6514 Alloy ──▶ Loki, host="neo" +``` + +Do the steps in this order. Each makes the next one safe: the first line +from `neo` arrives at a sender rule that names it, with its `app` fixed and no +firewall rule able to read it. + +1. **Deploy the receiver side.** `syslog.alloy`'s `neo` rule, its fixed + `app="routeros"`, and the `host="morpheus"` selectors on the firewall's + Loki rules ship with the change that added this section, and + `scripts/check_syslog_senders.sh` covers them. Confirm the running Alloy + has them, as §2 says to, before going on: + + ```bash + docker exec alloy grep -c 'routeros' /etc/alloy/syslog.alloy # expect 1 + docker inspect -f '{{.State.StartedAt}}' alloy + ``` + +2. **On morpheus, add the neo path** under **Services → Syslog-ng → + Advanced**: + + ```text + source s_neo { network(ip("10.7.7.1") port(5514) transport("udp") flags(no-hostname)); }; + rewrite r_host_neo { set("neo" value("HOST")); }; + log { source(s_neo); rewrite(r_host_neo); destination(d_alloy_tls); }; # form name l_neo + ``` + + Port `5514`, because pfSense's own `syslogd` holds `*:514`. Bound to + `10.7.7.1`, so nothing on another interface reaches it. + `flags(no-hostname)` means whatever `neo` writes as its hostname is never + read, and the rewrite sets it. Check `sockstat -4l | grep 5514` shows + syslog-ng on `10.7.7.1`. + +3. **On morpheus, one pass on the switch LAN** (`igc0`): + `10.7.7.2 → 10.7.7.1` UDP `5514`, *Allow Neo syslog to Firewall*, above the + per-VLAN blocks, beside the DNS and NTP passes to the gateway. It reaches the + firewall's own address and nothing else, and nothing into or out of + Winterfell changes. + +4. **On `neo`**, from the switch LAN or SSH jumped through morpheus + (`ssh -J admin@10.0.99.1 gerrrt@10.7.7.2`), with safe mode on: + + ```text + /system logging action set remote remote=10.7.7.1 remote-port=5514 \ + remote-protocol=udp remote-log-format=syslog src-address=10.7.7.2 + /system logging add topics=info action=remote + /system logging add topics=warning action=remote + /system logging add topics=error action=remote + /system logging add topics=critical action=remote + /system scheduler add name=log-heartbeat interval=5m policy=read,write,test \ + on-event=":log info \"log heartbeat\"" + ``` + + One rule per topic, because a rule that lists several matches only lines + carrying all of them. The `memory` rules stay, so the console still shows + the log when morpheus is the suspect. The heartbeat is what keeps + `SwitchLogsStopped` honest: Home Assistant's API session logged in once in + four hours on 2026-11-23, so traffic alone is no pulse. + +5. **Verify both hops.** On morpheus, the plain hop: + + ```bash + tcpdump -ni igc0 -A -c 3 'udp port 5514 and src host 10.7.7.2' + ``` + + On prometheus, the stored lines and their labels: + + ```bash + curl -sG http://localhost:3100/loki/api/v1/query_range \ + --data-urlencode 'query={host="neo"}' --data-urlencode 'limit=5' \ + | jq -r '.data.result[] | "\(.stream.app) \(.stream.level)\t\(.values[0][1])"' + ``` + + Expect `routeros` on every line. A line from `neo` stored as + `host="morpheus"` means Alloy is running without the `neo` rule. Nothing in + Loki with packets on `igc0` means syslog-ng is not listening on `5514`. + +6. **Measure a day of it**, as §8 does for the firewall: + + ```bash + curl -sG http://localhost:3100/loki/api/v1/query \ + --data-urlencode 'query=sum(count_over_time({host="neo"}[24h]))' | jq '.data.result' + ``` + + On 2026-11-23 a link flapping on `ether4` was most of it, about 250 lines + an hour. If Home Assistant's login and logout pairs ever dominate, drop + them in Alloy by user and address, not on the switch, so a login by anyone + else is never filtered. + +To undo it, set the `remote` action back to `0.0.0.0` and remove the four +`remote` rules and the scheduler entry on `neo`, then the pass and the three +syslog-ng objects on morpheus. Silence `SwitchLogsStopped`, which fires 30 +minutes later, as it should. + +--- + ## Rollback Untick **Enable Remote Logging** on pfSense. That stops the source instantly and diff --git a/docs/security.md b/docs/security.md index cdfff469a..cea4f19a4 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 | 192 alert rules, 30 days of metrics and logs | +| Losing visibility of a failure | 194 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 | @@ -228,8 +228,10 @@ TCP-only, with the catch-all carrying the rest, and the DNS and NTP passes to **The switch LAN was the other exception and is not any more.** Since 2026-09-02 that interface carries six logged blocks — one per VLAN — above an egress rule -renamed *Allow internet*, with DNS and NTP to the gateway the only passes above -them ([#229](https://github.com/Gerrrt/HomeLab/issues/229)); since 2026-09-06 +renamed *Allow internet*, with DNS, NTP and, since 2026-11-23, `neo`'s syslog +to the gateway the only passes above them +([#229](https://github.com/Gerrrt/HomeLab/issues/229), +[ADR-0127](adr/0127-relay-neos-log-through-morpheus.md)); since 2026-09-06 nothing on Winterfell can reach it either ([ADR-0025](adr/0025-close-the-switch-lan-to-winterfell.md)), apart from SNMP from `10.0.99.20`. A second pass has been in force since 2026-11-11: diff --git a/scripts/check_syslog_senders.sh b/scripts/check_syslog_senders.sh index deb9106d9..653b33d86 100755 --- a/scripts/check_syslog_senders.sh +++ b/scripts/check_syslog_senders.sh @@ -29,6 +29,18 @@ # 10. morpheus's certificate from another address # -> the handshake completes, the allowlist drops it, and it is counted # +# and three for neo's log, which morpheus relays stamped with hostname `neo` +# (ADR-0127): +# +# 11. from the allowed address, hostname `neo`, tagged `filterlog` +# -> stored as host="neo", app="routeros", with none of filterlog's labels +# 12. the same, tagged `suricata` on Skids's facility +# -> stored as host="neo", app="routeros", and no `interface` +# 13. hostname `neo` from another address -> dropped and counted, like 10 +# +# 11 and 12 are what keep a line on neo's path out of the firewall's alerts: +# those rules select by app, and a neo line must never carry the firewall's. +# # Each refusal (1, 6-10) is checked for absence only after the accepted lines, # which were sent after it, have arrived. "Absent" therefore means refused, # not slow. The counter shows 10 reached Alloy at all, and Alloy's own log @@ -39,9 +51,9 @@ # # The one change made to syslog.alloy: the scratch network cannot be # 10.0.99.0/24 without taking the monitoring host's real route to VLAN 99, so -# the allowed address literal is rewritten to the scratch "morpheus". The -# rewrite has to match at least once, or this fails rather than testing a file -# with no allowlist in it. +# the allowed address literal is rewritten to the scratch "morpheus", in the +# morpheus rule and in the neo rule's "
;neo". The rewrite has to +# match both, or this fails rather than testing a file with no allowlist in it. # # Usage: scripts/check_syslog_senders.sh [--skips-file PATH] [--alloy-file PATH] # --alloy-file test a different syslog config (used to measure alternatives @@ -149,12 +161,13 @@ python3 - "${ALLOY_FILE}" "${WORK}/alloy/syslog.alloy" "${ALLOWED_IP}" <<'REWRIT import sys src, dst, ip = sys.argv[1:] text = open(src, encoding="utf-8").read() -old = '"10\\\\.0\\\\.99\\\\.1"' -new = '"' + ip.replace(".", "\\\\.") + '"' -n = text.count(old) -if n == 0: - sys.exit(f"the allowed-sender literal {old} is not in {src}: nothing to test") -open(dst, "w", encoding="utf-8").write(text.replace(old, new)) +esc = ip.replace(".", "\\\\.") +for old, new in (('"10\\\\.0\\\\.99\\\\.1"', '"' + esc + '"'), + ('"10\\\\.0\\\\.99\\\\.1;neo"', '"' + esc + ';neo"')): + if text.count(old) != 1: + sys.exit(f"the sender literal {old} is not in {src} exactly once: nothing to test") + text = text.replace(old, new) +open(dst, "w", encoding="utf-8").write(text) REWRITE chmod -R a+rwX "${WORK}" @@ -246,9 +259,9 @@ send_tls() { # from-ip line cert-name printf "%d %s" "${#msg}" "${msg}" | timeout 15 openssl s_client "${args[@]}" >/dev/null 2>&1 || true ' _ "$2" "${ALLOY_IP}" "$3" } -rfc5424() { # hostname token - printf '<134>1 %s %s filterlog 4242 - - %s,,,1000000103,igc0.20,match,block,in,4' \ - "$(date -u +%Y-%m-%dT%H:%M:%SZ)" "$1" "$2" +rfc5424() { # hostname token [app] [pri] + printf '<%s>1 %s %s %s 4242 - - %s,,,1000000103,igc0.20,match,block,in,4 [Priority: 1]' \ + "${4:-134}" "$(date -u +%Y-%m-%dT%H:%M:%SZ)" "$1" "${3:-filterlog}" "$2" } RUN_ID="$(date +%s)-$$" @@ -260,6 +273,9 @@ TOK_TLS_SIBLING="tls-sibling-${RUN_ID}" TOK_TLS_SERVER="tls-serverleaf-${RUN_ID}" TOK_TLS_OTHERCA="tls-otherca-${RUN_ID}" TOK_TLS_STRANGER="tls-stranger-${RUN_ID}" +TOK_NEO="neo-filterlog-${RUN_ID}" +TOK_NEO_SURICATA="neo-suricata-${RUN_ID}" +TOK_NEO_STRANGER="neo-stranger-${RUN_ID}" STAMP="$(LC_ALL=C date -u '+%b %e %H:%M:%S')" dropped_before="$(dropped)" @@ -272,8 +288,12 @@ send_tls "${ALLOWED_IP}" "$(rfc5424 - "${TOK_TLS_SIBLING}")" sibling send_tls "${ALLOWED_IP}" "$(rfc5424 - "${TOK_TLS_SERVER}")" grafana send_tls "${ALLOWED_IP}" "$(rfc5424 - "${TOK_TLS_OTHERCA}")" rogue send_tls "${STRANGER_IP}" "$(rfc5424 - "${TOK_TLS_STRANGER}")" morpheus +send_tls "${STRANGER_IP}" "$(rfc5424 neo "${TOK_NEO_STRANGER}")" morpheus send_tls "${ALLOWED_IP}" "$(rfc5424 - "${TOK_TLS}")" morpheus send_tls "${ALLOWED_IP}" "$(rfc5424 evil "${TOK_TLS_EVIL}")" morpheus +# 142 is local1.info, the facility syslog.alloy maps to Skids's Suricata. +send_tls "${ALLOWED_IP}" "$(rfc5424 neo "${TOK_NEO}")" morpheus +send_tls "${ALLOWED_IP}" "$(rfc5424 neo "${TOK_NEO_SURICATA}" suricata 142)" morpheus # Prints the label set of every stream holding the token, one JSON per line. streams_with() { @@ -302,7 +322,7 @@ wait_streams() { # token seconds -> prints streams once present } FAILED=0 -info "sent one line over UDP and seven over TLS through ${ALLOY_FILE#"${REPO_ROOT}"/}" +info "sent one line over UDP and ten over TLS through ${ALLOY_FILE#"${REPO_ROOT}"/}" # host_is — every stream carries host="morpheus" and nothing else # says `evil`. @@ -343,6 +363,40 @@ else fail "TLS line with a hostname never reached Loki" fi +# --- neo, relayed by morpheus (ADR-0127) ---------------------------------------- + +# neo_labels_ok ... — every stream is host="neo", +# app="routeros", and carries none of the named labels. +neo_labels_ok() { + python3 -c ' +import json, sys +bad = sys.argv[1:] +streams = [json.loads(l) for l in sys.stdin if l.strip()] +ok = streams and all(s.get("host") == "neo" and s.get("app") == "routeros" + and not any(b in s for b in bad) for s in streams) +sys.exit(0 if ok else 1)' "$@" +} + +if s11="$(wait_streams "${TOK_NEO}" 15)"; then + if printf '%s\n' "${s11}" | neo_labels_ok action interface direction; then + pass "hostname \"neo\" on morpheus's connection is host=\"neo\", and its filterlog tag becomes app=\"routeros\"" + else + fail "neo's line tagged filterlog was stored with the wrong labels: ${s11}" + fi +else + fail "neo's line on morpheus's connection never reached Loki" +fi + +if s12="$(wait_streams "${TOK_NEO_SURICATA}" 15)"; then + if printf '%s\n' "${s12}" | neo_labels_ok interface priority classification; then + pass "neo's line tagged suricata on Skids's facility gets app=\"routeros\" and no interface" + else + fail "neo's line tagged suricata was stored with the wrong labels: ${s12}" + fi +else + fail "neo's line tagged suricata never reached Loki" +fi + absent() { # token description local out if ! out="$(streams_with "$1")"; then @@ -359,6 +413,7 @@ absent "${TOK_TLS_SIBLING}" "a TLS line with another client certificate from th absent "${TOK_TLS_SERVER}" "a TLS line authenticated with a serverAuth leaf" absent "${TOK_TLS_OTHERCA}" "a TLS line with another CA's client certificate" absent "${TOK_TLS_STRANGER}" "a TLS line with morpheus's certificate from ${STRANGER_IP}" +absent "${TOK_NEO_STRANGER}" "a line with hostname neo from ${STRANGER_IP}" # The handshake refusals, by Alloy's own reason, so a refusal for some other # cause (a broken leaf, a wrong path) cannot pass as the intended one. Cases 7, @@ -377,10 +432,10 @@ else fi dropped_after="$(dropped)" -if ((dropped_after - dropped_before == 1)); then - pass "the TLS line from ${STRANGER_IP} is counted (reason=\"syslog_sender_not_allowed\")" +if ((dropped_after - dropped_before == 2)); then + pass "both TLS lines from ${STRANGER_IP} are counted (reason=\"syslog_sender_not_allowed\")" else - fail "drop counter moved by $((dropped_after - dropped_before)), expected 1" + fail "drop counter moved by $((dropped_after - dropped_before)), expected 2" fi exit "${FAILED}" diff --git a/stacks/observability/README.md b/stacks/observability/README.md index a7d694aa1..005e60837 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 26 LogQL rules, security, watchdog and NUT, evaluated by Loki's ruler + rules/*.rules.yaml 28 LogQL rules, security, watchdog and NUT, 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/alloy/syslog.alloy b/stacks/observability/alloy/syslog.alloy index 0b9b36a57..2f34e66e9 100644 --- a/stacks/observability/alloy/syslog.alloy +++ b/stacks/observability/alloy/syslog.alloy @@ -28,6 +28,13 @@ // pfSense reaches this on the management VLAN, where it already has an // interface (10.0.99.1), so no firewall rule is required. // +// neo's log rides the same connection (ADR-0127). RouterOS sends standard +// syslog over UDP only and offers no client certificate, so neo sends to +// syslog-ng on morpheus, on the switch LAN, and syslog-ng relays it here +// stamped with hostname `neo`. The `neo` rule in loki.relabel.network_syslog +// below is the one place this file reads a message hostname, and why that is +// safe is written there. +// // TLS ON 6514, AND NO UDP (#1049). This listener was UDP and RFC3164 at // first, because that is what pfSense sends by default. But a UDP source // address can be forged by any host on VLAN 99, so #844's allowlist below @@ -164,6 +171,26 @@ loki.relabel "network_syslog" { replacement = "morpheus" } + // neo, relayed by morpheus (ADR-0127). After the morpheus rule, so it + // overrides it, and only for a line that both arrives on morpheus's + // connection AND carries hostname `neo`. Every other line from 10.0.99.1 + // stays host="morpheus"; `neo` from any other address gets no host and is + // dropped below. + // + // This trusts a message hostname, which the paragraph above refuses, and + // that is safe here because the sender does not write it. morpheus's + // syslog-ng sets HOST itself on both of its paths: `neo` on the switch-LAN + // source, which also ignores any hostname neo sends (flags(no-hostname)), + // and `morpheus` on pfSense's own loopback path. So `neo` reaches this + // field only through the neo path, and only over the pinned TLS connection. + // docs/runbooks/ship-firewall-logs.md §10 is the syslog-ng side. + rule { + source_labels = ["__syslog_connection_ip_address", "__syslog_message_hostname"] + regex = "10\\.0\\.99\\.1;neo" + target_label = "host" + replacement = "neo" + } + // pfSense tags filterlog, dhcpd, unbound, sshd and so on. Low cardinality, // and it is how you separate firewall decisions from everything else. rule { @@ -171,6 +198,19 @@ loki.relabel "network_syslog" { target_label = "app" } + // ...except on neo's lines, which get a fixed app whatever their tag says. + // The firewall's Loki rules select by app (filterlog, suricata, kea-dhcp4), + // and a line on the neo path tagged `filterlog` must never be read as the + // firewall's: it could raise a firewall alert, or keep FirewallLogsStopped + // quiet while morpheus says nothing. Those rules also require + // host="morpheus" (ADR-0127), so either guard alone is enough. + rule { + source_labels = ["host"] + regex = "neo" + target_label = "app" + replacement = "routeros" + } + // Which interface a Suricata alert came from. pfSense runs one Suricata // process per interface, and the alert line itself does not say which: // @@ -192,8 +232,9 @@ loki.relabel "network_syslog" { // local4.none;local7.none;...`, so an interface set to one of those alerts on // the box and sends nothing — which looks exactly like a quiet interface. // - // Both labels are sourced, joined with the default `;`, so a facility - // collision with some other pfSense daemon cannot mislabel its lines. And an + // The labels are sourced, joined with the default `;`, so a facility + // collision with some other pfSense daemon cannot mislabel its lines, and + // `host` is among them so a line on neo's path never gets an interface. And an // unmapped facility gets NO interface label rather than a guessed one, for // the reason `.+` not `.*` is spelled out below: absent is visibly absent. // `sum by (interface)` shows it as an empty series; a wrong value would not. @@ -201,15 +242,15 @@ loki.relabel "network_syslog" { // Two values, one per interface, alongside filterlog's igc0. vocabulary // so the same picker drives both. rule { - source_labels = ["__syslog_message_app_name", "__syslog_message_facility"] - regex = "suricata;local1" + source_labels = ["host", "__syslog_message_app_name", "__syslog_message_facility"] + regex = "morpheus;suricata;local1" target_label = "interface" replacement = "igc0.20" } rule { - source_labels = ["__syslog_message_app_name", "__syslog_message_facility"] - regex = "suricata;local2" + source_labels = ["host", "__syslog_message_app_name", "__syslog_message_facility"] + regex = "morpheus;suricata;local2" target_label = "interface" replacement = "igc0.10" } diff --git a/stacks/observability/loki/rules/security.rules.yaml b/stacks/observability/loki/rules/security.rules.yaml index 862313b41..d6e270035 100644 --- a/stacks/observability/loki/rules/security.rules.yaml +++ b/stacks/observability/loki/rules/security.rules.yaml @@ -465,7 +465,7 @@ groups: expr: | sum by (interface) ( count_over_time( - {app="filterlog", action="pass"} + {host="morpheus", app="filterlog", action="pass"} |~ `,10\.0\.(10|20|40)\.[0-9]+,(10\.0\.(30|50|99)|10\.7\.7)\.[0-9]+,` [5m] ) ) > 0 @@ -511,7 +511,7 @@ groups: expr: | sum by (interface) ( count_over_time( - {app="filterlog", action="pass"} + {host="morpheus", app="filterlog", action="pass"} |~ `,(10\.0\.30|172\.31\.0)\.[0-9]+,(10\.0\.(10|20|40|50|99)|10\.7\.7)\.[0-9]+,` [5m] ) ) > 0 @@ -552,7 +552,7 @@ groups: expr: | sum by (interface, action) ( count_over_time( - {app="filterlog"} + {host="morpheus", app="filterlog"} |~ `,172\.30\.30\.[0-9]+,[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+,` [5m] ) ) > 0 @@ -580,7 +580,7 @@ groups: expr: | sum by (interface) ( count_over_time( - {app="filterlog", action="block"} + {host="morpheus", app="filterlog", action="block"} |~ `,10\.0\.20\.[0-9]+,10\.0\.(30|50|99)\.[0-9]+,` [10m] ) ) > 20 @@ -605,7 +605,7 @@ groups: # remote-logging setting was reset by an update, or Alloy stopped # accepting UDP — none of which any other alert here would catch. expr: | - absent_over_time({app="filterlog"}[30m]) + absent_over_time({host="morpheus", app="filterlog"}[30m]) for: 0s labels: component: logs @@ -685,7 +685,7 @@ groups: expr: | sum by (mac) ( count_over_time( - {app="kea-dhcp4"} + {host="morpheus", app="kea-dhcp4"} | regexp `hwtype=1 (?P[0-9a-f:]{17}).*10\.0\.(?P[0-9]{1,3})\.` | vlan = "50" [10m] @@ -694,7 +694,7 @@ groups: unless sum by (mac) ( count_over_time( - {app="kea-dhcp4"} + {host="morpheus", app="kea-dhcp4"} | regexp `hwtype=1 (?P[0-9a-f:]{17}).*10\.0\.(?P[0-9]{1,3})\.` | vlan = "50" [7d] offset 10m @@ -712,7 +712,7 @@ groups: Wi-Fi is a pre-shared key that people are given. A device here is either one of yours, one that rotated its private MAC, or one that has the PSK and should not. Find the address with - {app="kea-dhcp4"} |= "{{ $labels.mac }}" and identify it against + {host="morpheus", app="kea-dhcp4"} |= "{{ $labels.mac }}" and identify it against docs/network.md before deciding which. - alert: UnknownDeviceOnManagementSegment @@ -725,7 +725,7 @@ groups: expr: | sum by (mac) ( count_over_time( - {app="kea-dhcp4"} + {host="morpheus", app="kea-dhcp4"} | regexp `hwtype=1 (?P[0-9a-f:]{17}).*10\.0\.(?P[0-9]{1,3})\.` | vlan = "99" [10m] @@ -734,7 +734,7 @@ groups: unless sum by (mac) ( count_over_time( - {app="kea-dhcp4"} + {host="morpheus", app="kea-dhcp4"} | regexp `hwtype=1 (?P[0-9a-f:]{17}).*10\.0\.(?P[0-9]{1,3})\.` | vlan = "99" [7d] offset 10m @@ -768,7 +768,7 @@ groups: # class alone being unticked on morpheus, which leaves filterlog # arriving and this stream gone. expr: | - absent_over_time({app="kea-dhcp4"}[2h]) + absent_over_time({host="morpheus", app="kea-dhcp4"}[2h]) for: 0s labels: component: logs @@ -853,7 +853,7 @@ groups: # this warrants looking at the same evening, not the same quarter. expr: | sum by (interface, classification) ( - count_over_time({app="suricata", priority="1"} [10m]) + count_over_time({host="morpheus", app="suricata", priority="1"} [10m]) ) > 0 for: 0s labels: @@ -892,7 +892,7 @@ groups: # buys: the summary names the segment, which is the whole reason the # interfaces were enabled one at a time. expr: | - sum by (interface) (count_over_time({app="suricata"} [10m])) > 200 + sum by (interface) (count_over_time({host="morpheus", app="suricata"} [10m])) > 200 for: 5m labels: component: logs @@ -922,7 +922,7 @@ groups: # the process is up and inspecting nothing, which is the case nothing # else in the stack can see (#441). expr: | - absent_over_time({app="suricata"}[9h]) + absent_over_time({host="morpheus", app="suricata"}[9h]) for: 0s labels: component: logs @@ -938,3 +938,86 @@ groups: interfaces the processes are bound to on pfSense, that the last rule update left a non-empty set, and that syslog still leaves morpheus for UDP 1514 (FirewallLogsStopped would be firing too if it did not). + + # --------------------------------------------------------------------------- + # The core switch. neo's log reaches Loki through morpheus's syslog-ng + # (ADR-0127) as host="neo". Before that it lived only in the switch's RAM, + # 1,000 lines deep, so who logged in to the device every VLAN crosses was + # known only to that device, and only for a few hours. + # + # RouterOS writes every login the same way, whatever the service: + # + # user homeassistant logged in from 10.0.99.40 via api + # user gerrrt logged in from 10.7.7.1 via ssh + # + # read off neo on 2026-11-23. app is always `routeros` on this stream, set + # by syslog.alloy whatever the line's tag says, so these select by host. + - name: switch + interval: 1m + rules: + - alert: SwitchLoginFromUnexpectedSource + # Three sources are expected, and each is in network.md's LAN notes: + # - the switch LAN itself, 10.7.7.0/24: break-glass, and SSH jumped + # through morpheus arrives as 10.7.7.1; + # - desktop-02, 10.0.50.90, the one workstation in the switch's own + # management list; + # - Home Assistant's read-only user, from trinity, over the API + # (ADR-0111). Only that user from that address: `gerrrt` from + # 10.0.99.40 would mean trinity holds an admin credential. + # Anything else is a login the firewall and the switch's own filter + # were both supposed to make impossible. + # + # The `|=` comes first because the label filters below are true for a + # line the regexp did not match: an absent label is "", which is + # neither the switch LAN nor `homeassistant`. + expr: | + sum by (user, source, via) ( + count_over_time( + {host="neo"} + |= " logged in from " + | regexp `user (?P\S+) logged in from (?P\S+) via (?P\S+)` + | source !~ `10\.7\.7\.[0-9]+|10\.0\.50\.90` + | user != "homeassistant" or source != "10.0.99.40" or via != "api" + [10m] + ) + ) > 0 + for: 0s + labels: + component: logs + severity: critical + category: security + annotations: + runbook_url: "https://github.com/Gerrrt/HomeLab/blob/main/docs/runbooks/respond-to-a-security-alert.md#switchloginfromunexpectedsource" + summary: "neo: {{ $labels.user }} logged in from {{ $labels.source }} via {{ $labels.via }}" + description: >- + A login to the core switch from somewhere other than the switch + LAN, desktop-02, or Home Assistant's read-only API user. Either a + pass that should not exist reaches the switch, or a credential is + being used from where it should not be. + + - alert: SwitchLogsStopped + # A heartbeat, not traffic, is what keeps this quiet. Measured on + # 2026-11-23, Home Assistant's API session logged in once in four + # hours, so its logins are no pulse, and the link changes that filled + # the buffer that day were a fault on ether4. So neo logs one line every + # five minutes from a scheduler entry, `log-heartbeat` + # (ship-firewall-logs.md §10), and thirty minutes is six of them missed. + # + # neo sends over UDP and holds nothing back, so what this catches is + # lost, not late: the relay on morpheus down, the pass removed, or the + # switch's remote action reset. + expr: | + absent_over_time({host="neo"}[30m]) + for: 0s + labels: + component: logs + severity: warning + category: monitoring + annotations: + summary: "No log lines from neo for 30 minutes" + description: >- + The switch writes a heartbeat every five minutes, so its log has + stopped reaching Loki. If FirewallLogsStopped is also firing, the + fault is morpheus's syslog-ng or the TLS hop. If not, check the + switch-LAN pass on morpheus, the syslog-ng neo source, and neo's + `remote` logging action (ship-firewall-logs.md §10). diff --git a/stacks/observability/loki/tests/security.test.yaml b/stacks/observability/loki/tests/security.test.yaml index e214fe519..e5e5724a0 100644 --- a/stacks/observability/loki/tests/security.test.yaml +++ b/stacks/observability/loki/tests/security.test.yaml @@ -770,7 +770,7 @@ tests: window: 30m streams: [] expect: - - {app: filterlog} + - {host: morpheus, app: filterlog} - alert: FirewallLogsStopped name: one line twenty minutes ago is enough @@ -829,7 +829,7 @@ tests: window: 2h streams: [] expect: - - {app: kea-dhcp4} + - {host: morpheus, app: kea-dhcp4} - alert: DhcpLeaseLogsStopped name: one lease ninety minutes ago is enough @@ -895,7 +895,7 @@ tests: window: 9h streams: [] expect: - - {app: suricata} + - {host: morpheus, app: suricata} - alert: SuricataLogsStopped name: one alert eight hours ago is enough @@ -910,3 +910,90 @@ tests: Webserver [Classification: Misc activity] [Priority: 3] {TCP} 10.0.20.15:51544 -> 10.0.99.20:443 expect: [] + + # =========================================================================== + # ADR-0127: neo's log on the same listener. A line on that path is stored as + # host="neo" with app="routeros" (syslog.alloy); these cases check the second + # guard, that the firewall's rules read host="morpheus" only, by giving a neo + # line the firewall's app outright. + - alert: FirewallLogsStopped + name: a filterlog-tagged line from neo does not keep it quiet + window: 30m + streams: + - labels: {host: neo, app: filterlog, action: pass, direction: in, + reason: match, interface: igc0.50} + entries: + - before: 20m + line: "70,,,1000102400,igc0.50,match,pass,in,4,0x0,,64,40200,0,DF,6,tcp,60,\ + 10.0.50.12,93.184.215.14,40200,443,0,S,1200040001,,64240,,mss;sackOK;TS;nop;wscale" + expect: + - {host: morpheus, app: filterlog} + + - alert: SuricataHighPriorityAlert + name: a priority-1 line from neo does not fire + streams: + - labels: {app: suricata, host: neo, interface: igc0.20, + priority: "1", classification: A Network Trojan was detected} + entries: + - before: 4m + line: >- + [1:2027758:3] ET MALWARE Observed Malicious SSL Cert + [Classification: A Network Trojan was detected] [Priority: 1] + {TCP} 10.0.20.15:51544 -> 198.51.100.23:443 + expect: [] + + # --- SwitchLoginFromUnexpectedSource: a login to neo from elsewhere -------- + - alert: SwitchLoginFromUnexpectedSource + name: an admin login from Winterfell fires + streams: + - labels: {log_type: syslog, host: neo, app: routeros, level: info} + entries: + - before: 3m + line: "system,info,account user gerrrt logged in from 10.0.99.20 via ssh" + expect: + - {user: gerrrt, source: 10.0.99.20, via: ssh} + + - alert: SwitchLoginFromUnexpectedSource + name: another user from Home Assistant's address fires + streams: + - labels: {log_type: syslog, host: neo, app: routeros, level: info} + entries: + - before: 3m + line: "system,info,account user gerrrt logged in from 10.0.99.40 via api" + expect: + - {user: gerrrt, source: 10.0.99.40, via: api} + + - alert: SwitchLoginFromUnexpectedSource + name: the expected sources and ordinary lines do not + streams: + - labels: {log_type: syslog, host: neo, app: routeros, level: info} + entries: + - before: 5m + line: "system,info,account user homeassistant logged in from 10.0.99.40 via api" + - before: 4m + line: "system,info,account user gerrrt logged in from 10.7.7.1 via ssh" + - before: 3m + line: "system,info,account user gerrrt logged in from 10.0.50.90 via winbox" + - before: 2m + line: "system,info,account user homeassistant logged out from 10.0.99.40 via api" + - before: 1m + line: "interface,info ether4 link up (speed 1G, full duplex)" + expect: [] + + # --- SwitchLogsStopped: no line from neo for 30 minutes -------------------- + - alert: SwitchLogsStopped + name: thirty minutes without a line fires + window: 30m + streams: [] + expect: + - {host: neo} + + - alert: SwitchLogsStopped + name: one heartbeat twenty minutes ago is enough + window: 30m + streams: + - labels: {log_type: syslog, host: neo, app: routeros, level: info} + entries: + - before: 20m + line: "script,info log heartbeat" + expect: [] From b75adea32b9f01b94c214b64bf95aec7215e22c6 Mon Sep 17 00:00:00 2001 From: Garrett Allen <98648590+Gerrrt@users.noreply.github.com> Date: Mon, 23 Nov 2026 18:59:48 +0000 Subject: [PATCH 2/2] fix(logs): capture neo's login address as login_from, and order the relay rewrite first MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Every line on the syslog path carries source="network", so Loki renamed the regexp's `source` capture to source_extracted and the rule compared "network": every login to neo, expected or not, would have paged. The capture is now login_from, and the fixtures carry source: network as production lines do; the old rule fails all three login cases against them. ship-firewall-logs.md §10 now makes morpheus's r_host_morpheus rewrite a checked first step, before Alloy trusts the hostname neo. Refs #1659 Co-Authored-By: Claude Opus 5.5 --- docs/runbooks/ship-firewall-logs.md | 22 ++++++++++++++----- .../loki/rules/security.rules.yaml | 16 +++++++++----- .../loki/tests/security.test.yaml | 12 +++++----- 3 files changed, 33 insertions(+), 17 deletions(-) diff --git a/docs/runbooks/ship-firewall-logs.md b/docs/runbooks/ship-firewall-logs.md index 758434f30..6fdd1b1d8 100644 --- a/docs/runbooks/ship-firewall-logs.md +++ b/docs/runbooks/ship-firewall-logs.md @@ -499,7 +499,17 @@ Do the steps in this order. Each makes the next one safe: the first line from `neo` arrives at a sender rule that names it, with its `app` fixed and no firewall rule able to read it. -1. **Deploy the receiver side.** `syslog.alloy`'s `neo` rule, its fixed +1. **On morpheus, make the existing path write its own name first.** The + `r_host_morpheus` rewrite on the TLS log path (§3 step 4) must be live + before Alloy trusts the hostname `neo`. Without it, the package-generated + source can take a hostname from a pfSense line, and one that read `neo` + would be stored as the switch. Check: + + ```bash + ssh admin@10.0.99.1 'grep -c "rewrite(r_host_morpheus)" /usr/local/etc/syslog-ng.conf' # expect 1 + ``` + +2. **Deploy the receiver side.** `syslog.alloy`'s `neo` rule, its fixed `app="routeros"`, and the `host="morpheus"` selectors on the firewall's Loki rules ship with the change that added this section, and `scripts/check_syslog_senders.sh` covers them. Confirm the running Alloy @@ -510,7 +520,7 @@ firewall rule able to read it. docker inspect -f '{{.State.StartedAt}}' alloy ``` -2. **On morpheus, add the neo path** under **Services → Syslog-ng → +3. **On morpheus, add the neo path** under **Services → Syslog-ng → Advanced**: ```text @@ -525,13 +535,13 @@ firewall rule able to read it. read, and the rewrite sets it. Check `sockstat -4l | grep 5514` shows syslog-ng on `10.7.7.1`. -3. **On morpheus, one pass on the switch LAN** (`igc0`): +4. **On morpheus, one pass on the switch LAN** (`igc0`): `10.7.7.2 → 10.7.7.1` UDP `5514`, *Allow Neo syslog to Firewall*, above the per-VLAN blocks, beside the DNS and NTP passes to the gateway. It reaches the firewall's own address and nothing else, and nothing into or out of Winterfell changes. -4. **On `neo`**, from the switch LAN or SSH jumped through morpheus +5. **On `neo`**, from the switch LAN or SSH jumped through morpheus (`ssh -J admin@10.0.99.1 gerrrt@10.7.7.2`), with safe mode on: ```text @@ -551,7 +561,7 @@ firewall rule able to read it. `SwitchLogsStopped` honest: Home Assistant's API session logged in once in four hours on 2026-11-23, so traffic alone is no pulse. -5. **Verify both hops.** On morpheus, the plain hop: +6. **Verify both hops.** On morpheus, the plain hop: ```bash tcpdump -ni igc0 -A -c 3 'udp port 5514 and src host 10.7.7.2' @@ -569,7 +579,7 @@ firewall rule able to read it. `host="morpheus"` means Alloy is running without the `neo` rule. Nothing in Loki with packets on `igc0` means syslog-ng is not listening on `5514`. -6. **Measure a day of it**, as §8 does for the firewall: +7. **Measure a day of it**, as §8 does for the firewall: ```bash curl -sG http://localhost:3100/loki/api/v1/query \ diff --git a/stacks/observability/loki/rules/security.rules.yaml b/stacks/observability/loki/rules/security.rules.yaml index d6e270035..e7966362e 100644 --- a/stacks/observability/loki/rules/security.rules.yaml +++ b/stacks/observability/loki/rules/security.rules.yaml @@ -970,14 +970,20 @@ groups: # The `|=` comes first because the label filters below are true for a # line the regexp did not match: an absent label is "", which is # neither the switch LAN nor `homeassistant`. + # + # The address is captured as `login_from`, not `source`: every line on + # this path already carries source="network" from the listener, and + # Loki renames a capture that collides with a stream label to + # `_extracted`, so a filter on `source` would compare "network" + # and every login would fire. expr: | - sum by (user, source, via) ( + sum by (user, login_from, via) ( count_over_time( {host="neo"} |= " logged in from " - | regexp `user (?P\S+) logged in from (?P\S+) via (?P\S+)` - | source !~ `10\.7\.7\.[0-9]+|10\.0\.50\.90` - | user != "homeassistant" or source != "10.0.99.40" or via != "api" + | regexp `user (?P\S+) logged in from (?P\S+) via (?P\S+)` + | login_from !~ `10\.7\.7\.[0-9]+|10\.0\.50\.90` + | user != "homeassistant" or login_from != "10.0.99.40" or via != "api" [10m] ) ) > 0 @@ -988,7 +994,7 @@ groups: category: security annotations: runbook_url: "https://github.com/Gerrrt/HomeLab/blob/main/docs/runbooks/respond-to-a-security-alert.md#switchloginfromunexpectedsource" - summary: "neo: {{ $labels.user }} logged in from {{ $labels.source }} via {{ $labels.via }}" + summary: "neo: {{ $labels.user }} logged in from {{ $labels.login_from }} via {{ $labels.via }}" description: >- A login to the core switch from somewhere other than the switch LAN, desktop-02, or Home Assistant's read-only API user. Either a diff --git a/stacks/observability/loki/tests/security.test.yaml b/stacks/observability/loki/tests/security.test.yaml index e5e5724a0..4f0eb7a63 100644 --- a/stacks/observability/loki/tests/security.test.yaml +++ b/stacks/observability/loki/tests/security.test.yaml @@ -946,27 +946,27 @@ tests: - alert: SwitchLoginFromUnexpectedSource name: an admin login from Winterfell fires streams: - - labels: {log_type: syslog, host: neo, app: routeros, level: info} + - labels: {log_type: syslog, source: network, host: neo, app: routeros, level: info} entries: - before: 3m line: "system,info,account user gerrrt logged in from 10.0.99.20 via ssh" expect: - - {user: gerrrt, source: 10.0.99.20, via: ssh} + - {user: gerrrt, login_from: 10.0.99.20, via: ssh} - alert: SwitchLoginFromUnexpectedSource name: another user from Home Assistant's address fires streams: - - labels: {log_type: syslog, host: neo, app: routeros, level: info} + - labels: {log_type: syslog, source: network, host: neo, app: routeros, level: info} entries: - before: 3m line: "system,info,account user gerrrt logged in from 10.0.99.40 via api" expect: - - {user: gerrrt, source: 10.0.99.40, via: api} + - {user: gerrrt, login_from: 10.0.99.40, via: api} - alert: SwitchLoginFromUnexpectedSource name: the expected sources and ordinary lines do not streams: - - labels: {log_type: syslog, host: neo, app: routeros, level: info} + - labels: {log_type: syslog, source: network, host: neo, app: routeros, level: info} entries: - before: 5m line: "system,info,account user homeassistant logged in from 10.0.99.40 via api" @@ -992,7 +992,7 @@ tests: name: one heartbeat twenty minutes ago is enough window: 30m streams: - - labels: {log_type: syslog, host: neo, app: routeros, level: info} + - labels: {log_type: syslog, source: network, host: neo, app: routeros, level: info} entries: - before: 20m line: "script,info log heartbeat"