Fix apt refresh on apt 2.7+ and check the security repository #30
No files matched your search
@@ -10,16 +10,25 @@ After=network-online.target
|
|||||||
[Service]
|
[Service]
|
||||||
Type=oneshot
|
Type=oneshot
|
||||||
# Same as `apt-get update`: downloads lists, installs nothing. A failure (no
|
# 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
|
# network, lock held by an admin's apt run) fails this unit but not the report,
|
||||||
# dashboard flags lists that stay old.
|
# since kernelwatch-agent.service only Wants= it. The stamp then stops moving
|
||||||
ExecStart=-/usr/bin/apt-get -q update
|
# 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
|
TimeoutStartSec=5min
|
||||||
Nice=10
|
Nice=10
|
||||||
IOSchedulingClass=idle
|
IOSchedulingClass=idle
|
||||||
|
|
||||||
# apt needs root to write /var/lib/apt and drops to _apt for downloads, so this
|
# 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.
|
# runs as root (the default) but loses everything apt update doesn't touch.
|
||||||
User=root
|
# 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
|
NoNewPrivileges=yes
|
||||||
ProtectHome=yes
|
ProtectHome=yes
|
||||||
PrivateTmp=yes
|
PrivateTmp=yes
|
||||||
|
|||||||
+12
-1
@@ -310,11 +310,22 @@ class PackagingTest(unittest.TestCase):
|
|||||||
def test_apt_update_is_opt_in_and_runs_before_reports(self):
|
def test_apt_update_is_opt_in_and_runs_before_reports(self):
|
||||||
unit = self.read("kernelwatch-apt-update.service")
|
unit = self.read("kernelwatch-apt-update.service")
|
||||||
self.assertIn("ConditionPathExists=/etc/kernelwatch/apt-update", unit)
|
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")
|
agent = self.read("kernelwatch-agent.service")
|
||||||
for key in ("Wants=", "After="):
|
for key in ("Wants=", "After="):
|
||||||
line = next(l for l in agent.splitlines() if l.startswith(key))
|
line = next(l for l in agent.splitlines() if l.startswith(key))
|
||||||
self.assertIn("kernelwatch-apt-update.service", line)
|
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__":
|
if __name__ == "__main__":
|
||||||
|
|||||||
Reference in new issue
Block a user