"""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'})"