@astrofoundry/pi-astro 0.40.61 → 0.40.63
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.
- package/extensions/astro-discord/daily-run.test.ts +13 -5
- package/extensions/astro-discord/daily-run.ts +14 -2
- package/extensions/astro-discord/index.ts +1 -1
- package/extensions/astro-discord/security-monitor.test.ts +1 -1
- package/extensions/astro-discord/security-monitor.ts +6 -5
- package/extensions/astro-discord/security.test.ts +31 -3
- package/extensions/astro-discord/security.ts +57 -12
- package/package.json +1 -1
- package/specialists/entry/remote/spc-identity-dmz-entry.sh +15 -1
- package/specialists/identity/run.ts +2 -2
- package/specialists/wrappers.test.ts +2 -1
|
@@ -227,11 +227,11 @@ describe("report summaries", () => {
|
|
|
227
227
|
const tool = (over: Partial<ToolsReport["lines"][number]>): ToolsReport["lines"][number] => ({ key: "brew:jq", label: "jq", installed: "1.8.1", latest: "1.8.2", major: false, action: { kind: "brew", name: "jq" }, state: "offered", ...over }) as ToolsReport["lines"][number];
|
|
228
228
|
|
|
229
229
|
it("says what the tools report updated, what failed, and what waits for a button", () => {
|
|
230
|
-
const report = { date: "2026-10-24", lines: [tool({ state: "updated", plan: "auto" }), tool({ key: "brew:herdr", label: "herdr", latest: "0.10.0", state: "failed", plan: "auto" }), tool({ key: "pi", label: "Pi", latest: "1.4.0", plan: "button" }), tool({ key: "spc:node", label: "Node", latest: "26.1.0", major: true, plan: "update" })], messages: [{ id: "9", keys: [], head: true, all: false }] } as unknown as ToolsReport;
|
|
230
|
+
const report = { date: "2026-10-24", lines: [tool({ state: "updated", plan: "auto" }), tool({ key: "brew:herdr", label: "herdr", latest: "0.10.0", state: "failed", plan: "auto" }), tool({ key: "pi", label: "Pi", latest: "1.4.0", plan: "button" }), tool({ key: "spc:node", label: "Node", latest: "26.1.0", major: true, plan: "update" }), tool({ key: "cask:temurin@17", label: "temurin@17", latest: "17.0.18", plan: "auto", manual: "its installer asks for your password; on Cortex: brew upgrade --cask temurin@17" })], messages: [{ id: "9", keys: [], head: true, all: false }] } as unknown as ToolsReport;
|
|
231
231
|
expect(toolsSummary(report, "2026-10-24", "5")).toEqual({
|
|
232
232
|
area: "Cortex tools",
|
|
233
|
-
line: "1 updated (jq 1.8.2), 1 failed (herdr), Pi 1.4.0, Node 26.1.0 wait for a button",
|
|
234
|
-
needs: ["Node 26.1.0 waits for its button (major version)", "Pi 1.4.0 waits for its button", "herdr automatic update failed"],
|
|
233
|
+
line: "1 updated (jq 1.8.2), 1 failed (herdr), Pi 1.4.0, Node 26.1.0 wait for a button, 1 by hand",
|
|
234
|
+
needs: ["Node 26.1.0 waits for its button (major version)", "Pi 1.4.0 waits for its button", "herdr automatic update failed", "temurin@17 17.0.18 by hand: its installer asks for your password; on Cortex: brew upgrade --cask temurin@17"],
|
|
235
235
|
channelId: "5",
|
|
236
236
|
messageId: "9",
|
|
237
237
|
});
|
|
@@ -240,11 +240,19 @@ describe("report summaries", () => {
|
|
|
240
240
|
|
|
241
241
|
it("says what the Arcane report updated, rolled back, and leaves to the owner", () => {
|
|
242
242
|
const stack = (name: string, over: Partial<ArcaneReport["stacks"][number]>) => ({ stack: name, lines: [], actionable: true, state: "offered", ...over }) as ArcaneReport["stacks"][number];
|
|
243
|
-
const
|
|
243
|
+
const line = (over: Partial<ArcaneReport["stacks"][number]["lines"][number]>) => ({ service: "gotenberg", status: "current", action: "", running: "8.40.0", latest: "8.40.0", tag: "8.40.0", major: false, note: "newer major 9 available", ...over }) as ArcaneReport["stacks"][number]["lines"][number];
|
|
244
|
+
const stacks = [
|
|
245
|
+
stack("media", { plan: "auto", state: "updated" }),
|
|
246
|
+
stack("mealie", { plan: "auto", state: "rolled back" }),
|
|
247
|
+
stack("stirling-pdf", { plan: "careful" }),
|
|
248
|
+
stack("supabase", { actionable: false, held: "review first" }),
|
|
249
|
+
stack("paperless", { actionable: false, lines: [line({}), line({ service: "broker", status: "unknown", note: "registry timeout" })] }),
|
|
250
|
+
];
|
|
251
|
+
const report = { date: "2026-10-24", stacks, messages: [{ id: "8", stacks: [], head: true }] } as unknown as ArcaneReport;
|
|
244
252
|
expect(arcaneSummary(report, "2026-10-24", "6")).toEqual({
|
|
245
253
|
area: "Arcane",
|
|
246
254
|
line: "1 stack updated (media), mealie rolled back, stirling-pdf waits for you, supabase held",
|
|
247
|
-
needs: ["stirling-pdf waits for you (Upgrade carefully)", "mealie automatic update rolled back"],
|
|
255
|
+
needs: ["stirling-pdf waits for you (Upgrade carefully)", "mealie automatic update rolled back", "supabase update held: review first", "paperless gotenberg 8.40.0: major 9 needs a tag change by hand", "paperless broker: the update check failed"],
|
|
248
256
|
channelId: "6",
|
|
249
257
|
messageId: "8",
|
|
250
258
|
});
|
|
@@ -369,7 +369,7 @@ export function macosStatus(macs: readonly MacUpdates[]): AreaStatus {
|
|
|
369
369
|
export interface ReportLine {
|
|
370
370
|
area: string;
|
|
371
371
|
line: string;
|
|
372
|
-
/** Items the report tagged
|
|
372
|
+
/** Items that need the owners: what the report tagged them for, waits for them, or must be done by hand. */
|
|
373
373
|
needs: string[];
|
|
374
374
|
channelId?: string;
|
|
375
375
|
messageId?: string;
|
|
@@ -396,11 +396,20 @@ export function toolsSummary(report: ToolsReport | null, date: string, channelId
|
|
|
396
396
|
...report.lines.filter((l) => l.plan === "update" && l.state === "offered").map((l) => `${escapeDiscord(l.label)} ${escapeDiscord(l.latest)} waits for its button (${l.major ? "major version" : "release notes"})`),
|
|
397
397
|
...report.lines.filter((l) => l.plan === "button" && l.state === "offered").map((l) => `${escapeDiscord(l.label)} ${escapeDiscord(l.latest)} waits for its button`),
|
|
398
398
|
...failed.filter((l) => l.plan === "auto").map((l) => `${escapeDiscord(l.label)} automatic update failed`),
|
|
399
|
+
...manual.map((l) => `${escapeDiscord(l.label)} ${escapeDiscord(l.latest)} by hand: ${escapeDiscord(l.manual ?? "")}`),
|
|
399
400
|
];
|
|
400
401
|
return { area: "Cortex tools", line: parts.join(", ") || "everything up to date", needs, channelId, ...(report.messages[0] ? { messageId: report.messages[0].id } : {}) };
|
|
401
402
|
}
|
|
402
403
|
|
|
403
|
-
/**
|
|
404
|
+
/** A service line only the owner can act on: a failed check, or a newer major that needs a tag change by hand. */
|
|
405
|
+
function byHand(stack: string, l: ArcaneReport["stacks"][number]["lines"][number]): string | null {
|
|
406
|
+
const where = `${escapeDiscord(stack)} ${escapeDiscord(l.service)}`;
|
|
407
|
+
if (l.status === "unknown") return `${where}: the update check failed`;
|
|
408
|
+
const newer = /newer major (\S+) available/.exec(l.note)?.[1];
|
|
409
|
+
return newer ? `${where} ${escapeDiscord(l.running ?? l.tag)}: major ${escapeDiscord(newer)} needs a tag change by hand` : null;
|
|
410
|
+
}
|
|
411
|
+
|
|
412
|
+
/** The Arcane Daily Report after its automatic updates and checks: updated, rolled back, waiting for the owner, held, by hand. */
|
|
404
413
|
export function arcaneSummary(report: ArcaneReport | null, date: string, channelId: string): ReportLine {
|
|
405
414
|
if (!report || report.date !== date) return { area: "Arcane", line: "no report today; the bridge log has the reason", needs: ["the Arcane Daily Report did not run today; the bridge log has the reason"], channelId };
|
|
406
415
|
const by = (pick: (s: ArcaneReport["stacks"][number]) => boolean) => report.stacks.filter(pick).map((s) => s.stack);
|
|
@@ -419,6 +428,9 @@ export function arcaneSummary(report: ArcaneReport | null, date: string, channel
|
|
|
419
428
|
const needs = [
|
|
420
429
|
...waiting.map((s) => `${escapeDiscord(s.stack)} waits for you (${s.plan === "careful" ? "Upgrade carefully" : "major version"})`),
|
|
421
430
|
...report.stacks.filter((s) => s.plan === "auto" && (s.state === "rolled back" || s.state === "failed")).map((s) => `${escapeDiscord(s.stack)} automatic update ${s.state}`),
|
|
431
|
+
...report.stacks.filter((s) => s.held !== undefined).map((s) => `${escapeDiscord(s.stack)} update held: ${escapeDiscord(s.held ?? "")}`),
|
|
432
|
+
...report.stacks.flatMap((s) => s.lines.map((l) => byHand(s.stack, l)).filter((t): t is string => t !== null)),
|
|
433
|
+
...(report.holdsError ? [`update-holds.json is unreadable: ${escapeDiscord(report.holdsError)}`] : []),
|
|
422
434
|
];
|
|
423
435
|
return { area: "Arcane", line: parts.join(", ") || "no updates", needs, channelId, ...(report.messages[0] ? { messageId: report.messages[0].id } : {}) };
|
|
424
436
|
}
|
|
@@ -613,7 +613,7 @@ class Bridge {
|
|
|
613
613
|
const name: ReportName = monday ? "security-weekly" : "security";
|
|
614
614
|
const posted = done(name) ? undefined : await (monday ? this.security.weeklyReport(securitySchedule, date) : this.security.dailyReport(securitySchedule, date)).catch((err) => log(`daily ${date}: security report failed: ${err instanceof Error ? err.message : String(err)}`));
|
|
615
615
|
const area = monday ? "Security (weekly)" : "Security";
|
|
616
|
-
reports.push(posted ? { area, line: posted.headline, needs: posted.
|
|
616
|
+
reports.push(posted ? { area, line: posted.headline, needs: posted.needs, channelId: securitySchedule.channelId, messageId: posted.messageId } : { area, line: done(name) ? "already posted today" : "the report failed; the bridge log has the reason", needs: done(name) ? [] : ["the security report failed; the bridge log has the reason"], channelId: securitySchedule.channelId });
|
|
617
617
|
}
|
|
618
618
|
const tools = reportSchedule(this.config, "tools");
|
|
619
619
|
if (tools && !this.stopping) {
|
|
@@ -309,7 +309,7 @@ describe("security monitor", () => {
|
|
|
309
309
|
expect(text).not.toContain("waiting on the publisher");
|
|
310
310
|
expect(h.calls).toContainEqual(["arcane", "images", "list", "--all"]);
|
|
311
311
|
expect(h.calls).toContainEqual(["arcane", "images", "vulnerabilities", "list", "--severity", "critical", "--all"]);
|
|
312
|
-
expect(summary).toEqual({ headline: "quiet day (24 h to 06:05 CEST)",
|
|
312
|
+
expect(summary).toEqual({ headline: "quiet day (24 h to 06:05 CEST)", needs: [], messageId: "100" });
|
|
313
313
|
expect(text).toContain("## 🛡️ Security Daily Report\\n🟢 quiet day · 24 h to 06:05 CEST");
|
|
314
314
|
expect(text).toContain("🚫 **CrowdSec** · 2 bans, all front door SNI scanning");
|
|
315
315
|
expect(text).toContain("📦 **Host packages** · 1 new CVE on 1 host, fixed versions exist\\n- CVE-1 (openssl, High 7.5) on dmz");
|
|
@@ -94,7 +94,8 @@ export interface SecurityClick {
|
|
|
94
94
|
/** What a posted security report tells the morning summary. */
|
|
95
95
|
export interface PostedSummary {
|
|
96
96
|
headline: string;
|
|
97
|
-
|
|
97
|
+
/** What the report lists under Needs you. */
|
|
98
|
+
needs: string[];
|
|
98
99
|
messageId: string;
|
|
99
100
|
}
|
|
100
101
|
|
|
@@ -460,7 +461,7 @@ export class SecurityMonitor {
|
|
|
460
461
|
return (await this.deps.rest.createComponentsMessage(channelId, report.components, report.mention ? this.owners() : undefined)).id;
|
|
461
462
|
}
|
|
462
463
|
|
|
463
|
-
/** Posts the Security Daily Report; returns its headline and
|
|
464
|
+
/** Posts the Security Daily Report; returns its headline and what needs the owners, for the morning summary. */
|
|
464
465
|
async dailyReport(s: ReportSchedule, date: string): Promise<PostedSummary | undefined> {
|
|
465
466
|
const now = this.deps.now();
|
|
466
467
|
if (reportSchedule(this.deps.config(), "security-weekly") && zonedWeekday(s.timeZone, new Date(now)) === MONDAY) {
|
|
@@ -478,13 +479,13 @@ export class SecurityMonitor {
|
|
|
478
479
|
const state = readSecurityState();
|
|
479
480
|
const wazuh = wazuhDigest(events, state.origins, (e) => acked(state, e));
|
|
480
481
|
if (this.deps.stopping()) return;
|
|
481
|
-
const data = { until: clockText(new Date(now).toISOString(), s.timeZone).replace(/^\d+ \w+ /, ""), crowdsec, wazuh, found: vulns?.found ?? null, closed: vulns?.closed ?? null, attention, ...images };
|
|
482
|
+
const data = { until: clockText(new Date(now).toISOString(), s.timeZone).replace(/^\d+ \w+ /, ""), timeZone: s.timeZone, crowdsec, wazuh, found: vulns?.found ?? null, closed: vulns?.closed ?? null, attention, ...images, alerts: state.alerts };
|
|
482
483
|
writeReportState("security", { date, status: "sending" });
|
|
483
484
|
const report = dailyCard(data, this.owners());
|
|
484
485
|
const id = await this.postReport(s.channelId, report);
|
|
485
486
|
writeReportState("security", { date, status: "sent", messageId: id });
|
|
486
487
|
this.deps.log(`security report ${date}: posted`);
|
|
487
|
-
return { headline: report.headline,
|
|
488
|
+
return { headline: report.headline, needs: report.needs, messageId: id };
|
|
488
489
|
}
|
|
489
490
|
|
|
490
491
|
async weeklyReport(s: ReportSchedule, date: string): Promise<PostedSummary | undefined> {
|
|
@@ -543,7 +544,7 @@ export class SecurityMonitor {
|
|
|
543
544
|
const id = await this.postReport(s.channelId, report);
|
|
544
545
|
writeReportState("security-weekly", { date, status: "sent", messageId: id });
|
|
545
546
|
this.deps.log(`security weekly report ${date}: posted`);
|
|
546
|
-
return { headline: report.headline,
|
|
547
|
+
return { headline: report.headline, needs: report.needs, messageId: id };
|
|
547
548
|
}
|
|
548
549
|
|
|
549
550
|
// ------------------------------------------------------------ buttons
|
|
@@ -17,6 +17,7 @@ import {
|
|
|
17
17
|
crowdsecDailyLine,
|
|
18
18
|
crowdsecWeeklyLine,
|
|
19
19
|
dailyCard,
|
|
20
|
+
dailyNeeds,
|
|
20
21
|
dailyNeedsOwner,
|
|
21
22
|
emptyState,
|
|
22
23
|
healthChange,
|
|
@@ -481,9 +482,10 @@ describe("daily report", () => {
|
|
|
481
482
|
const attention = parseAttention({ checked_at: "x", bouncer: { count: 1, oldest_pull_seconds: 6 }, wazuh_agents: { total: 8, active: 8 }, health_issues: [] });
|
|
482
483
|
|
|
483
484
|
it("reads quiet day in a green card and tags nobody when nothing is open", () => {
|
|
484
|
-
const data = { until: "06:00 CEST", crowdsec: summary(), wazuh: wazuhDigest([], {}, () => false), found: [], closed: [], attention, images: { scanned: 57, total: 57, critical: [] }, offers: new Map() };
|
|
485
|
+
const data = { until: "06:00 CEST", timeZone: TZ, crowdsec: summary(), wazuh: wazuhDigest([], {}, () => false), found: [], closed: [], attention, images: { scanned: 57, total: 57, critical: [] }, offers: new Map(), alerts: [] };
|
|
485
486
|
const report = dailyCard(data, [OWNER]);
|
|
486
487
|
expect(report.headline).toBe("quiet day (24 h to 06:00 CEST)");
|
|
488
|
+
expect(report.needs).toEqual([]);
|
|
487
489
|
expect(report.mention).toBe(false);
|
|
488
490
|
expect(report.components).toEqual([
|
|
489
491
|
{
|
|
@@ -507,14 +509,40 @@ describe("daily report", () => {
|
|
|
507
509
|
|
|
508
510
|
it("names urgent alerts and failed checks in an orange card and tags the owner while something is open", () => {
|
|
509
511
|
const wazuh = wazuhDigest([event({ rule: "5712", level: 12, description: "brute force" })], {}, () => false);
|
|
510
|
-
const data = { until: "06:00 CEST", crowdsec: null, wazuh, found: [], closed: [], attention, images: { scanned: 57, total: 57, critical: [] }, offers: new Map() };
|
|
512
|
+
const data = { until: "06:00 CEST", timeZone: TZ, crowdsec: null, wazuh, found: [], closed: [], attention, images: { scanned: 57, total: 57, critical: [] }, offers: new Map(), alerts: [{ key: alertKey(event({ rule: "5712" })), channelId: "c9" }] };
|
|
511
513
|
const report = dailyCard(data, [OWNER]);
|
|
512
514
|
expect(report.headline).toBe("1 urgent alert, 1 check failed (24 h to 06:00 CEST)");
|
|
515
|
+
expect(report.needs).toEqual(["urgent alert not acknowledged: brute force on arcane, 20 Oct 14:50 CEST; Acknowledge it in <#c9>", "1 check of this report failed; the bridge log on Cortex has the reason"]);
|
|
513
516
|
expect(report.mention).toBe(true);
|
|
514
517
|
expect(report.components[0].accent_color).toBe(0xe67e22);
|
|
515
|
-
expect(texts(report.components)
|
|
518
|
+
expect(texts(report.components).slice(0, 2)).toEqual([
|
|
519
|
+
"## 🛡️ Security Daily Report\n🟠 1 urgent alert, 1 check failed · 24 h to 06:00 CEST",
|
|
520
|
+
"### Needs you\n1. urgent alert not acknowledged: brute force on arcane, 20 Oct 14:50 CEST; Acknowledge it in <#c9>\n2. 1 check of this report failed; the bridge log on Cortex has the reason",
|
|
521
|
+
]);
|
|
516
522
|
expect(report.components[1]).toEqual({ type: 10, content: `<@${OWNER}>` });
|
|
517
523
|
});
|
|
524
|
+
|
|
525
|
+
it("leaves out a NAS loss that a later restore ended and names our images to rebuild", () => {
|
|
526
|
+
const lost = event({ id: "n1", rule: "100012", level: 12, timestamp: "2026-10-20T01:00:00.000+0000" });
|
|
527
|
+
const back = event({ id: "n2", rule: "100013", level: 10, timestamp: "2026-10-20T01:05:00.000+0000" });
|
|
528
|
+
const oom = event({ id: "o1", agent: "space-x", rule: "5108", level: 12, description: "System running out of memory. Availability of the system is in risk.", timestamp: "2026-10-20T06:24:00.000+0000" });
|
|
529
|
+
const wazuh = wazuhDigest([lost, back, oom], {}, () => false);
|
|
530
|
+
expect(wazuh.unacknowledged.map((e) => e.id)).toEqual(["n1", "o1"]);
|
|
531
|
+
expect(wazuh.open.map((e) => e.id)).toEqual(["o1"]);
|
|
532
|
+
const builds = new Map([["ghcr.io/astrofoundry/app:1", { created: 1, newer: false }], ["ghcr.io/astrofoundry/web:1", { created: 1, newer: true }]]);
|
|
533
|
+
const critical = [
|
|
534
|
+
{ id: "CVE-1", pkg: "a", image: "ghcr.io/astrofoundry/app:1" },
|
|
535
|
+
{ id: "CVE-2", pkg: "b", image: "ghcr.io/astrofoundry/app:1" },
|
|
536
|
+
{ id: "CVE-3", pkg: "c", image: "ghcr.io/astrofoundry/web:1" },
|
|
537
|
+
{ id: "CVE-4", pkg: "d", image: "docker.io/library/redis:7" },
|
|
538
|
+
];
|
|
539
|
+
const data = { until: "06:00 CEST", timeZone: TZ, crowdsec: summary(), wazuh, found: [], closed: [], attention, images: { scanned: 57, total: 57, critical, builds }, offers: new Map(), alerts: [{ key: alertKey(oom), channelId: "c9" }] };
|
|
540
|
+
expect(dailyNeeds(data)).toEqual([
|
|
541
|
+
"urgent alert not acknowledged: System running out of memory. Availability of the system is in risk on space-x, 20 Oct 08:24 CEST; Acknowledge it in <#c9>",
|
|
542
|
+
"rebuild app:1 (2): our images carry critical CVEs that have a fixed version",
|
|
543
|
+
]);
|
|
544
|
+
expect(dailyCard(data, [OWNER]).components[0].accent_color).toBe(0xe67e22);
|
|
545
|
+
});
|
|
518
546
|
});
|
|
519
547
|
|
|
520
548
|
describe("weekly report", () => {
|
|
@@ -410,6 +410,8 @@ export interface WazuhDigest {
|
|
|
410
410
|
urgent: number;
|
|
411
411
|
/** Urgent events that were not acknowledged when they came. */
|
|
412
412
|
unacknowledged: WazuhEvent[];
|
|
413
|
+
/** Unacknowledged events still open: a NAS loss that a later restore on the same agent ended is not. */
|
|
414
|
+
open: WazuhEvent[];
|
|
413
415
|
/** Deployment-file changes no commit or operation of ours explains. */
|
|
414
416
|
unexplained: WazuhEvent[];
|
|
415
417
|
}
|
|
@@ -421,8 +423,8 @@ function originCount(n: number, of: number): string {
|
|
|
421
423
|
|
|
422
424
|
/** The Wazuh line of a report: alerts at level 10 or higher, grouped by issue and agent, urgent ones first. */
|
|
423
425
|
export function wazuhDigest(events: readonly WazuhEvent[] | null, origins: SecurityState["origins"], acked: (e: WazuhEvent) => boolean, maxGroups = 4): WazuhDigest {
|
|
424
|
-
if (!events) return { line: "Wazuh · the check failed", failed: true, count: 0, urgent: 0, unacknowledged: [], unexplained: [] };
|
|
425
|
-
if (events.length === 0) return { line: "Wazuh · no alerts at level 10+", failed: false, count: 0, urgent: 0, unacknowledged: [], unexplained: [] };
|
|
426
|
+
if (!events) return { line: "Wazuh · the check failed", failed: true, count: 0, urgent: 0, unacknowledged: [], open: [], unexplained: [] };
|
|
427
|
+
if (events.length === 0) return { line: "Wazuh · no alerts at level 10+", failed: false, count: 0, urgent: 0, unacknowledged: [], open: [], unexplained: [] };
|
|
426
428
|
const groups = new Map<string, { label: string; agent: string; events: WazuhEvent[]; urgent: number; known: number }>();
|
|
427
429
|
let urgent = 0;
|
|
428
430
|
const unacknowledged: WazuhEvent[] = [];
|
|
@@ -451,7 +453,10 @@ export function wazuhDigest(events: readonly WazuhEvent[] | null, origins: Secur
|
|
|
451
453
|
const quiet = urgent - unacknowledged.length;
|
|
452
454
|
const urgentText = urgent === 0 ? "none urgent" : `${urgent} urgent${quiet > 0 ? ` (${quiet} acknowledged)` : ""}`;
|
|
453
455
|
const line = `Wazuh · ${events.length} alert${events.length === 1 ? "" : "s"} at level 10+, ${urgentText} · ${shown.join(" · ")}${more}`;
|
|
454
|
-
|
|
456
|
+
const restored = new Map<string, number>();
|
|
457
|
+
for (const e of events) if (e.rule === "100013") restored.set(e.agent, Math.max(restored.get(e.agent) ?? 0, Date.parse(e.timestamp)));
|
|
458
|
+
const open = unacknowledged.filter((e) => !(e.rule === "100012" && (restored.get(e.agent) ?? 0) > Date.parse(e.timestamp)));
|
|
459
|
+
return { line, failed: false, count: events.length, urgent, unacknowledged, open, unexplained };
|
|
455
460
|
}
|
|
456
461
|
|
|
457
462
|
// ---------------------------------------------------------------- vulnerabilities
|
|
@@ -717,6 +722,19 @@ export function imageVulnLine(facts: ImageVulnFacts | null, offers: ReadonlyMap<
|
|
|
717
722
|
return parts.join(" · ");
|
|
718
723
|
}
|
|
719
724
|
|
|
725
|
+
/** Our own images with critical CVEs that have a fix and no newer build in the registry: only our rebuild closes them. */
|
|
726
|
+
export function rebuildItem(facts: ImageVulnFacts | null): string | null {
|
|
727
|
+
if (!facts) return null;
|
|
728
|
+
const counts = new Map<string, number>();
|
|
729
|
+
for (const v of facts.critical) {
|
|
730
|
+
const build = facts.builds?.get(v.image) ?? facts.builds?.get(v.image.split("@")[0]);
|
|
731
|
+
if (isOwnImage(v.image) && !build?.newer) counts.set(v.image, (counts.get(v.image) ?? 0) + 1);
|
|
732
|
+
}
|
|
733
|
+
if (counts.size === 0) return null;
|
|
734
|
+
const images = [...counts.entries()].sort((x, y) => y[1] - x[1] || x[0].localeCompare(y[0])).map(([image, n]) => `${escapeDiscord(shortImageName(image))} (${n})`);
|
|
735
|
+
return `rebuild ${images.join(", ")}: our images carry critical CVEs that have a fixed version`;
|
|
736
|
+
}
|
|
737
|
+
|
|
720
738
|
// ---------------------------------------------------------------- reports
|
|
721
739
|
|
|
722
740
|
const GREEN = 0x57f287;
|
|
@@ -733,10 +751,17 @@ export function section(icon: string, line: string): string {
|
|
|
733
751
|
export interface ReportCard {
|
|
734
752
|
/** The state without the report's name, for the morning summary: `quiet day (24 h to 06:00 CEST)`. */
|
|
735
753
|
headline: string;
|
|
754
|
+
/** What the owners must act on, listed under Needs you and in the morning summary. */
|
|
755
|
+
needs: string[];
|
|
736
756
|
mention: boolean;
|
|
737
757
|
components: MessageComponent[];
|
|
738
758
|
}
|
|
739
759
|
|
|
760
|
+
/** The numbered Needs you list right under a report's title, or nothing. */
|
|
761
|
+
function needsBlock(items: readonly string[]): string[] {
|
|
762
|
+
return items.length === 0 ? [] : [`### Needs you\n${items.map((t, i) => `${i + 1}. ${t}`).join("\n")}`];
|
|
763
|
+
}
|
|
764
|
+
|
|
740
765
|
/** Text Displays in groups divided by separators. */
|
|
741
766
|
function card(groups: readonly (readonly string[])[], attention: boolean, mention: string | null): MessageComponent[] {
|
|
742
767
|
const components = groups.filter((g) => g.length > 0).flatMap((g, i) => [...(i > 0 ? [SEPARATOR] : []), ...g.map((content): MessageComponent => ({ type: 10, content }))]);
|
|
@@ -746,6 +771,7 @@ function card(groups: readonly (readonly string[])[], attention: boolean, mentio
|
|
|
746
771
|
export interface DailyData {
|
|
747
772
|
/** Local time the report covers up to, already formatted (`06:00 CEST`). */
|
|
748
773
|
until: string;
|
|
774
|
+
timeZone: string;
|
|
749
775
|
crowdsec: AlertSummary | null;
|
|
750
776
|
wazuh: WazuhDigest;
|
|
751
777
|
found: VulnEvent[] | null;
|
|
@@ -755,6 +781,8 @@ export interface DailyData {
|
|
|
755
781
|
offers: ReadonlyMap<string, ImageOffer>;
|
|
756
782
|
/** The Arcane Daily Report's channel, linked from offered updates. */
|
|
757
783
|
arcaneChannelId?: string;
|
|
784
|
+
/** Alerts posted to Discord, to tell an unacknowledged alert from one that was never posted. */
|
|
785
|
+
alerts: readonly Pick<PostedAlert, "key" | "channelId">[];
|
|
758
786
|
}
|
|
759
787
|
|
|
760
788
|
function headline(urgent: number, unexplained: number, health: number, failed: number): string {
|
|
@@ -776,9 +804,23 @@ export function dailyNeedsOwner(d: DailyData): boolean {
|
|
|
776
804
|
return (d.attention?.issues.length ?? 0) > 0 || failures(d) > 0;
|
|
777
805
|
}
|
|
778
806
|
|
|
807
|
+
/** What the owners must act on today: health issues, unexplained changes, open urgent alerts, our images to rebuild, failed checks. */
|
|
808
|
+
export function dailyNeeds(d: DailyData): string[] {
|
|
809
|
+
const items: string[] = [];
|
|
810
|
+
for (const i of d.attention?.issues ?? []) items.push(escapeDiscord(i.message.replace(/\.$/, "")));
|
|
811
|
+
if (d.wazuh.unexplained.length > 0) items.push(`${d.wazuh.unexplained.length} unexplained deployment change${d.wazuh.unexplained.length === 1 ? "" : "s"}; Investigate on the alert`);
|
|
812
|
+
items.push(...unacknowledgedItems(d.wazuh, d.alerts, d.timeZone));
|
|
813
|
+
const rebuild = rebuildItem(d.images);
|
|
814
|
+
if (rebuild) items.push(rebuild);
|
|
815
|
+
const failed = failures(d);
|
|
816
|
+
if (failed > 0) items.push(`${failed} check${failed === 1 ? "" : "s"} of this report failed; the bridge log on Cortex has the reason`);
|
|
817
|
+
return items;
|
|
818
|
+
}
|
|
819
|
+
|
|
779
820
|
export function dailyCard(d: DailyData, owners: readonly string[]): ReportCard {
|
|
780
821
|
const state = headline(d.wazuh.urgent, d.wazuh.unexplained.length, d.attention?.issues.length ?? 0, failures(d));
|
|
781
822
|
const mention = dailyNeedsOwner(d);
|
|
823
|
+
const needs = dailyNeeds(d);
|
|
782
824
|
const sections = [
|
|
783
825
|
section("🚫", crowdsecDailyLine(d.crowdsec)),
|
|
784
826
|
section("👁️", d.wazuh.line),
|
|
@@ -789,8 +831,9 @@ export function dailyCard(d: DailyData, owners: readonly string[]): ReportCard {
|
|
|
789
831
|
];
|
|
790
832
|
return {
|
|
791
833
|
headline: `${state} (24 h to ${d.until})`,
|
|
834
|
+
needs,
|
|
792
835
|
mention,
|
|
793
|
-
components: card([[`## 🛡️ ${DAILY_PREFIX}\n${state === "quiet day" ? "🟢" : "🟠"} ${state} · 24 h to ${d.until}`], sections], state !== "quiet day", mention ? mentionLine(owners) : null),
|
|
836
|
+
components: card([[`## 🛡️ ${DAILY_PREFIX}\n${state === "quiet day" ? "🟢" : "🟠"} ${state} · 24 h to ${d.until}`], needsBlock(needs), sections], state !== "quiet day" || needs.length > 0, mention ? mentionLine(owners) : null),
|
|
794
837
|
};
|
|
795
838
|
}
|
|
796
839
|
|
|
@@ -899,15 +942,15 @@ function crlText(crl: WeeklyData["crl"], timeZone: string): string {
|
|
|
899
942
|
return `RADIUS CRL: renew within ${crl.days} days (warned ${dayText(crl.warned, timeZone)})`;
|
|
900
943
|
}
|
|
901
944
|
|
|
902
|
-
/** One item per alert key the owners did not acknowledge: what changed, when, and where to acknowledge it, if anywhere. */
|
|
903
|
-
function unacknowledgedItems(
|
|
945
|
+
/** One item per open alert key the owners did not acknowledge: what changed, when, and where to acknowledge it, if anywhere. */
|
|
946
|
+
function unacknowledgedItems(wazuh: WazuhDigest, alerts: readonly Pick<PostedAlert, "key" | "channelId">[], timeZone: string): string[] {
|
|
904
947
|
const groups = new Map<string, WazuhEvent[]>();
|
|
905
|
-
for (const e of
|
|
948
|
+
for (const e of wazuh.open) if (e.rule !== DEPLOYMENT_RULE) groups.set(alertKey(e), [...(groups.get(alertKey(e)) ?? []), e]);
|
|
906
949
|
return [...groups.entries()].map(([key, events]) => {
|
|
907
950
|
const last = events.reduce((a, b) => (Date.parse(b.timestamp) > Date.parse(a.timestamp) ? b : a));
|
|
908
951
|
const what = last.path ? `\`${last.path.replace(/`/g, "'")}\` ${escapeDiscord(last.event ?? "changed")}` : escapeDiscord(issueLabel(last));
|
|
909
|
-
const when = events.length > 1 ? ` × ${events.length}, last ${clockText(last.timestamp,
|
|
910
|
-
const posted =
|
|
952
|
+
const when = events.length > 1 ? ` × ${events.length}, last ${clockText(last.timestamp, timeZone)}` : `, ${clockText(last.timestamp, timeZone)}`;
|
|
953
|
+
const posted = alerts.find((a) => a.key === key);
|
|
911
954
|
const fact = `${what} on ${escapeDiscord(last.agent)}${when}`;
|
|
912
955
|
return posted ? `urgent alert not acknowledged: ${fact}; Acknowledge it in <#${posted.channelId}>` : `urgent alert never posted, so it has no Acknowledge button: ${fact}; check that it was expected`;
|
|
913
956
|
});
|
|
@@ -917,12 +960,14 @@ export function needsYou(d: WeeklyData): string[] {
|
|
|
917
960
|
const items: string[] = [];
|
|
918
961
|
for (const i of d.attention?.issues ?? []) items.push(escapeDiscord(i.message.replace(/\.$/, "")));
|
|
919
962
|
if (d.wazuh.unexplained.length > 0) items.push(`${d.wazuh.unexplained.length} unexplained deployment change${d.wazuh.unexplained.length === 1 ? "" : "s"} this week; Investigate on the alert`);
|
|
920
|
-
items.push(...unacknowledgedItems(d));
|
|
963
|
+
items.push(...unacknowledgedItems(d.wazuh, d.alerts, d.timeZone));
|
|
921
964
|
if (d.patching && d.patching.rebootPending.length > 0) items.push(`reboot ${d.patching.rebootPending.map(escapeDiscord).join(", ")} to load installed updates`);
|
|
922
965
|
const stuck = d.openWithFix.filter((v) => d.now - Date.parse(v.since) > 3 * DAY);
|
|
923
966
|
if (stuck.length > 0) items.push(`${stuck.length} CVE${stuck.length === 1 ? "" : "s"} with a fixed version still open after 3 days (${[...new Set(stuck.map((v) => v.agent))].map(escapeDiscord).join(", ")}); unattended-upgrades may be stuck`);
|
|
924
967
|
const offered = offeredImages(d.images, d.offers);
|
|
925
968
|
if (offered.length > 0) items.push(`update ${offered.map(escapeDiscord).join(", ")} in the Arcane Daily Report: the newer image replaces one with a critical CVE`);
|
|
969
|
+
const rebuild = rebuildItem(d.images);
|
|
970
|
+
if (rebuild) items.push(rebuild);
|
|
926
971
|
if (d.crl !== null && d.crl !== "unknown") items.push(`renew the RADIUS CRL (wifi-device.sh renew-crl), ${d.crl.days} days left`);
|
|
927
972
|
if (d.backups) {
|
|
928
973
|
const stale = d.backups.guests.filter((g) => d.now / 1000 - g.last > STALE_BACKUP_S);
|
|
@@ -959,11 +1004,11 @@ export function weeklyCard(d: WeeklyData, owners: readonly string[]): ReportCard
|
|
|
959
1004
|
section("🩺", `${healthLine(d.attention)} · ${crlText(d.crl, d.timeZone)}`),
|
|
960
1005
|
section("💾", backupLine(d.backups, d.now, d.timeZone)),
|
|
961
1006
|
];
|
|
962
|
-
const needsBlock = items.length === 0 ? [] : [`### Needs you\n${items.map((t, i) => `${i + 1}. ${t}`).join("\n")}`];
|
|
963
1007
|
return {
|
|
964
1008
|
headline: `${d.range} · ${state} · ${needs}`,
|
|
1009
|
+
needs: items,
|
|
965
1010
|
mention: items.length > 0,
|
|
966
|
-
components: card([[`## 🛡️ ${WEEKLY_PREFIX} · ${d.range}\n${state} · ${needs}`], needsBlock, sections, [`-# ${lastDayLine(d.last24h)}`]], incidents > 0 || items.length > 0, items.length > 0 ? mentionLine(owners) : null),
|
|
1011
|
+
components: card([[`## 🛡️ ${WEEKLY_PREFIX} · ${d.range}\n${state} · ${needs}`], needsBlock(items), sections, [`-# ${lastDayLine(d.last24h)}`]], incidents > 0 || items.length > 0, items.length > 0 ? mentionLine(owners) : null),
|
|
967
1012
|
};
|
|
968
1013
|
}
|
|
969
1014
|
|
package/package.json
CHANGED
|
@@ -18,9 +18,23 @@ case "$name" in
|
|
|
18
18
|
case "$unit" in pomerium|nginx|lego-renew) ;; *) echo "bad unit" >&2; exit 2 ;; esac
|
|
19
19
|
since_ok "$since" || { echo "bad since" >&2; exit 2; }
|
|
20
20
|
journalctl -u "$unit" --since "$since" --no-pager -n 200 ;;
|
|
21
|
-
config-template) cat /etc/pomerium/config.yaml.template ;;
|
|
21
|
+
config-template) sudo cat /etc/pomerium/config.yaml.template ;;
|
|
22
22
|
render) sudo /usr/local/sbin/render-pomerium ;;
|
|
23
23
|
pomerium-restart) sudo systemctl restart pomerium && systemctl is-active pomerium ;;
|
|
24
|
+
pomerium-version) /usr/local/bin/pomerium --version ;;
|
|
25
|
+
pomerium-upgrade)
|
|
26
|
+
# stdin: the release tarball as base64; pomerium-upgrade checks it against the sha256 argument.
|
|
27
|
+
version="${rest%% *}"; sum="${rest#* }"
|
|
28
|
+
printf '%s' "$version" | grep -Eq '^v[0-9]+\.[0-9]+\.[0-9]+$' || { echo "bad version" >&2; exit 2; }
|
|
29
|
+
printf '%s' "$sum" | grep -Eq '^[0-9a-f]{64}$' || { echo "bad sha256" >&2; exit 2; }
|
|
30
|
+
stage="$(mktemp -d -p /var/tmp)"
|
|
31
|
+
base64 -d > "$stage/pomerium.tar.gz"
|
|
32
|
+
if sudo /usr/local/sbin/pomerium-upgrade "$version" "$sum" "$stage/pomerium.tar.gz"; then
|
|
33
|
+
rm -rf "$stage"
|
|
34
|
+
else
|
|
35
|
+
rm -rf "$stage"
|
|
36
|
+
exit 1
|
|
37
|
+
fi ;;
|
|
24
38
|
nginx-reload) sudo nginx -t && sudo systemctl reload nginx ;;
|
|
25
39
|
lego-renew) sudo systemctl start lego-renew.service && systemctl status lego-renew.service --no-pager --lines=10 ;;
|
|
26
40
|
deploy-config)
|
|
@@ -147,9 +147,9 @@ export function publishedSha256(checksums: string): string {
|
|
|
147
147
|
return sum;
|
|
148
148
|
}
|
|
149
149
|
|
|
150
|
-
/** `0.34.0+
|
|
150
|
+
/** `0.34.0+98fca09dc` (since Pomerium 0.34) or `pomerium version pomerium: 0.33.6+6d2d78cec` as `v0.34.0` or `v0.33.6`. */
|
|
151
151
|
export function installedRelease(output: string): string | null {
|
|
152
|
-
const m =
|
|
152
|
+
const m = /(?:^|pomerium:\s*)v?(\d+\.\d+\.\d+)/m.exec(output);
|
|
153
153
|
return m ? `v${m[1]}` : null;
|
|
154
154
|
}
|
|
155
155
|
|
|
@@ -101,7 +101,8 @@ describe("identity wrapper", () => {
|
|
|
101
101
|
expect(publishedSha256(`${"0".repeat(64)} pomerium-darwin-arm64.tar.gz\n${sum} pomerium-linux-amd64.tar.gz\n`)).toBe(sum);
|
|
102
102
|
expect(() => publishedSha256(`${"0".repeat(64)} pomerium-darwin-arm64.tar.gz\n`)).toThrow(/no sha256/);
|
|
103
103
|
expect(installedRelease("pomerium: 0.33.1+01af7466f\nenvoy: 20260618180819-16ede7a56f2f\n")).toBe("v0.33.1");
|
|
104
|
-
expect(installedRelease("0.
|
|
104
|
+
expect(installedRelease("pomerium version pomerium: 0.33.6+6d2d78cec\nenvoy: 20261026222654-30d955cf07bd\n")).toBe("v0.33.6");
|
|
105
|
+
expect(installedRelease("0.34.0+98fca09dc\nenvoy version 20261102191522-e7b75c3a606d (LicenseRef-Pomerium-Community-Edition-1.0)\nLicensed under the terms of the Pomerium Community Edition License 1.0: https://github.com/pomerium/pomerium\n")).toBe("v0.34.0");
|
|
105
106
|
expect(installedRelease("command not found")).toBeNull();
|
|
106
107
|
});
|
|
107
108
|
|