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

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:
patrickandClaude Opus 5.5 committed 2026-11-01 14:58:10 -05:00
1 parent fa6cca4f64
commit c9912d5fbc
12 files changed
+261 -4

No files matched your search

+1 -1
View File
@@ -4,4 +4,4 @@ __version__ = "0.4.0"
# 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.8.0"
AGENT_VERSION = "0.9.0"
+7
View File
@@ -40,6 +40,11 @@ class Config:
# A host with unattended-upgrades enabled that hasn't had a successful run in this
# long is in update. It normally runs daily. 0 disables the check.
unattended_upgrades_stale_after_days: float = 3.0
# A host whose apt lists have no repository for its release's security suite
# (e.g. trixie-security), or whose copy of it is older than this while its other
# lists refresh, is in update: security updates can't reach it. Debian and
# Ubuntu publish it at least daily. 0 disables the check.
security_repo_stale_after_days: float = 7.0
# Where `scheduled-backup` (kernelwatch-backup.timer) writes dated copies of the
# database, and how many days of them it keeps; 0 keeps them all. It must stay
@@ -105,6 +110,8 @@ def load(path: str | None = None) -> Config:
raise SystemExit(f"{path}: report_min_interval_seconds must be zero or positive")
if not math.isfinite(cfg.unattended_upgrades_stale_after_days) or cfg.unattended_upgrades_stale_after_days < 0:
raise SystemExit(f"{path}: unattended_upgrades_stale_after_days must be zero or positive and finite")
if not math.isfinite(cfg.security_repo_stale_after_days) or cfg.security_repo_stale_after_days < 0:
raise SystemExit(f"{path}: security_repo_stale_after_days must be zero or positive and finite")
if cfg.os_eol_warn_days < 0:
raise SystemExit(f"{path}: os_eol_warn_days must be zero or positive")
if cfg.boot_min_free_mb < 0:
+2
View File
@@ -52,6 +52,8 @@ FIELDS: dict[str, str] = {
"unattended_upgrades_run_age_seconds": "int",
"unattended_upgrades_kept_back": "strlist",
"apt_lists_age_seconds": "int",
"security_repo_suite": "str",
"security_repo_age_seconds": "int",
"uptime_seconds": "int",
}
+29
View File
@@ -191,6 +191,33 @@ def unattended_upgrades_problem(report: dict[str, Any], cfg: Config) -> tuple[bo
"is apt-daily-upgrade.timer enabled?")
def security_repo_problem(report: dict[str, Any], cfg: Config, today: date) -> str | None:
"""Why security updates may not be reaching this host from its release's security
suite, or None. Agents before 0.9.0, and releases without a codename, don't
report the suite.
The age is of the suite's Date: field as of apt's last successful fetch of it, so
it keeps growing when fetching that repository fails, even while the update
stamps and other lists move on."""
suite = report.get("security_repo_suite")
if not suite or not cfg.security_repo_stale_after_days:
return None
rel = support.release(report)
if rel is not None and today > rel.end:
return None # the suite has stopped publishing; support.check covers it
age = report.get("security_repo_age_seconds")
if age is None:
return (f"apt has no {suite} repository, so security updates can't arrive; "
"add it to the apt sources and run apt update")
if age <= cfg.security_repo_stale_after_days * 86400:
return None
apt_age = report.get("apt_lists_age_seconds")
if apt_age is None or apt_age / 3600 > cfg.apt_stale_after_hours:
return None # apt isn't refreshing anything; the package list reason covers it
return (f"apt's {suite} list is {_age(age)} old while apt update otherwise succeeds; "
f"run apt update and look for errors about {suite}")
def _kernel_only_reboot_file(report: dict[str, Any]) -> bool:
"""/run/reboot-required exists only because of kernel packages."""
pkgs = report.get("reboot_required_pkgs") or []
@@ -295,6 +322,8 @@ def evaluate(received_at: int | None, report: dict[str, Any] | None, now: float,
status.raise_to("update", "package list age unknown")
elif apt_age / 3600 > cfg.apt_stale_after_hours:
status.raise_to("update", f"package lists {apt_age / 86400:.0f}d old; apt update not running?")
if why := security_repo_problem(report, cfg, datetime.fromtimestamp(now, timezone.utc).date()):
status.raise_to("update", why)
if host and (reported := hostname_mismatch(host, report)):
status.note(f"registered as {host} but reports itself as {reported}; "
+11
View File
@@ -95,6 +95,16 @@ def unattended_upgrades_summary(report: dict[str, Any]) -> str | None:
for what, age in last.items())
def security_repo_summary(report: dict[str, Any]) -> str | None:
suite = report.get("security_repo_suite")
if not suite:
return None # agents before 0.9.0, or no release codename
age = report.get("security_repo_age_seconds")
if age is None:
return f"{suite}: not in apt's sources"
return f"{suite}, published {duration(age)} before the report"
def phased_summary(report: dict[str, Any]) -> tuple[str, str]:
"""(short cell text, full description) for updates deferred by Ubuntu's phasing."""
if report.get("os_id") not in (None, "ubuntu"):
@@ -527,6 +537,7 @@ class Handler(BaseHTTPRequestHandler):
field("Kept back by unattended-upgrades", r.get("unattended_upgrades_kept_back"), code=True),
field("Package lists age", duration(r.get("apt_lists_age_seconds"))
if r.get("apt_lists_age_seconds") is not None else None),
field("Security repository", security_repo_summary(r)),
field("Uptime", duration(r.get("uptime_seconds")) if r.get("uptime_seconds") is not None else None),
field("Agent version", r.get("agent_version")),
])