Dockhand vulnerability scans: warn about critical findings, with a setting to turn it off
Reads what Dockhand's scans have already stored (never starts one) every 15 minutes and raises a warning per Docker host with critical findings. Unknown counts and stale readings are held, not treated as clean. Settings -> Notifications has a switch (on by default); the Docker page shows counts, scan coverage and the critical findings; /metrics and docs updated. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
65214f6f0f
commit
5a2b320175
25 files changed
+8527
-12
No files matched your search
@@ -5,12 +5,13 @@
|
||||
*/
|
||||
import { eq } from "drizzle-orm";
|
||||
import { db } from "../db/client.js";
|
||||
import { assets, endpointChecks, heartbeats, integrations, maintenanceWindows, secrets, servers, upsState, jellyfinState, authentikState, immichState, paperlessState, nextcloudState, netboxState, n8nState } from "../db/schema.js";
|
||||
import { assets, endpointChecks, heartbeats, integrations, maintenanceWindows, secrets, servers, upsState, jellyfinState, authentikState, immichState, paperlessState, nextcloudState, netboxState, n8nState, dockhandVulnerabilities } from "../db/schema.js";
|
||||
import { isUpsFresh, upsSyncStatuses } from "./upsSync.js";
|
||||
import { levelStatuses } from "./serviceLevels.js";
|
||||
import { backupState, listAll as listDuplicati } from "./duplicati.js";
|
||||
import { isJellyfinFresh, jellyfinSyncStatuses, streamsOf } from "./jellyfinSync.js";
|
||||
import { isNextcloudFresh, nextcloudSyncStatuses } from "./nextcloudSync.js";
|
||||
import { dockerVulnSyncStatuses, isDockerVulnFresh } from "./dockerVulnSync.js";
|
||||
import { isNetBoxFresh, netboxSyncStatuses } from "./netboxSync.js";
|
||||
import { isN8nFresh, n8nSyncStatuses, workflowsOf as n8nWorkflowsOf } from "./n8nSync.js";
|
||||
import { componentsOf as paperlessComponentsOf, failedOf as paperlessFailedOf, isPaperlessFresh, paperlessSyncStatuses } from "./paperlessSync.js";
|
||||
@@ -83,6 +84,22 @@ async function addNextcloudMetrics(out: Exposition, now: Date) {
|
||||
}
|
||||
}
|
||||
|
||||
/** Each Docker host's vulnerability counts from Dockhand's scans, for /metrics. Only while the reading is recent, and only for hosts whose summary could be read. */
|
||||
async function addDockerVulnMetrics(out: Exposition, now: Date) {
|
||||
const statuses = await dockerVulnSyncStatuses();
|
||||
const names = new Map((await db.select({ id: integrations.id, name: integrations.name, enabled: integrations.enabled }).from(integrations).where(eq(integrations.type, "dockhand"))).map((r) => [r.id, r]));
|
||||
for (const s of await db.select().from(dockhandVulnerabilities)) {
|
||||
const row = names.get(s.integrationId);
|
||||
if (!row || !row.enabled || s.critical === null || !isDockerVulnFresh(statuses[s.integrationId], now.getTime())) continue;
|
||||
const labels = { integration: row.name, host: s.environmentName };
|
||||
out.add("homelab_docker_vulnerabilities", "gauge", "Vulnerabilities in the scanned images of a Docker host, by severity, from Dockhand's stored scans.", s.critical, { ...labels, severity: "critical" });
|
||||
if (s.high !== null) out.add("homelab_docker_vulnerabilities", "gauge", "Vulnerabilities in the scanned images of a Docker host, by severity, from Dockhand's stored scans.", s.high, { ...labels, severity: "high" });
|
||||
if (s.medium !== null) out.add("homelab_docker_vulnerabilities", "gauge", "Vulnerabilities in the scanned images of a Docker host, by severity, from Dockhand's stored scans.", s.medium, { ...labels, severity: "medium" });
|
||||
if (s.low !== null) out.add("homelab_docker_vulnerabilities", "gauge", "Vulnerabilities in the scanned images of a Docker host, by severity, from Dockhand's stored scans.", s.low, { ...labels, severity: "low" });
|
||||
if (s.imagesScanned !== null) out.add("homelab_docker_images_scanned", "gauge", "How many of a Docker host's images have a vulnerability scan in Dockhand.", s.imagesScanned, labels);
|
||||
}
|
||||
}
|
||||
|
||||
/** Each NetBox, for /metrics: the workers running and what it holds. Only while the reading is recent. */
|
||||
async function addNetBoxMetrics(out: Exposition, now: Date) {
|
||||
const statuses = await netboxSyncStatuses();
|
||||
@@ -388,6 +405,7 @@ export async function buildMetrics(now: Date = new Date()): Promise<string> {
|
||||
await addN8nMetrics(out, now);
|
||||
await addNetBoxMetrics(out, now);
|
||||
await addNextcloudMetrics(out, now);
|
||||
await addDockerVulnMetrics(out, now);
|
||||
await addHeartbeatMetrics(out, now);
|
||||
return out.toString();
|
||||
}
|
||||
Reference in new issue
Block a user