@@ -235,14 +338,14 @@ function FindingsSection({
{shown.length === 0 ? (
0 ? () => (setTier(""), setFixKind("")) : undefined}
+ title={pool.length === 0 ? (view === "open" ? "Nothing to fix" : "Nothing fixed or removed in 30 days") : "No findings match"}
+ onClear={pool.length > 0 ? () => (setTier(""), setFixKind("")) : undefined}
testId="infra-empty"
>
- {open.length === 0 ? "Nothing your accounts run is behind a fix you have to make. AWS-managed rows are below." : undefined}
+ {pool.length === 0 && view === "open" ? "Nothing your accounts run is behind a fix you have to make. AWS-managed rows are below." : undefined}
) : (
-
+
{shown.map((f) => (
))}
@@ -271,6 +374,25 @@ function FindingRow({ f, admin, dryRun, defaultOpen }: { f: InfraFinding; admin:
const [asked, setAsked] = useState(null);
const status = INFRA_STATUS_LOOK[f.status] ?? INFRA_STATUS_LOOK.open;
const aws = f.fix.kind === "aws";
+ const done = isClosed(f);
+ const [approving, setApproving] = useState(null);
+ const approve = async (when: ApplyWhen) => {
+ setApproving(when);
+ try {
+ const r = await infraApi.apply(f.id, when);
+ const words =
+ r.status === "queued"
+ ? when === "immediate"
+ ? "Approved: Coderhelm applies it in AWS now (non-production first) and reads it back."
+ : "Approved: Coderhelm applies it in the next maintenance window (non-production first) and reads it back."
+ : (r.reason ?? "Nothing to apply.");
+ setAsked(words);
+ toast(words);
+ } catch (e) {
+ toast(e instanceof Error && /\b403\b/.test(e.message) ? "Only admins can approve updates in AWS." : "Could not approve it. Try again.", "error");
+ }
+ setApproving(null);
+ };
const askFix = async () => {
setAsking(true);
try {
@@ -288,7 +410,9 @@ function FindingRow({ f, admin, dryRun, defaultOpen }: { f: InfraFinding; admin:
const prWords = f.pr ? (f.pr.state === "merged" ? "merged, waiting for the new version to run" : closed ? closedWords(f.pr) : f.pr.state) : null;
// A pull request closed without merging is history, not a fix on its way: the fix is offered again.
// (A finding the replacement check moved to its runbook is no longer a "pr" fix, so it gets no button.)
- const canAsk = admin && f.fix.kind === "pr" && f.status === "open" && (!f.pr || closed) && !asked;
+ const canAsk = !done && admin && f.fix.kind === "pr" && f.status === "open" && (!f.pr || closed) && !asked;
+ const applied = !!f.apply?.applied_at;
+ const canApprove = !done && admin && f.fix.kind === "apply" && f.status === "open" && !applied && !f.apply?.approved_at && !asked;
return (
+
+ {status.label}
+
+
+ ) : (
<>
{f.pr && (
@@ -321,13 +452,42 @@ function FindingRow({ f, admin, dryRun, defaultOpen }: { f: InfraFinding; admin:
)}
{!aws && !f.pr && f.status !== "open" && {status.label}}
+ {f.fix.kind === "apply" && f.apply?.approved_at && (
+
+ {applied ? "Sent to AWS" : "Approved"}
+
+ )}
>
+ )
}
actions={
canAsk ? (
+ ) : canApprove ? (
+
+
+
+
) : null
}
details={}
@@ -340,6 +500,11 @@ function FindingRow({ f, admin, dryRun, defaultOpen }: { f: InfraFinding; admin:
)}
{asked &&
{asked}
}
+ {!done && f.apply?.note && (
+
+ {f.apply.note}
+
+ )}
);
}
@@ -368,7 +533,7 @@ function Sources({ feeds, readAt }: { feeds: InfraFeed[] | null; readAt: string
testId="infra-source"
status={{ tone: readAt ? "success" : "muted" }}
title="Your AWS accounts"
- meta={[readAt ? "Read once a day, read-only" : "Not read yet"]}
+ meta={[readAt ? "Read once a day, and again when this page opens after a few minutes; read-only" : "Not read yet"]}
time={readAt}
/>
diff --git a/dashboard/src/app/security/infrastructure/parts.tsx b/dashboard/src/app/security/infrastructure/parts.tsx
index 10093ae7..ef93d60b 100644
--- a/dashboard/src/app/security/infrastructure/parts.tsx
+++ b/dashboard/src/app/security/infrastructure/parts.tsx
@@ -15,6 +15,7 @@ import { linkButton } from "@/components/ui";
import {
CONFIDENCE_LOOK,
FIX_LOOK,
+ isClosed,
howWords,
locationHref,
locationWords,
@@ -109,7 +110,7 @@ export function dayWords(day: string): string {
export function showFromTo(f: InfraFinding): boolean {
const to = f.fix.to?.trim() ?? "";
if (!to) return false;
- if (f.fix.kind === "runbook" && f.sources.some((s) => s.kind === "maintenance" && s.id.split(":").includes(to))) return false;
+ if ((f.fix.kind === "runbook" || f.fix.kind === "apply") && f.sources.some((s) => s.kind === "maintenance" && s.id.split(":").includes(to))) return false;
return to !== f.fix.summary && !/^(system-update|db-upgrade|os-patch|service-update|service-software)$/.test(to);
}
@@ -374,13 +375,63 @@ export function PrNotesBlocks({ n }: { n: InfraPrNotes }) {
);
}
+/** What Coderhelm applies after an approval, and what AWS answered. */
+function ApplyBlock({ f }: { f: InfraFinding }) {
+ const plan = f.fix.apply;
+ if (!plan) return null;
+ const a = f.apply;
+ return (
+
+
+ {plan.action} through AWS's apply-pending-maintenance-action, on {plan.arns.length} resource{plan.arns.length === 1 ? "" : "s"}, in the next
+ maintenance window unless you pick now. {plan.effect}
+
+ {a?.approved_at && (
+
+ Approved by {a.approved_by || "an admin"}
+ {a.opt_in === "immediate" ? ", to apply now" : ", for the next maintenance window"}.
+ {a.applied_at ? (
+ <>
+ {" "}
+ AWS accepted it .
+ >
+ ) : null}
+
+ )}
+ {a?.missing_permission && (
+
+ The role in this account lacks {a.missing_permission}. Turn ApplyMaintenance on in the role's update stack, or follow the runbook below.
+
+ )}
+
+ );
+}
+
/** What opens under a finding's row. */
export function FindingDetails({ f }: { f: InfraFinding }) {
const fix = f.fix;
- const rb = fix.kind === "runbook" ? (fix.runbook ?? null) : null;
- const order = fix.order ?? [];
+ const done = isClosed(f);
+ // A runbook is shown for a runbook fix, and behind an apply only when the
+ // role may not apply it. A closed finding shows no steps at all.
+ const rb = !done && (fix.kind === "runbook" || (fix.kind === "apply" && !!f.apply?.missing_permission)) ? (fix.runbook ?? null) : null;
+ const order = done ? [] : (fix.order ?? []);
return (
<>
+ {done && (
+
+
+ {f.status === "removed" ? (
+ <>
+ A full read of the account no longer lists this resource. Nothing to do.
+ >
+ ) : (
+ <>
+ The read of the account shows the fix running. Nothing to do.
+ >
+ )}
+
+
+ )}
{fix.kind === "aws" ? (
{fix.reason || "AWS patches this service itself."}
Apply by {dayWords(fix.apply_by)}. AWS applies it itself after that, in the maintenance window.
@@ -494,7 +546,8 @@ export function FindingDetails({ f }: { f: InfraFinding }) {
- First seen . It closes when Coderhelm reads the account again and sees the fix running.
+ First seen .
+ {done ? "" : " It closes when Coderhelm reads the account again and sees the fix running, or the resource gone."}
>
diff --git a/dashboard/src/lib/infra-security.ts b/dashboard/src/lib/infra-security.ts
index 677f6e33..fbf93e5c 100644
--- a/dashboard/src/lib/infra-security.ts
+++ b/dashboard/src/lib/infra-security.ts
@@ -22,8 +22,35 @@ export type InfraKind =
| "opensearch_domain"
| "container_image";
-export type FixKind = "pr" | "runbook" | "aws";
-export type InfraStatus = "open" | "fixing" | "pr_open" | "fixed" | "aws_managed" | "dismissed";
+export type FixKind = "pr" | "apply" | "runbook" | "aws";
+export type InfraStatus = "open" | "fixing" | "pr_open" | "fixed" | "aws_managed" | "dismissed" | "removed" | "merged";
+
+/** When to apply a pending action in AWS. */
+export type ApplyWhen = "next-maintenance" | "immediate";
+
+/** How Coderhelm applies a pending action once a person approves it. */
+export interface InfraApplyPlan {
+ /** AWS's name for the action: os-upgrade, system-update, db-upgrade, ... */
+ action: string;
+ arns: string[];
+ /** The IAM action the role needs. */
+ permission: string;
+ default_opt_in: ApplyWhen;
+ /** What applying it does to the database, in a line. */
+ effect: string;
+}
+
+/** A person's approval, and what AWS answered. */
+export interface InfraApplyState {
+ opt_in: ApplyWhen;
+ approved_by: string;
+ approved_at: string;
+ applied_at?: string;
+ applied?: string[];
+ note?: string;
+ /** The IAM action the role lacks, when AWS refused for that. */
+ missing_permission?: string;
+}
export type InfraConfidence = "high" | "medium" | "low";
@@ -142,6 +169,8 @@ export interface InfraFix {
after?: string[];
/** Why no CVE is named, or that an advisory is only related. */
advisory_note?: string;
+ /** What Coderhelm applies after one approval (kind "apply"). */
+ apply?: InfraApplyPlan | null;
}
export interface InfraFinding {
@@ -176,6 +205,12 @@ export interface InfraFinding {
first_seen_at: string;
updated_at: string;
fixed_at?: string | null;
+ /** When a full read of the account stopped listing the resource. */
+ removed_at?: string | null;
+ /** A person's approval of the action Coderhelm applies, and AWS's answer. */
+ apply?: InfraApplyState | null;
+ /** False once the finding is closed: nothing to open, follow or approve. */
+ actionable?: boolean;
environment?: string;
/** The lines of a fix run's change that would have replaced or destroyed a data resource. */
refused?: string[];
@@ -199,15 +234,43 @@ export interface InfraAccount {
missing: string[];
update_url: string | null;
read: { read_at: string; resources: number; errors: InfraReadError[] } | null;
+ /** Whether the role may apply approved maintenance (null until checked). */
+ apply_maintenance?: boolean | null;
}
export interface InfraOverview {
enabled: boolean;
dry_run: boolean;
- counts: { open: number; p0: number; p1: number; p2: number; p3: number; prs: number; runbooks: number; aws_managed: number; fixed_30d: number };
+ counts: {
+ open: number;
+ p0: number;
+ p1: number;
+ p2: number;
+ p3: number;
+ prs: number;
+ runbooks: number;
+ aws_managed: number;
+ fixed_30d: number;
+ removed_30d?: number;
+ applies?: number;
+ };
accounts: InfraAccount[];
findings: InfraFinding[];
read_at: string | null;
+ /** The oldest of the accounts' latest reads: how old the list can be. */
+ oldest_read_at: string | null;
+ /** Opening the page started a fresh read of the accounts. */
+ refreshing: boolean;
+}
+
+/** Fixed or removed: closed by a read of the account. */
+export function isClosed(f: Pick): boolean {
+ return f.status === "fixed" || f.status === "removed";
+}
+
+/** A step in AWS: a runbook, or an action Coderhelm applies after approval. */
+export function inAws(f: Pick): boolean {
+ return f.fix.kind === "runbook" || f.fix.kind === "apply";
}
export interface InfraPending {
@@ -304,8 +367,10 @@ export function checkInfraOverview(r: unknown): InfraOverview {
enabled: o.enabled !== false,
dry_run: o.dry_run === true,
accounts: Array.isArray(o.accounts) ? (o.accounts as InfraAccount[]) : [],
- findings,
+ findings: findings.filter((f) => f.status !== "merged"),
read_at: typeof o.read_at === "string" ? o.read_at : null,
+ oldest_read_at: typeof o.oldest_read_at === "string" ? o.oldest_read_at : typeof o.read_at === "string" ? o.read_at : null,
+ refreshing: o.refreshing === true,
};
}
@@ -355,6 +420,12 @@ export const infraApi = {
check: () => request<{ status: string }>("/api/security/infrastructure/check", json("POST")),
fix: (id: string) =>
request<{ status: "started" | "queued" | "skipped"; reason: string | null }>(`/api/security/infrastructure/findings/${encodeURIComponent(id)}/fix`, json("POST")),
+ /** Approve a pending action Coderhelm applies in AWS. */
+ apply: (id: string, when: ApplyWhen) =>
+ request<{ status: "queued" | "skipped"; reason?: string | null; when?: ApplyWhen }>(
+ `/api/security/infrastructure/findings/${encodeURIComponent(id)}/apply`,
+ json("POST", { when }),
+ ),
};
// ── Words ───────────────────────────────────────────────────────────────
@@ -392,6 +463,7 @@ export function countWords(kind: InfraKind, n: number): string {
export const FIX_LOOK: Record = {
pr: { label: "Fix PR", tone: "info", hover: "A pull request in the code that defines it." },
+ apply: { label: "Applied by Coderhelm", tone: "info", hover: "A step in AWS with no code change. Coderhelm applies it after one approval, non-production first, and checks the result." },
runbook: { label: "Runbook", tone: "attention", hover: "A step to apply in AWS. Coderhelm shows it; it never runs it." },
aws: { label: "AWS-managed", tone: "muted", hover: "AWS patches it. Nothing to do." },
};
@@ -403,6 +475,8 @@ export const INFRA_STATUS_LOOK: Record