Fix apt refresh on apt 2.7+ and check the security repository #30

Merged
patrick merged 3 commits from feat/security-repo-check into main 2026-11-01 20:08:36 +00:00
3 changed files with 34 additions and 8 deletions
Showing only changes of commit fa6cca4f64 - Show all commits

No files matched your search

+9 -5
View File
@@ -228,18 +228,22 @@ phased_packages() {
} }
# Seconds since apt last refreshed its package lists, or empty if unknown. # Seconds since apt last refreshed its package lists, or empty if unknown.
# Both stamps are touched only after a successful update: update-success-stamp by
# Ubuntu's update-notifier hook and kernelwatch-apt-update.service, update-stamp by
# apt-daily. lists/partial changes on every attempt, failed ones too, so it's only
# a last resort for hosts that have neither (Debian without either timer).
apt_lists_age() { apt_lists_age() {
local newest=0 f m local newest=0 f m
for f in \ for f in \
"$ROOT/var/lib/apt/periodic/update-success-stamp" \ "$ROOT/var/lib/apt/periodic/update-success-stamp" \
"$ROOT/var/lib/apt/periodic/update-stamp" \ "$ROOT/var/lib/apt/periodic/update-stamp"; do
"$ROOT/var/lib/apt/lists/partial"; do
[[ -e $f ]] || continue
m=$(stat -c %Y "$f" 2>/dev/null) || continue m=$(stat -c %Y "$f" 2>/dev/null) || continue
((m > newest)) && newest=$m ((m > newest)) && newest=$m
done done
((newest > 0)) && printf '%s' $(($(date +%s) - newest)) if ((newest == 0)); then
return 0 newest=$(stat -c %Y "$ROOT/var/lib/apt/lists/partial" 2>/dev/null) || return 0
fi
printf '%s' $(($(date +%s) - newest))
} }
# Size and free space of the filesystem holding /boot, in KiB, as "SIZE FREE"; # Size and free space of the filesystem holding /boot, in KiB, as "SIZE FREE";
+8 -3
View File
@@ -141,9 +141,14 @@ How the agent works it out:
list also on the host page. list also on the host page.
They never affect status, because Ubuntu doesn't phase security updates and They never affect status, because Ubuntu doesn't phase security updates and
there's nothing to act on until apt offers them. there's nothing to act on until apt offers them.
- **Package list freshness**: the mtime of apt's update stamps. The agent - **Package list freshness**: the mtime of apt's success stamps,
**doesn't run `apt update`** itself; it relies on the stock `apt-daily.timer`. `update-success-stamp` (Ubuntu, and `kernelwatch-apt-update.service`) and
If that's disabled, the host shows `update` with "package lists N days old". `update-stamp` (`apt-daily`), both in `/var/lib/apt/periodic/` and touched
only when `apt update` succeeds. A host with neither falls back to
`/var/lib/apt/lists/partial`, which changes on failed updates too. The agent
**doesn't run `apt update`** itself; it relies on `apt-daily.timer` or
`--with-apt-update`. If the lists stop refreshing, the host shows `update`
with "package lists N days old".
The agent sends raw facts and the server decides what they mean, so you can The agent sends raw facts and the server decides what they mean, so you can
change the status rules without touching the agents. change the status rules without touching the agents.
+17
View File
@@ -446,6 +446,23 @@ X
os.remove(os.path.join(self.root, "var/lib/apt/periodic/update-success-stamp")) os.remove(os.path.join(self.root, "var/lib/apt/periodic/update-success-stamp"))
self.assertIsNone(self.report()["apt_lists_age_seconds"]) self.assertIsNone(self.report()["apt_lists_age_seconds"])
def test_newest_success_stamp_wins(self):
self.write_root("var/lib/apt/periodic/update-stamp", age=600)
self.assertAlmostEqual(self.report()["apt_lists_age_seconds"], 600, delta=60)
def test_failed_updates_touching_partial_dont_count_as_fresh(self):
# apt touches lists/partial even when the update fails.
os.makedirs(os.path.join(self.root, "var/lib/apt/lists/partial"))
self.assertAlmostEqual(self.report()["apt_lists_age_seconds"], 7200, delta=60)
def test_partial_is_the_last_resort_without_stamps(self):
os.remove(os.path.join(self.root, "var/lib/apt/periodic/update-success-stamp"))
partial = os.path.join(self.root, "var/lib/apt/lists/partial")
os.makedirs(partial)
t = time.time() - 3600
os.utime(partial, (t, t))
self.assertAlmostEqual(self.report()["apt_lists_age_seconds"], 3600, delta=60)
def test_send_without_config_fails_cleanly(self): def test_send_without_config_fails_cleanly(self):
proc = self.run_agent() proc = self.run_agent()
self.assertNotEqual(proc.returncode, 0) self.assertNotEqual(proc.returncode, 0)