Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions docs/changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,35 @@ docstring gives: it is a record, not a claim about now.

## 2026-11-22

- **`gandalf`'s power-off timer is built, not installed
([#1647](https://github.com/Gerrrt/HomeLab/issues/1647)).** This builds
ADR-0124 in the repository. `scripts/range-poweroff.sh` holds the deadline
under `/run`, sends the 30- and 5-minute `wall` warnings, waits while `dpkg`
holds its lock, and powers off. Linked as `range-extend`, it sets the
deadline 1 to 12 hours from now. `systemd/range/` runs it every
minute. `check` and `extend` hold one lock, so a check never acts on a
deadline an extension has just replaced. Review on the PR caught both: a
five-minute timer could skip the last warning, and the unlocked version
could act on a replaced deadline. `build-the-playground.md` §7 gains *The
power-off timer*, which installs it from Hicks with a `range-extend 6`
first, so an install on a box already up six hours does not power it off a
minute later. The read-back checks the timer is enabled and active.
- The `--self-test` has 21 fixtures, and `self-tests.sh` runs it in CI.
The two lock interleavings skip where there is no `flock`, as on macOS.
- Four deliberate breaks each failed at least one fixture: no `dpkg` wait,
no extension cap, no 5-minute warning, and no lock.
- It passed under `gandalf`'s own bash, run from standard input without
installing anything.
- `systemd-analyze verify` on `gandalf` reported only that the script was
not installed yet.

It was installed on `gandalf` the same evening at 17:44, from this
branch, by §7's commands: `self-test-ok`, a deadline of 23:44, and a run
by hand ending `Result=success`. The timer read `enabled` and `active`.
The every-minute timer and the lock were reinstalled the same way after
review.
The one-power-off proof in §7 has not been run.

- **`gandalf` will power itself off on a timer
([ADR-0124](adr/0124-power-gandalf-off-on-a-timer.md)).** Both audits of
`gandalf` found it left on for days, `ragnarok` included, against the
Expand Down
8 changes: 5 additions & 3 deletions docs/roadmap.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,11 @@ Closes when it is empty.

- **[#1647](https://github.com/Gerrrt/HomeLab/issues/1647) Power `gandalf`
off on a timer.** Decided by
[ADR-0124](adr/0124-power-gandalf-off-on-a-timer.md). No gate. Until it is
built, the range's "off between sessions" rests on the operator, and two
audits found it left on.
[ADR-0124](adr/0124-power-gandalf-off-on-a-timer.md). No gate. The script
and its units are in the repository and installed on `gandalf`. Left: prove
one power-off, `build-the-playground.md` §7. Until then the
range's "off between sessions" rests on the operator, and two audits found
it left on.
- **[#1226](https://github.com/Gerrrt/HomeLab/issues/1226) The HomePods in
Home Assistant, for control.** Decided by
[ADR-0099](adr/0099-control-the-homepods-from-home-assistant-and-leave-their-audio-out.md).
Expand Down
77 changes: 72 additions & 5 deletions docs/runbooks/build-the-playground.md
Original file line number Diff line number Diff line change
Expand Up @@ -1080,14 +1080,15 @@ Two audits found the box left on for days anyway (2026-11-13 and 2026-11-22).
[ADR-0124](../adr/0124-power-gandalf-off-on-a-timer.md) takes the backstop
off the person: a timer on the host powers it off at a deadline, six hours
after boot by default or what the last `range-extend` set (1 to 12 hours
ahead), with a warning on every shell 30 and 5 minutes
before. **It is decided and not built yet**
([#1647](https://github.com/Gerrrt/HomeLab/issues/1647)). Until it is, the
power-off at the end below is still yours alone. Once it is built, this
section installs it and the read-back checks it is enabled.
ahead), with a warning on every shell 30 and 5 minutes before
([#1647](https://github.com/Gerrrt/HomeLab/issues/1647)). The power-off at
the end below is still the plan. The timer is what happens when the plan is
forgotten. Installed on `gandalf` on 2026-11-22, below.

```text
on → read the firewall back → revert every target to `clean` → work → revert → off
↑
6 h after boot or the last range-extend → off, by itself
```

**Read the firewall back before anything else.** The collector and the alerts
Expand All @@ -1107,6 +1108,11 @@ print `1`. Anything else means the session does not start until §2's lines
have been rerun and checked in `/etc/network/interfaces`.
`ls /etc/apt/sources.list.d/` should list Debian's and Proxmox's sources
only (§4, *Nothing else on `gandalf`*).
`systemctl is-enabled homelab-range-poweroff.timer; systemctl is-active
homelab-range-poweroff.timer` should read `enabled` and `active`, and
`homelab-range-poweroff status` should show a deadline in the future. A
disabled timer puts the range back on discipline alone (ADR-0124), so the
session does not start until *The power-off timer* above has been rerun.

**Then check Proxmox's own updates.** `unattended-upgrades` covers Debian's
packages only (§4, *Services on `gandalf`*). `apt update && apt list
Expand All @@ -1117,6 +1123,67 @@ installed a `proxmox-kernel-*` package, or `/run/reboot-required` exists,
reboot and start this section again from the top. The firewall read-back runs
again too, since a reboot is a fresh power-on.

### The power-off timer

Install it once, from a Hicks workstation in a checkout of this repository.
It is three files and a symlink, and nothing else on the host changes:

```bash
G=root@10.0.30.30
ssh "$G" 'install -d -m 0755 /usr/local/sbin'
scp scripts/range-poweroff.sh "$G":/usr/local/sbin/homelab-range-poweroff
scp systemd/range/homelab-range-poweroff.service systemd/range/homelab-range-poweroff.timer "$G":/etc/systemd/system/
ssh "$G" 'chmod 0755 /usr/local/sbin/homelab-range-poweroff &&
chmod 0644 /etc/systemd/system/homelab-range-poweroff.* &&
ln -sf /usr/local/sbin/homelab-range-poweroff /usr/local/sbin/range-extend &&
homelab-range-poweroff --self-test >/dev/null && echo self-test-ok &&
range-extend 6 &&
systemd-analyze verify /etc/systemd/system/homelab-range-poweroff.service &&
systemctl daemon-reload && systemctl enable --now homelab-range-poweroff.timer &&
homelab-range-poweroff status'
```

**You should see** `self-test-ok`, no output from `systemd-analyze`, and a
deadline six hours from now. The `range-extend 6` before the enable is
deliberate. Without it the deadline is six hours after *this* boot, and on a
box that has been up longer than that, the first run powers it off a
minute after the install. The self-test exercises every branch with
fakes, so it can run on the host without powering anything off.

Running it, as root on `gandalf`:

| | |
| --- | --- |
| `homelab-range-poweroff status` | The deadline and the minutes left |
| `range-extend 3` | Set the deadline three hours from now. 1 to 12. It can also bring the deadline closer |
| `journalctl -t homelab-range-poweroff` | Every warning, extension, wait and power-off |

At 30 minutes and again at 5, every shell on the host gets a `wall` message
that says how to extend. Past the deadline the next run powers off, unless
`dpkg` holds its lock. Then it waits for the run after that. Nothing reaches
the Proxmox web UI, so a session driven only from `8006` gets no warning.
Check `status` from a shell when you start one.

**Prove it once after installing**, with a session you can afford to lose:

1. `range-extend 1`, then check `status` reads about 60 minutes.
2. Keep an SSH session open. The 30- and 5-minute `wall` messages should
reach it.
3. Start one guest. At the deadline the box should power itself off, and
`journalctl -t homelab-range-poweroff -b -1` at the next power-on should
end with `powering gandalf off`.

> **Installed on `gandalf` 2026-11-22 at 17:44**, from #1649's branch
> before it merged, by the commands above. The output was `self-test-ok`,
> nothing from `systemd-analyze`, and a deadline of 23:44. A run of the
> service by hand ended `Result=success`. The timer read `enabled` and
> `active`, with its next run five minutes out. That install had the first
> timer, every five minutes. Review on #1649 moved it to every minute and
> added the lock. The new files were reinstalled the same way, and the
> self-test ran 21 fixtures on the box.

Record the proof's result here. **Not yet run on `gandalf`.**

---

## 8. Check the four properties
Expand Down
1 change: 1 addition & 0 deletions scripts/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,7 @@ They need the running estate, so CI cannot run them. Timers do.
| `capture-screenshots.sh` | `screenshots` | Renders the dashboards into [`docs/images/`](../docs/images/README.md) |
| `packer-smoke.sh` | — | Clones a Packer template, boots it, checks it and destroys it ([`packer/`](../packer/README.md)) |
| `finish-attack-vm.sh` | — | Finishes the range's attack VM, `ragnarok`, after `tofu/` makes it on `gandalf` from 902 ([ADR-0116](../docs/adr/0116-build-the-range-attack-vm-with-opentofu-and-prove-it-with-a-script.md)): writes `99-no-forward.conf` and ADR-0014's outbound scope as an nftables policy, at the IP stack and at `eth0`'s egress for raw Ethernet, and proves it neither forwards, NATs nor reaches past `10.0.30.0/24` and the range, over SSH checked against a host key read through the guest agent ([`build-the-playground.md`](../docs/runbooks/build-the-playground.md) §5) |
| `range-poweroff.sh` | — | Powers `gandalf` off at a deadline, six hours after boot or what the last `range-extend` set (1 to 12 hours ahead), checked every minute under one lock, warning on every shell at 30 and 5 minutes, and never while `dpkg` holds its lock ([ADR-0124](../docs/adr/0124-power-gandalf-off-on-a-timer.md)). Installed with [`systemd/range/`](../systemd/range) by [`build-the-playground.md`](../docs/runbooks/build-the-playground.md) §7. Its `--self-test` is the only test of the deadline logic: a real run powers the range host off |
| `stage-agent-msis.sh` | — | Stages the Wazuh and Velociraptor MSIs the lab pipeline installs, and the two Debian packages `garuda` installs, into `${SOC_DATA_DIR}/agent-msi` on `odin`, which the SOC stack's Caddy serves. The vendor packages are checked against their pins; the Velociraptor `.deb` is built by the server and its hash printed ([#1068](https://github.com/Gerrrt/HomeLab/issues/1068), [ADR-0092](../docs/adr/0092-enrol-garuda-in-odins-soc-with-debian-packages-staged-on-odin.md)) |
| `lab-known-hosts.sh` | — | Reads the lab domain's SSH host keys through the guest agent into `ansible/.known_hosts`, after any rebuild ([ADR-0085](../docs/adr/0085-check-the-lab-domains-host-keys-against-keys-read-through-the-guest-agent.md)) |
| `gen_population.py` | — | The lab domain's users, into `ansible/population/` |
Expand Down
Loading