readings-window
aien-dev/readings-window
Brought by drakestapleton
GitHub aien-dev/readings-window#2 (code only)
Apply it
git checkout -b patch-ee49e8aa7f832e6a 254f9acf5c43f6a24d0d9add5f5203a02b377cf3 curl -fsSL https://interplane.io/drakestapleton/readings-window/patches/ee49e8aa7f832e6a.patch | git am
Provenance
github-import 1
aien-dev/readings-window
2
8cd99929baaca4ccefb5a82a62b096eacbb769c2
{"kind":"github-import","owner":"aien-dev","repo":"readings-window","number":2,"url":"https://github.com/aien-dev/readings-window/pull/2","export_sha256":"967c79e26a893657b5cdaa45efd442be5dbd2ecfe68e25f9a8c1b5da4d60d452","imported_utc":"2026-11-18T16:40:29Z","metadata":"unavailable","state_derived":true}
Changes
diff --git a/.crumb b/.crumb index 6b06c6b..a9f6980 100644 --- a/.crumb +++ b/.crumb @@ -13,7 +13,7 @@ "generated": { "children": [ { - "digest": "8de654ee8668d45e418ecbd819d728be14048b313004d939fc2dce7501e5c2fa", + "digest": "fe8b6360c2144daa08e8dbb644b31829295074c853975b6ed6efd62f53978d63", "last_commit": "d910ecb", "name": "scripts", "purpose": "Directory scripts. Purpose not yet described by a human." @@ -25,15 +25,15 @@ "purpose": "Directory src. Purpose not yet described by a human." } ], - "children_root": "sha256:a45c5b9cdd45beb6ee01b85df15800509a639ed4b73198e9354de38df03ad84f", - "compiled_at": "2026-10-04T15:57:57Z", + "children_root": "sha256:2370aabb1416026f33dae6c6c8894d5d5a4d49273fb6eb98f82838bac1aca5f0", + "compiled_at": "2026-10-04T16:19:23Z", "compiler": "crumb-compile/1", - "digest": "sha256:4ef4b1a658c7f74fd2faf537c4608f97de587daf1a32e1668e085f29cf17a423", + "digest": "sha256:caac4cc67120988c5a85c0ad0103060a7d0c127436d3ca0e60c9bacf831f6402", "evidence_files": 0, "evidence_root": "sha256:e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", "files": 10, - "generated_at_commit": "307efd088093ff9dce1c3833ffbb51d6f0171e90", - "source_tree": "sha256:db6dc1a6dc5f1d17652c1e525458085fac19749526d8c079f8456b7ae6474f8e" + "generated_at_commit": "254f9acf5c43f6a24d0d9add5f5203a02b377cf3", + "source_tree": "sha256:fbeda7336b9b050cffca5b5b4c095fa5268e8325703dce66f43e6731e72fc006" }, "owner_lane": "", "seed": { diff --git a/README.md b/README.md index 590afaf..9fdef56 100644 --- a/README.md +++ b/README.md @@ -13,7 +13,7 @@ A small Rust service: it collects one JSON line of readings from the Spark every - `readings-window collect`: fetch one reading from the Spark and append it to the history file. - `readings-window serve`: HTTPS server on port 9443. -`scripts/` holds the exposure watch (a timer that checks what the house exposes to the internet, scanning only our own public IP). +`scripts/` holds the exposure watch: a 15-minute timer that scans our own public IP from inside the LAN (the router hairpin view, which is not the same as the internet view) and flags any change against an accepted baseline in `/etc/exposure-watch/baseline.json`. Operational notes, unit names and the deployment layout are in `NOTES.md`. Build: `cargo build --release`. No Python. License: Apache-2.0. diff --git a/scripts/.crumb b/scripts/.crumb index 47a5aab..b6498e9 100644 --- a/scripts/.crumb +++ b/scripts/.crumb @@ -7,14 +7,14 @@ "generated": { "children": [], "children_root": "sha256:e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", - "compiled_at": "2026-10-04T15:56:29Z", + "compiled_at": "2026-10-04T16:19:23Z", "compiler": "crumb-compile/1", - "digest": "sha256:8de654ee8668d45e418ecbd819d728be14048b313004d939fc2dce7501e5c2fa", + "digest": "sha256:fe8b6360c2144daa08e8dbb644b31829295074c853975b6ed6efd62f53978d63", "evidence_files": 0, "evidence_root": "sha256:e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", "files": 3, - "generated_at_commit": "d910ecbfcd8224bc8520bdeda3ecc172fe69d6f5", - "source_tree": "sha256:6291570551e299211513a4d37f46eb08fe38363c1d3b6f3567f82d1479076231" + "generated_at_commit": "254f9acf5c43f6a24d0d9add5f5203a02b377cf3", + "source_tree": "sha256:3fe5648cbd2fb7d2d103c726d2d3eeaf659163d0f866f0df525115595c75143d" }, "owner_lane": "", "seed": { diff --git a/scripts/exposure-watch.sh b/scripts/exposure-watch.sh index 8d186b8..896ea9e 100644 --- a/scripts/exposure-watch.sh +++ b/scripts/exposure-watch.sh @@ -1,5 +1,7 @@ #!/bin/bash -# exposure-watch: checks what the house exposes to the internet; writes exposure.json. Scans ONLY our own public IP. +# exposure-watch: what the house shows on its public IP, scanned from INSIDE the LAN (router hairpin view). Scans ONLY our own public IP. +# Inside view != internet view: the router answers its own 53/80 and reflects LAN-only forwards (e.g. 9443). Baseline holds the accepted inside view; Ports in optional_tcp may come and go without alarming (the router's own 53/80 flicker in the hairpin view). +# the real outside view is a separate, occasional check (check-host.net or similar). A change here means "something on the router or LAN moved", not proof of exposure. export PATH=/usr/sbin:/usr/bin:/sbin:/bin OUT=/var/lib/readings-window/exposure.json STATE=/var/lib/exposure-watch @@ -25,11 +27,13 @@ fi # baseline (first run creates it from the expected lists) if [ ! -s "$BASE" ]; then - echo '{"expected_tcp":[443,9443],"expected_udp":[3478]}' > "$BASE" + echo '{"vantage":"lan-hairpin","expected_tcp":[443,9443],"optional_tcp":[53,80],"expected_udp":[3478],"note":"inside view; outside check 2026-10-04 (check-host.net) showed only 443/tcp"}' > "$BASE" log "baseline created" fi exp_tcp=$(grep -o '"expected_tcp":\[[^]]*\]' "$BASE" | grep -o '[0-9]\+' | sort -n | tr '\n' ' ') exp_udp=$(grep -o '"expected_udp":\[[^]]*\]' "$BASE" | grep -o '[0-9]\+' | sort -n | tr '\n' ' ') +opt_tcp=$(grep -o '"optional_tcp":\[[^]]*\]' "$BASE" | grep -o '[0-9]\+' | sort -n | tr '\n' ' ') +base_note=$(grep -o '"note":"[^"]*"' "$BASE" | sed 's/^"note":"//; s/"$//') # b. scans PORTS="1-1024,1194,1723,2222,3000,3010,3389,4433,5000,5900,8000,8080,8443,9443,10443,18443,41641,50443" @@ -72,9 +76,9 @@ done # e. compare changes=() fmt() { echo "$*" | xargs; } -for p in $open_tcp; do [[ " $exp_tcp" == *" $p "* ]] || changes+=("TCP port $p is open to the internet and is not expected."); done -for p in $exp_tcp; do [[ " $open_tcp" == *" $p "* ]] || changes+=("Expected TCP port $p is not reachable from outside."); done -for p in $open_udp; do [[ " $exp_udp" == *" $p "* ]] || changes+=("UDP port $p is open to the internet and is not expected."); done +for p in $open_tcp; do [[ " $exp_tcp" == *" $p "* || " $opt_tcp" == *" $p "* ]] || changes+=("TCP port $p is open in the inside view and is not in the baseline."); done +for p in $exp_tcp; do [[ " $open_tcp" == *" $p "* ]] || changes+=("Baseline TCP port $p is not reachable in the inside view."); done +for p in $open_udp; do [[ " $exp_udp" == *" $p "* ]] || changes+=("UDP port $p is open in the inside view and is not in the baseline."); done [ "$upnp" = on ] && changes+=("The router answers UPnP, so devices could open ports by themselves.") [ -n "$mappings" ] && changes+=("The router lists UPnP port mappings.") [ "$dns_ok" = false ] && changes+=("DNS does not match the public IP $ip:$dns_detail.") @@ -85,8 +89,8 @@ jarr() { local o="" x; for x in "$@"; do o="$o${o:+,}$x"; done; echo "[$o]"; } sarr() { local o="" x; for x in "$@"; do o="$o${o:+,}\"$x\""; done; echo "[$o]"; } mapjson=$(printf '%s\n' "$mappings" | sed '/^$/d' | sed 's/^/"/; s/$/"/' | paste -sd, -) chjson=""; for c in "${changes[@]}"; do chjson="$chjson${chjson:+,}\"${c//\"/\\\"}\""; done -json=$(printf '{"ts":%s,"public_ip":"%s","open_tcp":%s,"open_udp":%s,"upnp":"%s","upnp_mappings":[%s],"dns_ok":%s,"expected_tcp":%s,"expected_udp":%s,"status":"%s","changes":[%s]}' \ - "$ts" "$ip" "$(jarr $open_tcp)" "$(jarr $open_udp)" "$upnp" "$mapjson" "$dns_ok" "$(jarr $exp_tcp)" "$(jarr $exp_udp)" "$status" "$chjson") +json=$(printf '{"ts":%s,"vantage":"lan-hairpin","baseline_note":"%s","public_ip":"%s","open_tcp":%s,"open_udp":%s,"upnp":"%s","upnp_mappings":[%s],"dns_ok":%s,"expected_tcp":%s,"optional_tcp":%s,"expected_udp":%s,"status":"%s","changes":[%s]}' \ + "$ts" "${base_note//\"/}" "$ip" "$(jarr $open_tcp)" "$(jarr $open_udp)" "$upnp" "$mapjson" "$dns_ok" "$(jarr $exp_tcp)" "$(jarr $opt_tcp)" "$(jarr $exp_udp)" "$status" "$chjson") echo "$json" > "$OUT.tmp" && chmod 644 "$OUT.tmp" && mv "$OUT.tmp" "$OUT" [ "$status" = changed ] && echo "$json" >> "$STATE/alerts.log" log "status=$status end $(date -u +%FT%TZ)"