New integration kinds adguard (status, statistics, filter lists and a real DNS question over UDP; alerts for DNS down/not running, protection left off, stale lists) and grafana (alert rules firing or failing, data-source health). Optional warning for running Docker images built more than N days ago (off by default). A server's overview cards can be folded and arranged, kept per user. Migrations 0075-0077; docs, metrics and tests included. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
148 lines
7.3 KiB
TypeScript
148 lines
7.3 KiB
TypeScript
import { useEffect, useState } from "react";
|
|
import { Link } from "react-router-dom";
|
|
import { api, type DockhandVulnerabilitiesResponse, type DockhandVulnerabilityEnvironment } from "../api/client";
|
|
import TimeAgo from "../components/TimeAgo";
|
|
import { readableError } from "../utils/errors";
|
|
|
|
const count = (v: number | null) => (v === null ? "—" : v.toLocaleString());
|
|
|
|
const ageText = (days: number) => (days >= 730 ? `${Math.floor(days / 365)} years` : days >= 60 ? `${Math.floor(days / 30)} months` : `${days} days`);
|
|
|
|
function Host({ env, imageAgeDays }: { env: DockhandVulnerabilityEnvironment; imageAgeDays: number }) {
|
|
const [open, setOpen] = useState(false);
|
|
const unscanned = env.totalImages !== null && env.imagesScanned !== null ? env.totalImages - env.imagesScanned : null;
|
|
return (
|
|
<div className="mb-3">
|
|
<div className="d-flex flex-wrap align-items-center gap-2">
|
|
<strong>{env.environmentName}</strong>
|
|
{env.critical === null ? (
|
|
<span className="badge bg-secondary-lt text-secondary">Not read</span>
|
|
) : env.critical > 0 ? (
|
|
<span className="badge bg-red-lt text-red">{env.critical} critical</span>
|
|
) : (
|
|
<span className="badge bg-green-lt text-green">No critical</span>
|
|
)}
|
|
<span className="text-secondary small">
|
|
{count(env.high)} high · {count(env.medium)} medium · {count(env.low)} low
|
|
</span>
|
|
<span className="text-secondary small ms-auto">
|
|
{env.imagesScanned === null ? "" : `${env.imagesScanned} of ${env.totalImages ?? "?"} images scanned`}
|
|
{unscanned !== null && unscanned > 0 ? ` — ${unscanned} not scanned yet` : ""}
|
|
</span>
|
|
</div>
|
|
{env.images && env.images.oldest.length > 0 && (
|
|
<div className="small text-secondary mt-1">
|
|
Oldest running images: {env.images.oldest.slice(0, 3).map((i) => `${i.image} (${ageText(i.ageDays)})`).join(", ")}
|
|
{imageAgeDays > 0 && env.images.over !== null ? (env.images.over > 0 ? ` — ${env.images.over} built more than ${imageAgeDays} days ago (an alert)` : ` — none older than ${imageAgeDays} days`) : ""}
|
|
{env.images.undated > 0 ? ` · ${env.images.undated} with no build date` : ""}
|
|
</div>
|
|
)}
|
|
{env.findings.length > 0 && (
|
|
<>
|
|
<button className="btn btn-link btn-sm p-0 mt-1" onClick={() => setOpen((o) => !o)}>
|
|
{open ? "Hide the critical findings" : `Show the critical findings${env.critical !== null && env.critical > env.findings.length ? ` (first ${env.findings.length} of ${env.critical})` : ""}`}
|
|
</button>
|
|
{open && (
|
|
<div className="table-responsive mt-2">
|
|
<table className="table table-sm table-vcenter">
|
|
<thead>
|
|
<tr>
|
|
<th>CVE</th>
|
|
<th>Package</th>
|
|
<th>Installed</th>
|
|
<th>Fixed in</th>
|
|
<th>Image</th>
|
|
<th>Used by</th>
|
|
</tr>
|
|
</thead>
|
|
<tbody>
|
|
{env.findings.map((f, i) => (
|
|
<tr key={`${f.cve}:${f.package}:${f.imageName}:${i}`}>
|
|
<td className="text-nowrap">{f.cve}</td>
|
|
<td className="text-break">{f.package}</td>
|
|
<td className="text-secondary text-break">{f.installedVersion || "—"}</td>
|
|
<td className="text-break">{f.fixedVersion ? <span className="text-green">{f.fixedVersion}</span> : <span className="text-secondary">no fix yet</span>}</td>
|
|
<td className="text-secondary text-break">{f.imageName}</td>
|
|
<td className="text-secondary text-break">{f.containers.length > 0 ? f.containers.join(", ") : "—"}</td>
|
|
</tr>
|
|
))}
|
|
</tbody>
|
|
</table>
|
|
</div>
|
|
)}
|
|
</>
|
|
)}
|
|
</div>
|
|
);
|
|
}
|
|
|
|
/** What Dockhand's own vulnerability scans found, per Docker host. Read from what was stored; nothing is asked of Dockhand here, and nothing is scanned. */
|
|
export default function DockerVulnerabilities({ integrationId }: { integrationId: number }) {
|
|
const [data, setData] = useState<DockhandVulnerabilitiesResponse | null>(null);
|
|
const [error, setError] = useState<string | null>(null);
|
|
useEffect(() => {
|
|
setData(null);
|
|
const load = () =>
|
|
api.integrations.dockhand
|
|
.vulnerabilities(integrationId)
|
|
.then((r) => {
|
|
setData(r);
|
|
setError(null);
|
|
})
|
|
.catch((err) => setError(readableError(err)));
|
|
void load();
|
|
const t = setInterval(load, 120_000);
|
|
return () => clearInterval(t);
|
|
}, [integrationId]);
|
|
|
|
const critical = (data?.environments ?? []).reduce((sum, e) => sum + (e.critical ?? 0), 0);
|
|
return (
|
|
<div className="card mt-3">
|
|
<div className="card-header">
|
|
<h3 className="card-title">
|
|
Vulnerabilities
|
|
{data && data.environments.length > 0 && (critical > 0 ? <span className="text-red fw-normal ms-2">{critical} critical</span> : <span className="text-secondary fw-normal ms-2">none critical</span>)}
|
|
</h3>
|
|
{data?.status && (
|
|
<div className="card-actions text-secondary small">
|
|
read <TimeAgo value={data.status.at} />
|
|
</div>
|
|
)}
|
|
</div>
|
|
<div className="card-body">
|
|
{error && <div className="text-yellow">{error}</div>}
|
|
{!data && !error && <div className="text-secondary">Reading…</div>}
|
|
{data && (
|
|
<>
|
|
<p className="text-secondary small">
|
|
From the scans Dockhand has already run on its images (it scans when it is told to — nothing is scanned from here). An image that was never scanned is not known to be clean.{" "}
|
|
{data.alerts ? (
|
|
<>
|
|
<strong>Critical</strong> findings are an alert — see <Link to="/alerts">Alerts</Link>;{" "}
|
|
{data.highThreshold > 0 ? (
|
|
<>
|
|
so is a host with <strong>{data.highThreshold} or more high</strong> ones (<Link to="/settings/notifications">Settings → Notifications</Link>); medium and low are only shown here.
|
|
</>
|
|
) : (
|
|
<>high, medium and low are only shown here (high ones can be alerted from a number you choose under Settings → Notifications).</>
|
|
)}
|
|
</>
|
|
) : (
|
|
<>
|
|
The alert for critical findings is switched off (<Link to="/settings/notifications">Settings → Notifications</Link>).
|
|
</>
|
|
)}
|
|
</p>
|
|
{data.status && !data.status.ok && <div className="text-yellow mb-2">The last attempt to read them failed: {data.status.error ?? "no answer"}.</div>}
|
|
{data.environments.length === 0 && !data.status && <div className="text-secondary">Not read yet — it is read a few minutes after Dockhand is added, then every quarter of an hour.</div>}
|
|
{data.environments.length === 0 && data.status?.ok && <div className="text-secondary">Dockhand lists no Docker hosts.</div>}
|
|
{data.environments.map((e) => (
|
|
<Host key={e.environmentId} env={e} imageAgeDays={data.imageAgeDays} />
|
|
))}
|
|
</>
|
|
)}
|
|
</div>
|
|
</div>
|
|
);
|
|
}
|