Check that the release's security repository is configured and fresh
CI / tests (Python 3.10) (pull_request) Successful in 36s
CI / tests (Python 3.11) (pull_request) Successful in 36s
CI / tests (Python 3.12) (pull_request) Successful in 37s
CI / tests (Python 3.13) (pull_request) Successful in 37s
CI / lint (pull_request) Successful in 4s
CI / tests (Python 3.10) (pull_request) Successful in 36s
CI / tests (Python 3.11) (pull_request) Successful in 36s
CI / tests (Python 3.12) (pull_request) Successful in 37s
CI / tests (Python 3.13) (pull_request) Successful in 37s
CI / lint (pull_request) Successful in 4s
security_count is only meaningful if apt has the release's security suite. A host missing it from its sources shows 0 security updates forever, and one whose apt can't fetch it (expired key, wrong URL after a release upgrade, a mirror that fell behind) keeps the last copy while the update stamps and other lists move on, so neither the simulation nor the package list age notices. The agent (0.9.0) now finds apt's list for <codename>-security by its Suite: (Ubuntu) or Codename: (Debian) field, since file names depend on the mirror (mirror+file: sources, several mirrors), and reports security_repo_suite and security_repo_age_seconds from its Date:, the newest copy winning. The server puts the host in update when there's no such list, or when it's older than security_repo_stale_after_days (default 7) while the package lists are otherwise fresh; if all of them are old, the existing "package lists N days old" reason covers it. Releases past the end of support are skipped: their suite has stopped publishing, and support.check already says so. ESM suites publish too rarely to judge by date and aren't checked. The host page gets a "Security repository" row. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
fa6cca4f64
commit
c9912d5fbc
12 files changed
+261
-4
No files matched your search
@@ -463,6 +463,70 @@ X
|
||||
os.utime(partial, (t, t))
|
||||
self.assertAlmostEqual(self.report()["apt_lists_age_seconds"], 3600, delta=60)
|
||||
|
||||
def write_list(self, name, fields, age=3600, mtime_age=None):
|
||||
"""An apt list (Release or InRelease) in the fake root, its Date: `age` seconds ago."""
|
||||
body = "".join(f"{k}: {v}\n" for k, v in fields.items())
|
||||
if age is not None:
|
||||
body += "Date: " + time.strftime("%a, %d %b %Y %H:%M:%S UTC", time.gmtime(time.time() - age)) + "\n"
|
||||
body += "MD5Sum:\n 0123 456 main/binary-amd64/Packages\nSHA256:\n abcd 456 Suite: trixie-security\n"
|
||||
if name.endswith("_InRelease"):
|
||||
body = "-----BEGIN PGP SIGNED MESSAGE-----\nHash: SHA512\n\n" + body + "-----BEGIN PGP SIGNATURE-----\n"
|
||||
self.write_root(f"var/lib/apt/lists/{name}", body, age=mtime_age)
|
||||
|
||||
def set_os(self, text):
|
||||
self.write_root("etc/os-release", text)
|
||||
|
||||
def test_security_repo_debian(self):
|
||||
self.write_list("deb.debian.org_debian_dists_trixie_InRelease",
|
||||
{"Suite": "stable", "Codename": "trixie"}, age=60)
|
||||
self.write_list("security.debian.org_debian-security_dists_trixie-security_InRelease",
|
||||
{"Suite": "stable-security", "Codename": "trixie-security"}, age=5 * 3600)
|
||||
self.set_os('ID=debian\nVERSION_ID="13"\nVERSION_CODENAME=trixie\n')
|
||||
r = self.report()
|
||||
self.assertEqual(r["security_repo_suite"], "trixie-security")
|
||||
self.assertAlmostEqual(r["security_repo_age_seconds"], 5 * 3600, delta=60)
|
||||
|
||||
def test_security_repo_ubuntu_newest_mirror_and_odd_file_names(self):
|
||||
# Ubuntu: Suite is the pocket, Codename the release. Mirrors and mirror+file:
|
||||
# sources give other file names; the newest copy counts.
|
||||
self.write_list("archive.ubuntu.com_ubuntu_dists_noble-security_InRelease",
|
||||
{"Suite": "noble-security", "Codename": "noble"}, age=3 * 86400)
|
||||
self.write_list("_etc_apt_mirrors_ubuntu.list_dists_noble-security_InRelease",
|
||||
{"Suite": "noble-security", "Codename": "noble"}, age=7200)
|
||||
self.write_list("esm.ubuntu.com_infra_ubuntu_dists_noble-infra-security_InRelease",
|
||||
{"Suite": "noble-infra-security", "Codename": "noble-infra-security"}, age=60)
|
||||
self.set_os('ID=ubuntu\nVERSION_ID="24.04"\nVERSION_CODENAME=noble\nUBUNTU_CODENAME=noble\n')
|
||||
r = self.report()
|
||||
self.assertEqual(r["security_repo_suite"], "noble-security")
|
||||
self.assertAlmostEqual(r["security_repo_age_seconds"], 7200, delta=60)
|
||||
|
||||
def test_security_repo_missing(self):
|
||||
self.write_list("deb.debian.org_debian_dists_trixie_InRelease",
|
||||
{"Suite": "stable", "Codename": "trixie"})
|
||||
self.set_os('ID=debian\nVERSION_ID="13"\nVERSION_CODENAME=trixie\n')
|
||||
r = self.report()
|
||||
self.assertEqual(r["security_repo_suite"], "trixie-security")
|
||||
self.assertIsNone(r["security_repo_age_seconds"])
|
||||
|
||||
def test_security_repo_matches_fields_not_checksum_lines(self):
|
||||
# write_list puts "Suite: trixie-security" in a checksum line of every list.
|
||||
self.write_list("deb.debian.org_debian_dists_trixie_Release",
|
||||
{"Suite": "stable", "Codename": "trixie"})
|
||||
self.set_os('ID=debian\nVERSION_ID="13"\nVERSION_CODENAME=trixie\n')
|
||||
self.assertIsNone(self.report()["security_repo_age_seconds"])
|
||||
|
||||
def test_security_repo_without_date_uses_mtime(self):
|
||||
self.write_list("local_dists_trixie-security_Release",
|
||||
{"Codename": "trixie-security"}, age=None, mtime_age=4 * 3600)
|
||||
self.set_os('ID=debian\nVERSION_ID="13"\nVERSION_CODENAME=trixie\n')
|
||||
self.assertAlmostEqual(self.report()["security_repo_age_seconds"], 4 * 3600, delta=60)
|
||||
|
||||
def test_security_repo_without_codename(self):
|
||||
# The default fake os-release has no VERSION_CODENAME (like Debian sid).
|
||||
r = self.report()
|
||||
self.assertIsNone(r["security_repo_suite"])
|
||||
self.assertIsNone(r["security_repo_age_seconds"])
|
||||
|
||||
def test_send_without_config_fails_cleanly(self):
|
||||
proc = self.run_agent()
|
||||
self.assertNotEqual(proc.returncode, 0)
|
||||
|
||||
Reference in new issue
Block a user