hub (unreleased): the System page shows the kernel clean-up and the security-profile refresh; a clean-up no longer hides a kernel step (R-1383)
gates / gates (push) Successful in 2m20s

Claude-Session: https://claude.ai/code/session_0159rPz1ZhFKsS53msqPYxtS
This commit is contained in:
admin committed 2026-11-14 18:06:12 +01:00
1 parent e5c643d73d
commit 68292e40f6
14 files changed
+452 -13

No files matched your search

+66
View File
@@ -38,6 +38,7 @@ type systemRow struct {
Held, RebootSince, KernelPanic, Oops cell
CrashRestarts24h, Guard cell
KernelDefault, KernelStep cell // R-836: the GRUB default kernel; the kernel lane's step
KernelCleanup, Profiles cell // R-1383: the clean-up of old kernels; the security-profile refresh
Bundle cell // R-840: the root-owned config bundle
Agent cell // R-530: the box's agent against the vouched one
// guest
@@ -115,6 +116,71 @@ func kernelCells(f sysfacts.System, kl osupdates.KernelLine, now time.Time) (dfl
return dflt, step
}
// cleanupCell is the System page's „Kernel clean-up” cell (R-1383, release 3; `11` §5.11.1): the newest clean-up of
// old kernels — how many it removed and kept and how much space it gained, the names in the title. Amber when it was
// refused or failed, or left paths of a removed kernel behind. A box tells the hub only when a clean-up removed
// something, was refused, or failed — so „—” is the normal reading for a box with nothing to remove.
func cleanupCell(kl osupdates.KernelLine, now time.Time) cell {
if kl.CleanupOutcome == "" {
return cell{Text: "—", Title: "no clean-up of old kernels reported (a box reports one only when it removed kernels, was refused, or failed)"}
}
when := ago(kl.CleanupAt, now)
switch kl.CleanupOutcome {
case "cleaned":
d := kl.Cleanup
if d == nil {
return cell{Text: "cleaned " + when, Title: kl.CleanupReason}
}
gained := "space gained unknown"
if d.BytesGained != nil {
gained = fmt.Sprintf("%.1f GiB gained", float64(*d.BytesGained)/(1<<30))
}
c := cell{Text: fmt.Sprintf("removed %d, kept %d · %s · %s", len(d.Removed), len(d.Kept), gained, when),
Title: "removed: " + strings.Join(d.Removed, ", ") + " — kept: " + strings.Join(d.Kept, ", ")}
if d.Leftovers > 0 {
c.Class = "warn"
c.Text += fmt.Sprintf(" · %d left-over path(s)", d.Leftovers)
}
return c
}
return cell{Text: kl.CleanupOutcome + " " + when, Class: "warn", Title: kl.CleanupReason}
}
// profileCell is the „Security profiles” cell (R-1383, release 3; `11` §5.12): the box's last refresh of its compiled
// AppArmor profiles — the kernel it ran on, how many compiled profiles changed, and any FAILED service it restarted
// (on the N100 that was the time service). Amber when the agent's last ask failed or got no answer.
func profileCell(f sysfacts.System, now time.Time) cell {
p := f.ProfileRefresh
if p == nil {
return cell{Text: "—", Title: "the box reports no security-profile refresh (an agent older than release 3, a BYO host, or no refresh yet)"}
}
var parts []string
if p.At != "" {
at, _ := time.Parse(time.RFC3339, p.At)
parts = append(parts, strings.TrimSpace(p.Kernel+" · "+fmt.Sprintf("%d rewritten", p.Rewritten)+" · "+ago(at, now)))
if len(p.Restarted) > 0 {
parts = append(parts, "restarted "+strings.Join(p.Restarted, ", "))
}
}
c := cell{Title: "last ask: " + p.LastAsk}
if p.LastAsk == "" {
c.Title = "from the box's own record (the agent has not asked since it started)"
}
switch p.LastAsk {
case "failed", "no_answer":
askAt, _ := time.Parse(time.RFC3339, p.LastAskAt)
parts = append(parts, "last ask "+strings.ToUpper(p.LastAsk)+" "+ago(askAt, now))
c.Class = "warn"
case "refused":
c.Title = "last ask: refused (an older root wrapper that does not know the mode, or a BYO host)"
}
if len(parts) == 0 {
parts = append(parts, "no refresh yet")
}
c.Text = strings.Join(parts, " · ")
return c
}
// agentCell is the "Agent" cell (R-530, hub v0.135.0): the box's agent against the vouched one, how far behind and
// since when. Amber while behind; red from the alarm's wait on (the operator alarm fires then). An unreadable
// version is "unknown", never a guess; nothing vouched → the version alone.
+92
View File
@@ -0,0 +1,92 @@
package web
import (
"strings"
"testing"
"time"
"gitea.dooplex.hu/admin/felhom-hub/internal/osupdates"
"gitea.dooplex.hu/admin/felhom-hub/internal/sysfacts"
)
// R-1383 (release 3): the two new cells of the System page, from what a box really sends.
// COMPANION RED-PROOFS (observed, audits/night-build-2026-11-14/B/redproof-hub-b3.txt).
func TestSystemCells_KernelCleanupAndSecurityProfiles(t *testing.T) {
now := time.Date(2026, 11, 15, 6, 0, 0, 0, time.UTC)
gained := int64(6442450944)
// --- the clean-up ---
if c := cleanupCell(osupdates.KernelLine{}, now); c.Text != "—" || c.Class != "" {
t.Errorf("no clean-up reported: %+v (a box with nothing to remove reports none — not a fault)", c)
}
kl := osupdates.KernelLine{CleanupOutcome: "cleaned", CleanupAt: now.Add(-3 * time.Hour), CleanupReason: "removed 6 …",
Cleanup: &osupdates.CleanupDetail{Removed: []string{"proxmox-kernel-7.0.2-6-pve-signed", "b", "c", "d", "e", "f"},
Kept: []string{"7.0.14-26-pve", "7.0.14-28-pve"}, BytesGained: &gained}}
c := cleanupCell(kl, now)
for _, want := range []string{"removed 6, kept 2", "6.0 GiB gained", "3"} {
if !strings.Contains(c.Text, want) {
t.Errorf("clean-up cell %q lacks %q", c.Text, want)
}
}
if c.Class != "" || !strings.Contains(c.Title, "proxmox-kernel-7.0.2-6-pve-signed") || !strings.Contains(c.Title, "kept: 7.0.14-26-pve, 7.0.14-28-pve") {
t.Errorf("clean-up cell = %+v, want no colour and the names in the title", c)
}
kl.Cleanup.Leftovers = 2
if c := cleanupCell(kl, now); c.Class != "warn" || !strings.Contains(c.Text, "2 left-over path(s)") {
t.Errorf("left-over paths must be amber and named: %+v", c)
}
kl.Cleanup = nil // an agent of release 2a
if c := cleanupCell(kl, now); !strings.HasPrefix(c.Text, "cleaned ") || c.Title != "removed 6 …" {
t.Errorf("a clean-up without detail: %+v", c)
}
for _, bad := range []string{"refused", "failed"} {
if c := cleanupCell(osupdates.KernelLine{CleanupOutcome: bad, CleanupAt: now.Add(-time.Hour), CleanupReason: "K4: the phase is judging"}, now); c.Class != "warn" || !strings.HasPrefix(c.Text, bad) || c.Title != "K4: the phase is judging" {
t.Errorf("%s clean-up: %+v, want amber with the reason", bad, c)
}
}
// --- the security profiles: parsed from a host report, as the page gets it ---
if c := profileCell(sysfacts.Parse(`{"host_id":"x"}`), now); c.Text != "—" || c.Class != "" {
t.Errorf("no stanza: %+v", c)
}
f := sysfacts.Parse(`{"profile_refresh":{"kernel":"7.0.14-28-pve","at":"2026-11-14T11:30:11Z","rewritten":2,"restarted":["chrony.service"],"last_ask":"refreshed","last_ask_at":"2026-11-14T11:30:11Z"}}`)
c = profileCell(f, now)
for _, want := range []string{"7.0.14-28-pve", "2 rewritten", "restarted chrony.service"} {
if !strings.Contains(c.Text, want) {
t.Errorf("profile cell %q lacks %q", c.Text, want)
}
}
if c.Class != "" {
t.Errorf("a good refresh must have no colour: %+v", c)
}
for _, ask := range []string{"failed", "no_answer"} {
f = sysfacts.Parse(`{"profile_refresh":{"kernel":"7.0.14-28-pve","at":"2026-11-14T11:30:11Z","rewritten":2,"last_ask":"` + ask + `","last_ask_at":"2026-11-15T05:00:00Z"}}`)
if c := profileCell(f, now); c.Class != "warn" || !strings.Contains(c.Text, "last ask "+strings.ToUpper(ask)) || !strings.Contains(c.Text, "2 rewritten") {
t.Errorf("last ask %s: %+v, want amber, the failed ask AND the older record", ask, c)
}
}
f = sysfacts.Parse(`{"profile_refresh":{"last_ask":"refused","last_ask_at":"2026-11-15T05:00:00Z"}}`)
if c := profileCell(f, now); c.Class != "" || c.Text != "no refresh yet" || !strings.Contains(c.Title, "older root wrapper") {
t.Errorf("a refused ask (an older wrapper) is not a fault: %+v", c)
}
}
// Both cells are on the rendered page, under their names, and a failed ask reaches „Needs attention”.
func TestSystemPage_ShowsCleanupAndProfiles(t *testing.T) {
in := fixtureInput(true)
gained := int64(1073741824)
in.KernelLines = map[string]osupdates.KernelLine{"demo-hp-d4e5f6": {CleanupOutcome: "cleaned", CleanupAt: in.Now.Add(-2 * time.Hour),
Cleanup: &osupdates.CleanupDetail{Removed: []string{"proxmox-kernel-7.0.14-20-pve-signed"}, Kept: []string{"7.0.14-23-pve"}, BytesGained: &gained}}}
f := in.Facts["demo-hp-d4e5f6"]
f.ProfileRefresh = &sysfacts.ProfileRefresh{Kernel: "7.0.14-23-pve", At: in.Now.Add(-5 * time.Hour).UTC().Format(time.RFC3339), Rewritten: 1,
Restarted: []string{"chrony.service"}, LastAsk: "failed", LastAskAt: in.Now.Add(-time.Hour).UTC().Format(time.RFC3339)}
in.Facts["demo-hp-d4e5f6"] = f
page := renderSystem(t, in)
for _, want := range []string{">Kernel clean-up</dt>", ">Security profiles</dt>", "removed 1, kept 1", "1.0 GiB gained",
"restarted chrony.service", "last ask FAILED"} {
if !strings.Contains(page, want) {
t.Errorf("the System page lacks %q", want)
}
}
if att := sysSection(page, "attention"); !strings.Contains(att, "security profiles") {
t.Errorf("a failed ask of the profile refresh is not under „Needs attention”")
}
}
+1 -1
View File
@@ -144,7 +144,7 @@ func TestSystemPage_EveryItemStillOnThePage(t *testing.T) {
// per box, in the box panel (every column of the old wide table)
`href="/hosts/demo-hp-d4e5f6"`, "Demo HP", `action="/os/ring/demo-hp-d4e5f6"`, `action="/os/enabled/tester1-0f1e2d"`,
">Tunnel</dt>", ">Proxmox</dt>", ">Kernel (running)</dt>", ">Kernel (next boot)</dt>", ">Kernel (default)</dt>",
">Kernel step</dt>", ">Debian</dt>", ">Felhom release</dt>", ">Pending</dt>", ">Not covered</dt>", ">Held</dt>",
">Kernel step</dt>", ">Kernel clean-up</dt>", ">Security profiles</dt>", ">Debian</dt>", ">Felhom release</dt>", ">Pending</dt>", ">Not covered</dt>", ">Held</dt>",
">Reboot needed</dt>", ">kernel.panic</dt>", ">Oops</dt>", ">Crash restarts 24 h</dt>", ">Crash guard</dt>",
">Root files</dt>", ">Agent</dt>", ">Guest Debian</dt>", ">Restart needed</dt>", ">Last disk trim</dt>",
">Docker</dt>", ">containerd</dt>", ">live-restore</dt>", ">Docker release</dt>", ">Last OS leg</dt>",
+3 -1
View File
@@ -52,6 +52,7 @@ func buildSystemPage(in systemInput) map[string]interface{} {
for i := range rows {
id := rows[i].HostID
rows[i].KernelDefault, rows[i].KernelStep = kernelCells(in.Facts[id], in.KernelLines[id], in.Now)
rows[i].KernelCleanup, rows[i].Profiles = cleanupCell(in.KernelLines[id], in.Now), profileCell(in.Facts[id], in.Now)
rows[i].Bundle = bundleCell(in.Facts[id], in.VouchedAgent, in.VouchedBundle, in.BundleSame[id], in.BundleSince[id], in.BundleAfter, in.Now)
rows[i].Agent = agentCell(in.Agents[id], in.VouchedAgent, in.AgentSince[id], in.AgentAfter, in.Now)
rows[i].Controller = unknownCell(in.Controllers[id])
@@ -94,7 +95,8 @@ func (r *systemRow) labelled() []struct {
}
return []lc{
{"tunnel", r.Tunnel}, {"Proxmox version", r.PVE}, {"running kernel", r.KernelRunning}, {"next-boot kernel", r.KernelNextBoot},
{"default kernel", r.KernelDefault}, {"kernel step", r.KernelStep}, {"host Debian", r.HostDebian},
{"default kernel", r.KernelDefault}, {"kernel step", r.KernelStep}, {"kernel clean-up", r.KernelCleanup},
{"security profiles", r.Profiles}, {"host Debian", r.HostDebian},
{"host updates not covered", r.HostNotCovered}, {"held packages", r.Held}, {"host restart", r.RebootSince},
{"kernel.panic", r.KernelPanic}, {"kernel oops", r.Oops}, {"crash restarts", r.CrashRestarts24h}, {"crash guard", r.Guard},
{"root files", r.Bundle}, {"agent", r.Agent}, {"controller", r.Controller}, {"guest Debian", r.GuestDebian},
+2
View File
@@ -185,6 +185,8 @@
<dt>Kernel (next boot)</dt>{{template "sys_dd" .KernelNextBoot}}
<dt title="The kernel GRUB boots normally (R-836). Amber: a one-shot flag names another kernel for the next boot only.">Kernel (default)</dt>{{template "sys_dd" .KernelDefault}}
<dt title="The kernel lane (R-836): the newest step, the kernel the box is due, and whether its household was told for tonight (no mail, no step).">Kernel step</dt>{{template "sys_dd" .KernelStep}}
<dt title="The newest clean-up of old kernels (R-1368): how many it removed and kept, and the space gained. A box reports one only when it removed kernels, was refused, or failed.">Kernel clean-up</dt>{{template "sys_dd" .KernelCleanup}}
<dt title="The box's last refresh of its compiled security (AppArmor) profiles (R-1388): the kernel it ran on, how many changed, and a failed service it restarted.">Security profiles</dt>{{template "sys_dd" .Profiles}}
<dt>Debian</dt>{{template "sys_dd" .HostDebian}}
<dt>Felhom release</dt>{{template "sys_dd" .HostRelease}}
<dt>Pending</dt>{{template "sys_dd" .HostPending}}