From 73b4a164e40f80385bdbedd0f8a1f280533186c1 Mon Sep 17 00:00:00 2001 From: patrick Date: Sat, 17 Oct 2026 13:13:03 -0400 Subject: [PATCH] Apply Ubuntu phasing in the agent's sandbox apt skips phasing in chroots, which it detects by running `ischroot -t`. ischroot compares / with /proc/1/root; the agent's DynamicUser can't read /proc/1/root, so ischroot answers "chroot" (-t = assume yes when unsure) and apt offered every phased update. On a real 26.04 host, 4 updates apt deferred as root were reported as installable, with 0 phased. Pass -o Dir::Bin::ischroot=/bin/false so apt applies phasing from /etc/machine-id exactly as it does for root. Agent 0.3.1, server 0.3.2. Co-Authored-By: Claude Opus 5.5 --- agent/kernelwatch-agent | 8 +++++++- server/kernelwatch/__init__.py | 4 ++-- tests/test_agent.py | 11 +++++++++++ 3 files changed, 20 insertions(+), 3 deletions(-) diff --git a/agent/kernelwatch-agent b/agent/kernelwatch-agent index 16e8797..7fa0307 100755 --- a/agent/kernelwatch-agent +++ b/agent/kernelwatch-agent @@ -6,7 +6,7 @@ # rules can change without redeploying agents. set -euo pipefail -AGENT_VERSION=0.3.0 +AGENT_VERSION=0.3.1 # Prefix for every file the agent reads. Only the test suite sets this. ROOT=${KERNELWATCH_ROOT:-} @@ -154,8 +154,14 @@ read_needrestart() { # Simulated dist-upgrade. Reads only: no locks, no cache files written. # dist-upgrade (not upgrade) so new-ABI kernel packages pulled in by the # meta-package show up. C locale because we parse apt's messages. +# +# apt skips phasing in chroots, detected with `ischroot -t`, which compares / +# with /proc/1/root. Unprivileged we can't read /proc/1/root, so ischroot +# answers "chroot" and apt would offer every phased update. We're not in one: +# say so, and apt applies phasing from /etc/machine-id like it does for root. apt_simulation() { LC_ALL=C apt-get -s -q \ + -o Dir::Bin::ischroot=/bin/false \ -o Debug::NoLocking=true \ -o Dir::Cache::pkgcache= \ -o Dir::Cache::srcpkgcache= \ diff --git a/server/kernelwatch/__init__.py b/server/kernelwatch/__init__.py index 54cddf9..3e7fc25 100644 --- a/server/kernelwatch/__init__.py +++ b/server/kernelwatch/__init__.py @@ -1,7 +1,7 @@ """kernelwatch: fleet kernel and reboot status dashboard.""" -__version__ = "0.3.1" +__version__ = "0.3.2" # Version of agent/kernelwatch-agent shipped alongside this server; older agents # are noted on the dashboard. tests/test_status.py checks the two stay in sync. -AGENT_VERSION = "0.3.0" +AGENT_VERSION = "0.3.1" diff --git a/tests/test_agent.py b/tests/test_agent.py index b26a504..1d59b30 100644 --- a/tests/test_agent.py +++ b/tests/test_agent.py @@ -198,6 +198,17 @@ X ["libnss-systemd", "libpam-systemd", "libsystemd-shared", "libsystemd0", "libudev1", "systemd", "systemd-resolved", "udev"])) + def test_apt_told_it_is_not_in_a_chroot(self): + # Otherwise unprivileged apt thinks it's in a chroot and ignores phasing + # (seen on a real 26.04 host: 4 phased updates counted as installable). + stub(self.bin, "apt-get", 'case "$*" in *Dir::Bin::ischroot=/bin/false*) ;; *) exit 1;; esac\n' + 'echo "The following upgrades have been deferred due to phasing:"\n' + 'echo " snapd open-vm-tools"\n' + 'echo "0 upgraded, 0 newly installed, 0 to remove and 2 not upgraded."\n') + r = self.report() + self.assertEqual(r["phased_packages"], ["open-vm-tools", "snapd"]) + self.assertEqual(r["upgradable_count"], 0) + def test_apt_runs_in_c_locale(self): stub(self.bin, "apt-get", 'echo "Inst locale-$LC_ALL [1] (2 x [amd64])"\n') self.assertEqual(self.report()["upgradable_count"], 1)