@astrofoundry/pi-astro 0.40.4 → 0.40.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -299,7 +299,8 @@ describe("security monitor", () => {
|
|
|
299
299
|
h.answers.set("arcane images vulnerabilities list", () => JSON.stringify({ data: [{ vulnerabilityId: "CVE-7", pkgName: "zlib", fixedVersion: "1.3.1", ignored: false, imageName: "nginx:latest" }] }));
|
|
300
300
|
await h.monitor.dailyReport(SCHEDULE, "2026-10-21");
|
|
301
301
|
const text = h.rest.messages[0].message.content;
|
|
302
|
-
expect(text).toContain("Arcane images · 1 critical CVE
|
|
302
|
+
expect(text).toContain("Arcane images · 1 critical CVE whose package has a fix, in 1 image · waiting on the publisher: nginx 1");
|
|
303
|
+
expect(h.calls).toContainEqual(["arcane", "images", "list", "--all"]);
|
|
303
304
|
expect(h.calls).toContainEqual(["arcane", "images", "vulnerabilities", "list", "--severity", "critical", "--all"]);
|
|
304
305
|
expect(text.split("\n")[0]).toBe("**Security Daily Report:** quiet day (24 h to 06:05 CEST)");
|
|
305
306
|
expect(text).toContain("CrowdSec · 2 bans, all front door SNI scanning");
|
|
@@ -33,6 +33,7 @@ import {
|
|
|
33
33
|
type OriginVerdict,
|
|
34
34
|
originArgs,
|
|
35
35
|
parseAttention,
|
|
36
|
+
parseImageBuilds,
|
|
36
37
|
parseImageVulns,
|
|
37
38
|
parseOrigin,
|
|
38
39
|
parseSecurityButton,
|
|
@@ -452,8 +453,10 @@ export class SecurityMonitor {
|
|
|
452
453
|
private async imageFacts(): Promise<{ images: ImageVulnFacts | null; offers: Map<string, ImageOffer>; arcaneChannelId?: string }> {
|
|
453
454
|
const summary = await this.read("images vulnerabilities summary", "arcane", ["images", "vulnerabilities", "summary"], (v) => (v && typeof v === "object" ? v : null));
|
|
454
455
|
const list = summary ? await this.read("images vulnerabilities list", "arcane", ["images", "vulnerabilities", "list", "--severity", "critical", "--all"], (v) => (v && typeof v === "object" ? v : null), 5 * MINUTE) : null;
|
|
455
|
-
const
|
|
456
|
-
if (summary && list && !
|
|
456
|
+
const parsed = summary && list ? parseImageVulns(summary, list) : null;
|
|
457
|
+
if (summary && list && !parsed) this.deps.log("security report: images vulnerabilities returned an unexpected answer");
|
|
458
|
+
const builds = parsed ? await this.read("images list", "arcane", ["images", "list", "--all"], (v) => (v && typeof v === "object" ? v : null), 5 * MINUTE) : null;
|
|
459
|
+
const images = parsed && builds ? { ...parsed, builds: parseImageBuilds(builds) } : parsed;
|
|
457
460
|
const arcaneChannelId = reportSchedule(this.deps.config(), "arcane")?.channelId;
|
|
458
461
|
return { images, offers: imageOffers(readPostedArcane()?.stacks ?? []), ...(arcaneChannelId ? { arcaneChannelId } : {}) };
|
|
459
462
|
}
|
|
@@ -37,6 +37,8 @@ import {
|
|
|
37
37
|
imageOffers,
|
|
38
38
|
imageVulnLine,
|
|
39
39
|
type ImageVulnFacts,
|
|
40
|
+
parseImageBuilds,
|
|
41
|
+
shortImageName,
|
|
40
42
|
offeredImages,
|
|
41
43
|
parseImageVulns,
|
|
42
44
|
nasOutage,
|
|
@@ -417,13 +419,42 @@ describe("Arcane image scans", () => {
|
|
|
417
419
|
],
|
|
418
420
|
};
|
|
419
421
|
expect(imageVulnLine(facts, offers, "1549873938140499999")).toBe(
|
|
420
|
-
"Arcane images · 5 critical CVEs
|
|
422
|
+
"Arcane images · 5 critical CVEs whose package has a fix, in 3 images · update offered in <#1549873938140499999>: mealie 3 (mealie) · held: postgres:15.8.1.085 1 (supabase: coordinated release: review first) · waiting on the publisher: nginx 1",
|
|
421
423
|
);
|
|
422
424
|
expect(offeredImages(facts, offers)).toEqual(["mealie"]);
|
|
423
425
|
expect(offeredImages(null, offers)).toEqual([]);
|
|
424
426
|
expect(imageVulnLine(null, offers)).toBe("Arcane images · the check failed");
|
|
425
427
|
expect(imageVulnLine({ scanned: 0, total: 57, critical: [] }, offers)).toBe("Arcane images · no Trivy scan yet (57 images)");
|
|
426
|
-
expect(imageVulnLine({ ...facts, critical: facts.critical.slice(4) }, new Map(), undefined, 0)).toBe("Arcane images · 1 critical CVE
|
|
428
|
+
expect(imageVulnLine({ ...facts, critical: facts.critical.slice(4) }, new Map(), undefined, 0)).toBe("Arcane images · 1 critical CVE whose package has a fix, in 1 image · waiting on the publisher: +1 more");
|
|
429
|
+
});
|
|
430
|
+
|
|
431
|
+
it("names our own images with their build date and a newer build waiting in the registry", () => {
|
|
432
|
+
const list = { data: [
|
|
433
|
+
{ repoTags: ["ghcr.io/astronaute77/arcane-graphile-worker:latest"], created: 1788801615, updateInfo: { hasUpdate: true } },
|
|
434
|
+
{ repoTags: ["ghcr.io/monadeo/grimoire-server:v0.27.57"], created: 1790000000, updateInfo: null },
|
|
435
|
+
{ repoTags: "bad" },
|
|
436
|
+
] };
|
|
437
|
+
const builds = parseImageBuilds(list);
|
|
438
|
+
expect(builds.get("ghcr.io/astronaute77/arcane-graphile-worker:latest")).toEqual({ created: 1788801615, newer: true });
|
|
439
|
+
expect(parseImageBuilds([{ repoTags: ["a:1"], created: 1 }]).get("a:1")).toEqual({ created: 1, newer: false });
|
|
440
|
+
expect(parseImageBuilds(null).size).toBe(0);
|
|
441
|
+
const facts: ImageVulnFacts = {
|
|
442
|
+
scanned: 20,
|
|
443
|
+
total: 57,
|
|
444
|
+
critical: [
|
|
445
|
+
{ id: "CVE-1", pkg: "glib", image: "ghcr.io/astronaute77/arcane-graphile-worker:latest" },
|
|
446
|
+
{ id: "CVE-2", pkg: "glib", image: "ghcr.io/astronaute77/arcane-graphile-worker:latest" },
|
|
447
|
+
{ id: "CVE-3", pkg: "zlib", image: "ghcr.io/monadeo/grimoire-server:v0.27.57@sha256:a86042bb83d85203283135f6f2762c85161a0d2458d9a5378e1a59174b946147" },
|
|
448
|
+
{ id: "CVE-4", pkg: "openssl", image: "ghcr.io/astrofoundry/bigcapital-redis:astrofoundry" },
|
|
449
|
+
{ id: "CVE-5", pkg: "pyjwt", image: "unclecode/crawl4ai:latest" },
|
|
450
|
+
{ id: "CVE-6", pkg: "openssl", image: "ghcr.io/hotio/lidarr:pr-plugins" },
|
|
451
|
+
],
|
|
452
|
+
builds,
|
|
453
|
+
};
|
|
454
|
+
expect(imageVulnLine(facts, new Map(), undefined, 1)).toBe(
|
|
455
|
+
"Arcane images · 6 critical CVEs whose package has a fix, in 5 images · ours to rebuild: arcane-graphile-worker 2 (built 7 Sept, a newer build waits in the registry), bigcapital-redis:astrofoundry 1 (build date unknown), grimoire-server:v0.27.57 1 (built 21 Sept) · waiting on the publisher: lidarr:pr-plugins 1, +1 more",
|
|
456
|
+
);
|
|
457
|
+
expect(shortImageName("postgres:18.6")).toBe("postgres:18.6");
|
|
427
458
|
});
|
|
428
459
|
});
|
|
429
460
|
|
|
@@ -575,12 +575,24 @@ export interface ImageVuln {
|
|
|
575
575
|
image: string;
|
|
576
576
|
}
|
|
577
577
|
|
|
578
|
+
/** What `images list` says about one image tag: when it was built, and whether its registry has a newer build. */
|
|
579
|
+
export interface ImageBuild {
|
|
580
|
+
/** Unix seconds. */
|
|
581
|
+
created: number | null;
|
|
582
|
+
newer: boolean;
|
|
583
|
+
}
|
|
584
|
+
|
|
578
585
|
export interface ImageVulnFacts {
|
|
579
586
|
scanned: number;
|
|
580
587
|
total: number;
|
|
581
588
|
critical: ImageVuln[];
|
|
589
|
+
/** Build facts by tag, for the images we build ourselves. */
|
|
590
|
+
builds?: ReadonlyMap<string, ImageBuild>;
|
|
582
591
|
}
|
|
583
592
|
|
|
593
|
+
/** Image namespaces our own CI builds: their CVEs wait on our rebuild, everything else on its publisher. */
|
|
594
|
+
export const OWN_IMAGE_PREFIXES = ["ghcr.io/astronaute77/", "ghcr.io/astrofoundry/", "ghcr.io/monadeo/"];
|
|
595
|
+
|
|
584
596
|
/** What the newest Arcane Daily Report offers for the stack that runs an image. */
|
|
585
597
|
export interface ImageOffer {
|
|
586
598
|
stack: string;
|
|
@@ -603,6 +615,19 @@ export function parseImageVulns(summary: unknown, list: unknown): ImageVulnFacts
|
|
|
603
615
|
return { scanned: s.scannedImages, total: s.totalImages, critical };
|
|
604
616
|
}
|
|
605
617
|
|
|
618
|
+
/** `images list --all`: build time and pending newer build for every tag. */
|
|
619
|
+
export function parseImageBuilds(list: unknown): Map<string, ImageBuild> {
|
|
620
|
+
const rows = Array.isArray(list) ? list : (list as { data?: unknown } | null)?.data;
|
|
621
|
+
const out = new Map<string, ImageBuild>();
|
|
622
|
+
if (!Array.isArray(rows)) return out;
|
|
623
|
+
for (const row of rows as Record<string, unknown>[]) {
|
|
624
|
+
const tags = Array.isArray(row.repoTags) ? row.repoTags.filter((t): t is string => typeof t === "string") : [];
|
|
625
|
+
const build = { created: typeof row.created === "number" ? row.created : null, newer: (row.updateInfo as { hasUpdate?: unknown } | null | undefined)?.hasUpdate === true };
|
|
626
|
+
for (const tag of tags) out.set(tag, build);
|
|
627
|
+
}
|
|
628
|
+
return out;
|
|
629
|
+
}
|
|
630
|
+
|
|
606
631
|
function repositoryOf(ref: string): string | null {
|
|
607
632
|
try {
|
|
608
633
|
const r = parseImageRef(ref);
|
|
@@ -624,12 +649,6 @@ export function imageOffers(stacks: readonly { stack: string; lines: { ref?: str
|
|
|
624
649
|
return out;
|
|
625
650
|
}
|
|
626
651
|
|
|
627
|
-
function offerText(offer: ImageOffer | undefined, arcaneChannelId: string | undefined): string {
|
|
628
|
-
if (offer?.offered) return `update offered: Update on ${escapeDiscord(offer.stack)} in the Arcane Daily Report${arcaneChannelId ? ` (<#${arcaneChannelId}>)` : ""}`;
|
|
629
|
-
if (offer?.held) return `${escapeDiscord(offer.stack)} is held: ${escapeDiscord(offer.held)}`;
|
|
630
|
-
return "no newer image offered yet";
|
|
631
|
-
}
|
|
632
|
-
|
|
633
652
|
/** Images with critical CVEs that an update in the newest Arcane Daily Report would replace. */
|
|
634
653
|
export function offeredImages(facts: ImageVulnFacts | null, offers: ReadonlyMap<string, ImageOffer>): string[] {
|
|
635
654
|
if (!facts) return [];
|
|
@@ -641,21 +660,59 @@ export function offeredImages(facts: ImageVulnFacts | null, offers: ReadonlyMap<
|
|
|
641
660
|
return [...stacks].sort();
|
|
642
661
|
}
|
|
643
662
|
|
|
644
|
-
|
|
663
|
+
function isOwnImage(image: string): boolean {
|
|
664
|
+
const repo = repositoryOf(image);
|
|
665
|
+
return repo !== null && OWN_IMAGE_PREFIXES.some((p) => repo.startsWith(p));
|
|
666
|
+
}
|
|
667
|
+
|
|
668
|
+
/** `crawl4ai`, `lidarr:pr-plugins`, `grimoire-server:v0.27.57`: the last path segment, with its tag unless it is latest. */
|
|
669
|
+
export function shortImageName(image: string): string {
|
|
670
|
+
try {
|
|
671
|
+
const r = parseImageRef(image);
|
|
672
|
+
const name = r.repository.split("/").pop() ?? r.repository;
|
|
673
|
+
return r.tag && r.tag !== "latest" ? `${name}:${r.tag}` : name;
|
|
674
|
+
} catch {
|
|
675
|
+
return image;
|
|
676
|
+
}
|
|
677
|
+
}
|
|
678
|
+
|
|
679
|
+
function buildText(build: ImageBuild | undefined): string {
|
|
680
|
+
const built = build?.created ? `built ${new Intl.DateTimeFormat("en-GB", { timeZone: "UTC", day: "numeric", month: "short" }).format(new Date(build.created * 1000))}` : "build date unknown";
|
|
681
|
+
return build?.newer ? `${built}, a newer build waits in the registry` : built;
|
|
682
|
+
}
|
|
683
|
+
|
|
684
|
+
/**
|
|
685
|
+
* Critical CVEs whose package has a fixed version, grouped by who can act:
|
|
686
|
+
* our own images (with their build date), images an update in the Arcane
|
|
687
|
+
* Daily Report replaces, held stacks, and images waiting on their publisher.
|
|
688
|
+
*/
|
|
689
|
+
export function imageVulnLine(facts: ImageVulnFacts | null, offers: ReadonlyMap<string, ImageOffer>, arcaneChannelId?: string, maxWaiting = 5): string {
|
|
645
690
|
if (!facts) return "Arcane images · the check failed";
|
|
646
691
|
if (facts.scanned === 0) return `Arcane images · no Trivy scan yet (${facts.total} images)`;
|
|
647
692
|
if (facts.critical.length === 0) return `Arcane images · no critical CVE with a fix (${facts.scanned} of ${facts.total} images scanned)`;
|
|
648
|
-
const
|
|
649
|
-
for (const v of facts.critical)
|
|
650
|
-
const
|
|
651
|
-
const
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
693
|
+
const counts = new Map<string, number>();
|
|
694
|
+
for (const v of facts.critical) counts.set(v.image, (counts.get(v.image) ?? 0) + 1);
|
|
695
|
+
const images = [...counts.entries()].sort((x, y) => y[1] - x[1] || x[0].localeCompare(y[0]));
|
|
696
|
+
const own: string[] = [];
|
|
697
|
+
const offered: string[] = [];
|
|
698
|
+
const held: string[] = [];
|
|
699
|
+
const waiting: string[] = [];
|
|
700
|
+
for (const [image, n] of images) {
|
|
701
|
+
const name = `${escapeDiscord(shortImageName(image))} ${n}`;
|
|
702
|
+
const offer = offers.get(repositoryOf(image) ?? "");
|
|
703
|
+
if (isOwnImage(image)) own.push(`${name} (${buildText(facts.builds?.get(image) ?? facts.builds?.get(image.split("@")[0]))})`);
|
|
704
|
+
else if (offer?.offered) offered.push(`${name} (${escapeDiscord(offer.stack)})`);
|
|
705
|
+
else if (offer?.held) held.push(`${name} (${escapeDiscord(offer.stack)}: ${escapeDiscord(offer.held)})`);
|
|
706
|
+
else waiting.push(name);
|
|
707
|
+
}
|
|
657
708
|
const n = facts.critical.length;
|
|
658
|
-
|
|
709
|
+
const parts = [`Arcane images · ${n} critical CVE${n === 1 ? "" : "s"} whose package has a fix, in ${images.length} image${images.length === 1 ? "" : "s"}`];
|
|
710
|
+
if (own.length > 0) parts.push(`ours to rebuild: ${own.join(", ")}`);
|
|
711
|
+
if (offered.length > 0) parts.push(`update offered${arcaneChannelId ? ` in <#${arcaneChannelId}>` : " in the Arcane Daily Report"}: ${offered.join(", ")}`);
|
|
712
|
+
if (held.length > 0) parts.push(`held: ${held.join(", ")}`);
|
|
713
|
+
const rest = waiting.length - Math.min(waiting.length, maxWaiting);
|
|
714
|
+
if (waiting.length > 0) parts.push(`waiting on the publisher: ${[...waiting.slice(0, maxWaiting), ...(rest > 0 ? [`+${rest} more`] : [])].join(", ")}`);
|
|
715
|
+
return parts.join(" · ");
|
|
659
716
|
}
|
|
660
717
|
|
|
661
718
|
// ---------------------------------------------------------------- reports
|