Run the agent unprivileged; detect in-place kernel upgrades

The agent ran as (capability-less) root only so needrestart could read
Ubuntu's root-only /boot images. Switch the unit to DynamicUser=yes and
make needrestart optional.

To cover the case needrestart was catching (running kernel's package
upgraded in place, same uname -r), the agent now reports the installed
package version of the running kernel and the server compares it with
the build in uname -v: "Debian 6.12.57-1" vs 6.12.57-1 on Debian,
"#85-Ubuntu" / "#33~24.04.1-Ubuntu" vs the upload part of 6.8.0-85.85 /
6.14.0-33.33~24.04.1 on Ubuntu. Unrecognised builds fall back to
needrestart and the newest-installed comparison.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
patrickandClaude Opus 5.5 committed 2026-10-17 10:19:41 -04:00
1 parent 07749b01b0
commit 48f2d155af
9 files changed
+109 -23

No files matched your search

+14 -11
View File
@@ -35,12 +35,16 @@ its full report and recent history.
How the agent works it out:
- **Running vs. installed kernel**: if [`needrestart`](https://github.com/liske/needrestart)
is installed, the agent uses `needrestart -b -k`, which also catches
ABI-compatible upgrades where the package name stays the same. Otherwise it
compares `uname -r` with the newest installed `linux-image-*` package.
Ubuntu 24.04 ships needrestart by default. **On Debian, install it**
(`apt install needrestart`) for accurate results.
- **Running vs. installed kernel**, three ways:
- A newer `linux-image-*` installed than `uname -r` means a version upgrade.
- The build in `uname -v` (`Debian 6.12.57-1`, `#85-Ubuntu`, `#33~24.04.1-Ubuntu`)
is compared with the installed package version of the running kernel
(`6.12.57-1`, `6.8.0-85.85`, `6.14.0-33.33~24.04.1`). A mismatch means the
package was upgraded in place after boot; `uname -r` didn't change, but a
reboot is still needed.
- [`needrestart`](https://github.com/liske/needrestart) `-b -k`, when it's
installed and can read `/boot`. It's optional. The agent runs unprivileged, so
on Ubuntu (root-only `/boot/vmlinuz-*`) it reports "unknown" and is ignored.
- **Available updates**: a simulated `apt-get dist-upgrade`. It is read-only, takes
no locks and writes no cache files. `dist-upgrade` is used so that new-ABI kernel
packages pulled in by the meta-package show up. Lines whose origin contains
@@ -152,11 +156,10 @@ sudo kernelwatch list-users
- **Host identity comes from the token, not the payload.** A host can only
report as itself. Tokens are 256-bit random values; only their SHA-256 is stored.
- **The agent** runs from a systemd unit with an empty capability set, a
read-only filesystem view and a syscall filter. It runs as uid 0 only because
Ubuntu's `/boot/vmlinuz-*` files are root-only, and needrestart has to read
them. The token reaches it through `LoadCredential=` and goes to curl on stdin,
so it never appears in a process listing.
- **The agent** runs as a throwaway unprivileged user (`DynamicUser=yes`) with
no capabilities, a read-only filesystem view and a syscall filter. The token
reaches it through `LoadCredential=` and goes to curl on stdin, so it never
appears in a process listing.
- **The dashboard** uses scrypt-hashed passwords, server-side sessions,
`HttpOnly` + `Secure` + `SameSite=Strict` cookies, an Origin check on form
posts, per-IP login rate limiting, and a strict CSP. Everything a host