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
2 changed files with 26 additions and 6 deletions
Showing only changes of commit 195fd035e0 - Show all commits

No files matched your search

+14 -5
View File
@@ -10,16 +10,25 @@ After=network-online.target
[Service]
Type=oneshot
# Same as `apt-get update`: downloads lists, installs nothing. A failure (no
# network, lock held by an admin's apt run) mustn't stop the report; the
# dashboard flags lists that stay old.
ExecStart=-/usr/bin/apt-get -q update
# network, lock held by an admin's apt run) fails this unit but not the report,
# since kernelwatch-agent.service only Wants= it. The stamp then stops moving
# and the dashboard flags the lists as old.
ExecStart=/usr/bin/apt-get -q update
# Reached only when apt succeeded. It's the stamp Ubuntu's update-notifier hook
# writes after every successful apt update, and the agent reads it as the lists'
# age; Debian has nothing else that writes it. lists/partial, the agent's last
# resort, changes even when the update fails.
ExecStartPost=/bin/sh -c 'mkdir -p /var/lib/apt/periodic && touch /var/lib/apt/periodic/update-success-stamp'
TimeoutStartSec=5min
Nice=10
IOSchedulingClass=idle
# apt needs root to write /var/lib/apt and drops to _apt for downloads, so this
# keeps root but loses everything apt update doesn't touch.
User=root
# runs as root (the default) but loses everything apt update doesn't touch.
# Don't add User=root: with it, NoNewPrivileges and any of the seccomp-based
# options below, apt 2.7+ (Ubuntu 24.04, Debian 13) can't switch to _apt
# ("seteuid 42 failed - seteuid (1: Operation not permitted)") and every update
# fails.
NoNewPrivileges=yes
ProtectHome=yes
PrivateTmp=yes
+12 -1
View File
@@ -310,11 +310,22 @@ class PackagingTest(unittest.TestCase):
def test_apt_update_is_opt_in_and_runs_before_reports(self):
unit = self.read("kernelwatch-apt-update.service")
self.assertIn("ConditionPathExists=/etc/kernelwatch/apt-update", unit)
self.assertIn("ExecStart=-/usr/bin/apt-get -q update", unit, "failure mustn't block the report")
self.assertIn("\nExecStart=/usr/bin/apt-get -q update\n", unit,
"a failed update must fail the unit, so ExecStartPost doesn't mark it fresh")
post = next(l for l in unit.splitlines() if l.startswith("ExecStartPost="))
self.assertIn("touch /var/lib/apt/periodic/update-success-stamp", post)
agent = self.read("kernelwatch-agent.service")
for key in ("Wants=", "After="):
line = next(l for l in agent.splitlines() if l.startswith(key))
self.assertIn("kernelwatch-apt-update.service", line)
self.assertNotRegex(agent, r"(?m)^(Requires|Requisite|BindsTo)=.*kernelwatch-apt-update",
"a failed apt update mustn't stop the report")
def test_apt_update_runs_as_root_without_user_root(self):
# User=root plus NoNewPrivileges plus any seccomp-based option stops apt 2.7+
# dropping to _apt, so every update fails. Root is the default anyway.
unit = self.read("kernelwatch-apt-update.service")
self.assertNotRegex(unit, r"(?m)^(User|DynamicUser)=")
if __name__ == "__main__":