Flag hosts whose OS release no longer gets security updates
CI / tests (Python 3.10) (pull_request) Successful in 30s
CI / tests (Python 3.11) (pull_request) Successful in 30s
CI / tests (Python 3.12) (pull_request) Successful in 28s
CI / tests (Python 3.13) (pull_request) Successful in 28s
CI / lint (pull_request) Successful in 3s
CI / tests (Python 3.10) (pull_request) Successful in 30s
CI / tests (Python 3.11) (pull_request) Successful in 30s
CI / tests (Python 3.12) (pull_request) Successful in 28s
CI / tests (Python 3.13) (pull_request) Successful in 28s
CI / lint (pull_request) Successful in 3s
Past its end of support a release gets no more security updates, so apt offers nothing and the host showed ok indefinitely. The server now has a table of when free security support ends for each release the agent installs on (support.py): Debian's LTS end, and Ubuntu's end of standard support plus end of ESM. Dates from Debian LTS and Ubuntu's release cycle via endoflife.date; a test checks the table covers every release agent/install.sh accepts. The agent reports whether Ubuntu Pro is attached and esm-infra's status, read from the pro client's world-readable status.json. A host past its date goes to update; within os_eol_warn_days (default 90) of it, the row gets a note. An Ubuntu host with ESM enabled isn't warned when standard support ends, only before ESM does. The host page shows the dates. Agent 0.7.0; older agents don't report ESM and count as having none. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
5a11d31e66
commit
bc46c55298
15 files changed
+348
-7
No files matched your search
@@ -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.6.0"
|
||||
AGENT_VERSION = "0.7.0"
|
||||
@@ -33,6 +33,10 @@ class Config:
|
||||
# Less free space than this on /boot's filesystem puts a host in update: the next
|
||||
# kernel (image plus initramfs, often over 100 MB) may not fit. 0 disables.
|
||||
boot_min_free_mb: int = 200
|
||||
# Note a host this many days before its OS release stops getting security updates
|
||||
# (or Ubuntu standard support ends without ESM). 0 disables the warning; a host
|
||||
# past the date is in update either way.
|
||||
os_eol_warn_days: int = 90
|
||||
|
||||
# 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
|
||||
@@ -96,6 +100,8 @@ def load(path: str | None = None) -> Config:
|
||||
raise SystemExit(f"{path}: ntfy_timeout_seconds must be positive and finite")
|
||||
if cfg.report_min_interval_seconds < 0:
|
||||
raise SystemExit(f"{path}: report_min_interval_seconds must be zero or positive")
|
||||
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:
|
||||
raise SystemExit(f"{path}: boot_min_free_mb must be zero or positive")
|
||||
if cfg.backup_keep_days < 0:
|
||||
|
||||
@@ -45,6 +45,8 @@ FIELDS: dict[str, str] = {
|
||||
"boot_size_kb": "int",
|
||||
"boot_free_kb": "int",
|
||||
"dpkg_unfinished_packages": "strlist",
|
||||
"ubuntu_pro_attached": "bool",
|
||||
"ubuntu_esm_infra": "str",
|
||||
"apt_lists_age_seconds": "int",
|
||||
"uptime_seconds": "int",
|
||||
}
|
||||
|
||||
@@ -15,7 +15,7 @@ from dataclasses import dataclass, field
|
||||
from datetime import date, datetime, timezone
|
||||
from typing import Any
|
||||
|
||||
from . import AGENT_VERSION
|
||||
from . import AGENT_VERSION, support
|
||||
from .config import Config
|
||||
|
||||
LEVELS = ("stale", "reboot", "update", "ok")
|
||||
@@ -229,6 +229,14 @@ def evaluate(received_at: int | None, report: dict[str, Any] | None, now: float,
|
||||
if low := boot_space_low(report, cfg):
|
||||
status.raise_to("update", low)
|
||||
|
||||
today = datetime.fromtimestamp(now, timezone.utc).date()
|
||||
if found := support.check(report, today, cfg.os_eol_warn_days):
|
||||
problem, why = found
|
||||
if problem:
|
||||
status.raise_to("update", why)
|
||||
else:
|
||||
status.note(why)
|
||||
|
||||
if services := report.get("services_need_restart"):
|
||||
shown = ", ".join(s.removesuffix(".service") for s in services[:5])
|
||||
more = f", +{len(services) - 5} more" if len(services) > 5 else ""
|
||||
|
||||
@@ -0,0 +1,98 @@
|
||||
"""When each supported OS release stops getting security updates.
|
||||
|
||||
A host past that date shows `ok` forever, because no updates will ever arrive to
|
||||
flag. So the status check compares the host's release (`os_id`, `os_version_id`)
|
||||
with the dates below.
|
||||
|
||||
Sources: the Debian security team and Debian LTS (wiki.debian.org/LTS) and
|
||||
Ubuntu's release cycle (ubuntu.com/about/release-cycle), as collected by
|
||||
endoflife.date. Add each new release when it ships; tests/test_support.py checks
|
||||
that every release the agent supports is listed.
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
from dataclasses import dataclass
|
||||
from datetime import date
|
||||
from typing import Any
|
||||
|
||||
|
||||
@dataclass(frozen=True)
|
||||
class Release:
|
||||
name: str
|
||||
# Debian: end of LTS, the last free security support (regular security support
|
||||
# ends about two years earlier and LTS continues it from the same repository).
|
||||
# Ubuntu: end of standard support for the main archive.
|
||||
end: date
|
||||
# Ubuntu only: end of Expanded Security Maintenance (esm-infra, part of Ubuntu
|
||||
# Pro), which keeps patching main after standard support ends.
|
||||
esm_end: date | None = None
|
||||
|
||||
|
||||
RELEASES: dict[tuple[str, str], Release] = {
|
||||
("debian", "11"): Release("Debian 11", date(2026, 8, 31)),
|
||||
("debian", "12"): Release("Debian 12", date(2028, 6, 30)),
|
||||
("debian", "13"): Release("Debian 13", date(2030, 6, 30)),
|
||||
("ubuntu", "20.04"): Release("Ubuntu 20.04", date(2025, 5, 31), date(2030, 4, 23)),
|
||||
("ubuntu", "22.04"): Release("Ubuntu 22.04", date(2027, 6, 1), date(2032, 4, 21)),
|
||||
("ubuntu", "24.04"): Release("Ubuntu 24.04", date(2029, 5, 31), date(2034, 4, 25)),
|
||||
("ubuntu", "26.04"): Release("Ubuntu 26.04", date(2031, 5, 29), date(2036, 4, 23)),
|
||||
}
|
||||
|
||||
|
||||
def release(report: dict[str, Any]) -> Release | None:
|
||||
return RELEASES.get((report.get("os_id") or "", report.get("os_version_id") or ""))
|
||||
|
||||
|
||||
def _esm(report: dict[str, Any]) -> bool:
|
||||
return report.get("ubuntu_esm_infra") == "enabled"
|
||||
|
||||
|
||||
def check(report: dict[str, Any], today: date, warn_days: int) -> tuple[bool, str] | None:
|
||||
"""(is it a problem, why) about this host's OS support, or None if there's nothing to say.
|
||||
|
||||
A problem means no security updates are coming: the release is past its last
|
||||
support date, or an Ubuntu release is past standard support without ESM. The
|
||||
rest are warnings for the `warn_days` before such a date (0 disables them)."""
|
||||
os_id, version = report.get("os_id"), report.get("os_version_id")
|
||||
if os_id not in ("debian", "ubuntu") or not version:
|
||||
return None # Debian testing/sid has no VERSION_ID; other distros aren't supported
|
||||
rel = release(report)
|
||||
if rel is None:
|
||||
return False, f"no end-of-support date known for {os_id} {version}"
|
||||
|
||||
def soon(day: date) -> int | None:
|
||||
left = (day - today).days
|
||||
return left if warn_days and 0 <= left <= warn_days else None
|
||||
|
||||
if rel.esm_end is None:
|
||||
if today > rel.end:
|
||||
return True, f"{rel.name} security support ended {rel.end}; upgrade the release"
|
||||
if (left := soon(rel.end)) is not None:
|
||||
return False, f"{rel.name} security support ends {rel.end} (in {left} days); plan the upgrade"
|
||||
return None
|
||||
|
||||
if today > rel.esm_end:
|
||||
return True, f"{rel.name} ESM ended {rel.esm_end}; upgrade the release"
|
||||
if _esm(report):
|
||||
if today > rel.end and (left := soon(rel.esm_end)) is not None:
|
||||
return False, f"{rel.name} ESM ends {rel.esm_end} (in {left} days); plan the upgrade"
|
||||
return None
|
||||
if today > rel.end:
|
||||
return True, (f"{rel.name} standard support ended {rel.end} and ESM isn't enabled; "
|
||||
"enable it with Ubuntu Pro or upgrade the release")
|
||||
if (left := soon(rel.end)) is not None:
|
||||
return False, (f"{rel.name} standard support ends {rel.end} (in {left} days); "
|
||||
"enable ESM with Ubuntu Pro or plan the upgrade")
|
||||
return None
|
||||
|
||||
|
||||
def summary(report: dict[str, Any]) -> str | None:
|
||||
"""The host page's one-line view of the release's support dates."""
|
||||
rel = release(report)
|
||||
if rel is None:
|
||||
return None
|
||||
if rel.esm_end is None:
|
||||
return f"until {rel.end}"
|
||||
esm = report.get("ubuntu_esm_infra")
|
||||
return f"standard until {rel.end}, ESM until {rel.esm_end} (esm-infra: {esm or 'unknown'})"
|
||||
@@ -19,7 +19,7 @@ from http.server import BaseHTTPRequestHandler, ThreadingHTTPServer
|
||||
from typing import Any
|
||||
from urllib.parse import parse_qs, quote, unquote, urlsplit
|
||||
|
||||
from . import __version__, auth, db
|
||||
from . import __version__, auth, db, support
|
||||
from .config import Config
|
||||
from .report import MAX_BODY_BYTES, ReportError, sanitize
|
||||
from .status import LEVELS, Status, evaluate
|
||||
@@ -490,6 +490,7 @@ class Handler(BaseHTTPRequestHandler):
|
||||
if latest else None),
|
||||
field("Reported hostname", r.get("reported_hostname")),
|
||||
field("OS", r.get("os_pretty_name")),
|
||||
field("OS security support", support.summary(r)),
|
||||
field("Running kernel", r.get("kernel_running"), code=True),
|
||||
field("Kernel build", r.get("kernel_build"), code=True),
|
||||
field("Running kernel package", r.get("kernel_running_pkg_version"), code=True),
|
||||
|
||||
Reference in new issue
Block a user