Skip to content

Infisical is the open-source platform for securing secrets, certificates, access, and AI Agents.

UI: add button to create new reports

adilson2e6d7ffd41c7
diff --git a/frontend/src/hooks/api/auditReports/index.ts b/frontend/src/hooks/api/auditReports/index.ts
index 6f957cd23f..41027003e3 100644
--- a/frontend/src/hooks/api/auditReports/index.ts
+++ b/frontend/src/hooks/api/auditReports/index.ts
@@ -1,11 +1,17 @@
-export { useDeleteAuditReport, useRequestAuditReport } from "./mutations";
-export { auditReportKeys, useGetAuditReports } from "./queries";
+export { useDeleteAuditReport, useRequestAuditReport, useRequestOrgAuditReport } from "./mutations";
+export { auditReportKeys, useGetAuditReports, useGetOrgAuditReports } from "./queries";
export {
AuditReportStatus,
AuditReportType,
+ OrgAuditReportType,
type TAuditReport,
type TAuditReportConfig,
type TAuditReportResultEntry,
type TGetAuditReportsDTO,
- type TRequestAuditReportDTO
+ type TGetOrgAuditReportsDTO,
+ type TOrgAuditReport,
+ type TOrgAuditReportConfig,
+ type TOrgAuditReportResultEntry,
+ type TRequestAuditReportDTO,
+ type TRequestOrgAuditReportDTO
} from "./types";
diff --git a/frontend/src/hooks/api/auditReports/mutations.tsx b/frontend/src/hooks/api/auditReports/mutations.tsx
index c54fd3fa5e..24c7429bbe 100644
--- a/frontend/src/hooks/api/auditReports/mutations.tsx
+++ b/frontend/src/hooks/api/auditReports/mutations.tsx
@@ -3,7 +3,13 @@ import { useMutation, useQueryClient } from "@tanstack/react-query";
import { apiRequest } from "@app/config/request";
import { auditReportKeys } from "./queries";
-import { TAuditReport, TDeleteAuditReportDTO, TRequestAuditReportDTO } from "./types";
+import {
+ TAuditReport,
+ TDeleteAuditReportDTO,
+ TOrgAuditReport,
+ TRequestAuditReportDTO,
+ TRequestOrgAuditReportDTO
+} from "./types";
export const useRequestAuditReport = () => {
const queryClient = useQueryClient();
@@ -19,6 +25,20 @@ export const useRequestAuditReport = () => {
});
};
+export const useRequestOrgAuditReport = () => {
+ const queryClient = useQueryClient();
+ return useMutation({
+ mutationFn: async (body: TRequestOrgAuditReportDTO) => {
+ const { data } = await apiRequest.post<TOrgAuditReport>(
+ "/api/v1/insights/secrets/reports",
+ body
+ );
+ return data;
+ },
+ onSuccess: () => queryClient.invalidateQueries({ queryKey: auditReportKeys.all() })
+ });
+};
+
export const useDeleteAuditReport = () => {
const queryClient = useQueryClient();
return useMutation({
diff --git a/frontend/src/hooks/api/auditReports/queries.tsx b/frontend/src/hooks/api/auditReports/queries.tsx
index 3ef639e6fc..badd558837 100644
--- a/frontend/src/hooks/api/auditReports/queries.tsx
+++ b/frontend/src/hooks/api/auditReports/queries.tsx
@@ -2,13 +2,22 @@ import { useQuery, UseQueryOptions } from "@tanstack/react-query";
import { apiRequest } from "@app/config/request";
-import { AuditReportStatus, TAuditReport, TGetAuditReportsDTO } from "./types";
+import {
+ AuditReportStatus,
+ TAuditReport,
+ TGetAuditReportsDTO,
+ TGetOrgAuditReportsDTO,
+ TOrgAuditReport
+} from "./types";
type TGetAuditReportsResponse = { reports: TAuditReport[]; totalCount: number };
+type TGetOrgAuditReportsResponse = { reports: TOrgAuditReport[]; totalCount: number };
export const auditReportKeys = {
all: () => ["audit-reports"] as const,
- list: (params: TGetAuditReportsDTO) => [...auditReportKeys.all(), "list", params] as const
+ list: (params: TGetAuditReportsDTO) => [...auditReportKeys.all(), "list", params] as const,
+ orgList: (params: TGetOrgAuditReportsDTO) =>
+ [...auditReportKeys.all(), "org-list", params] as const
};
// While any report is still generating, poll so the dashboard reflects status transitions in near real time.
@@ -48,3 +57,36 @@ export const useGetAuditReports = (
...options
});
};
+
+export const useGetOrgAuditReports = (
+ params: TGetOrgAuditReportsDTO,
+ options?: Omit<
+ UseQueryOptions<
+ TGetOrgAuditReportsResponse,
+ unknown,
+ TGetOrgAuditReportsResponse,
+ ReturnType<typeof auditReportKeys.orgList>
+ >,
+ "queryKey" | "queryFn"
+ >
+) => {
+ return useQuery({
+ queryKey: auditReportKeys.orgList(params),
+ queryFn: async () => {
+ const { data } = await apiRequest.get<TGetOrgAuditReportsResponse>(
+ "/api/v1/insights/secrets/reports",
+ {
+ params
+ }
+ );
+ return data;
+ },
+ refetchInterval: (query) => {
+ const hasInFlight = query.state.data?.reports.some((report) =>
+ IN_FLIGHT_STATUSES.includes(report.status)
+ );
+ return hasInFlight ? POLL_INTERVAL_MS : false;
+ },
+ ...options
+ });
+};
diff --git a/frontend/src/hooks/api/auditReports/types.ts b/frontend/src/hooks/api/auditReports/types.ts
index 64c3474214..2763273456 100644
--- a/frontend/src/hooks/api/auditReports/types.ts
+++ b/frontend/src/hooks/api/auditReports/types.ts
@@ -8,6 +8,14 @@ export enum AuditReportType {
SecretAccessLog = "SECRET_ACCESS_LOG"
}
+export enum OrgAuditReportType {
+ OrgUsageSummary = "ORG_USAGE_SUMMARY",
+ OrgNeedsAttention = "ORG_NEEDS_ATTENTION",
+ OrgAuthMethods = "ORG_AUTH_METHODS",
+ OrgStaticSecretUsage = "ORG_STATIC_SECRET_USAGE",
+ OrgSecretAccessVolume = "ORG_SECRET_ACCESS_VOLUME"
+}
+
export enum AuditReportStatus {
Pending = "pending",
Processing = "processing",
@@ -56,3 +64,37 @@ export type TDeleteAuditReportDTO = {
projectId: string;
auditReportId: string;
};
+
+export type TOrgAuditReportConfig = {
+ type: OrgAuditReportType;
+ inputs: Record<string, unknown>;
+};
+
+export type TOrgAuditReportResultEntry = {
+ type: OrgAuditReportType;
+ rowCount: number;
+ truncated: boolean;
+};
+
+export type TOrgAuditReport = {
+ id: string;
+ orgId: string;
+ requestedByUserId: string | null;
+ status: AuditReportStatus;
+ reportConfigs: TOrgAuditReportConfig[];
+ emailRecipients: string[];
+ resultSummary: TOrgAuditReportResultEntry[] | null;
+ errorMessage: string | null;
+ createdAt: string;
+ updatedAt: string;
+};
+
+export type TGetOrgAuditReportsDTO = {
+ offset?: number;
+ limit?: number;
+};
+
+export type TRequestOrgAuditReportDTO = {
+ reports: { type: OrgAuditReportType; inputs?: Record<string, unknown> }[];
+ emailRecipients?: string[];
+};
diff --git a/frontend/src/pages/organization/SecretInsightsPage/SecretInsightsPage.tsx b/frontend/src/pages/organization/SecretInsightsPage/SecretInsightsPage.tsx
index 264078206a..ca67120d56 100644
--- a/frontend/src/pages/organization/SecretInsightsPage/SecretInsightsPage.tsx
+++ b/frontend/src/pages/organization/SecretInsightsPage/SecretInsightsPage.tsx
@@ -1,13 +1,25 @@
import { Fragment, ReactNode } from "react";
import { Helmet } from "react-helmet";
-import { BoxIcon, KeyIcon, LayersIcon, RefreshCwIcon } from "lucide-react";
+import { format } from "date-fns";
+import { BoxIcon, FileTextIcon, KeyIcon, LayersIcon, PlusIcon, RefreshCwIcon } from "lucide-react";
+import { OrgPermissionCan } from "@app/components/permissions";
import { PageHeader } from "@app/components/v2";
-import { Skeleton } from "@app/components/v3";
+import {
+ Button,
+ Skeleton,
+ Tooltip,
+ TooltipContent,
+ TooltipProvider,
+ TooltipTrigger
+} from "@app/components/v3";
import { OrgPermissionSubjects, useOrganization } from "@app/context";
import { OrgPermissionSecretsManagementInsightsActions } from "@app/context/OrgPermissionContext/types";
import { withPermission } from "@app/hoc";
+import { usePopUp } from "@app/hooks";
import {
+ AuditReportStatus,
+ useGetOrgAuditReports,
useGetOrgAuthMethodDistribution,
useGetOrgSecretsAccessVolume,
useGetOrgSecretsCounts,
@@ -20,11 +32,15 @@ import { ProjectType } from "@app/hooks/api/projects/types";
import {
AuthMethodsCard,
NeedsAttentionCard,
+ RequestOrgAuditReportModal,
SecretAccessVolumeCard,
StaticSecretPresenceCard,
SummaryCard
} from "./components";
+const SENT_REPORT_STATUSES = [AuditReportStatus.Completed, AuditReportStatus.Partial];
+const IN_FLIGHT_REPORT_STATUSES = [AuditReportStatus.Pending, AuditReportStatus.Processing];
+
export const SecretInsightsPage = withPermission(
() => {
const { currentOrg } = useOrganization();
@@ -45,6 +61,17 @@ export const SecretInsightsPage = withPermission(
const { data: counts } = useGetOrgSecretsCounts(currentOrg.id);
+ const { popUp, handlePopUpOpen, handlePopUpToggle } = usePopUp(["requestOrgReport"] as const);
+ // Reports are generated asynchronously and delivered by email; the list is newest-first
+ // and polls while a report is in flight (the backend allows one in-flight report per org).
+ const { data: orgReports } = useGetOrgAuditReports({ offset: 0, limit: 10 });
+ const lastSentReport = orgReports?.reports.find((report) =>
+ SENT_REPORT_STATUSES.includes(report.status)
+ );
+ const hasInFlightReport = Boolean(
+ orgReports?.reports.some((report) => IN_FLIGHT_REPORT_STATUSES.includes(report.status))
+ );
+
// isSupported decides whether the audit-log-backed cards render at all
// (e.g. self-hosted instances without ClickHouse). While the auth methods query is
// pending we keep its grid slot so the row doesn't reflow when the card appears.
@@ -107,6 +134,45 @@ export const SecretInsightsPage = withPermission(
description="Organization-wide visibility into secret health, access patterns, and authentication hygiene."
>
{renderStatStrip("hidden justify-end dashboard:flex")}
+ <div className="flex items-center gap-3">
+ {lastSentReport && (
+ <span className="flex items-center gap-1.5 text-xs whitespace-nowrap text-mineshaft-300">
+ <FileTextIcon className="size-3.5" />
+ Last report sent {format(new Date(lastSentReport.createdAt), "MMM d, yyyy")}
+ </span>
+ )}
+ <OrgPermissionCan
+ I={OrgPermissionSecretsManagementInsightsActions.GenerateReport}
+ a={OrgPermissionSubjects.SecretsManagementInsights}
+ >
+ {(isAllowed) => {
+ const generateButton = (
+ <Button
+ variant="neutral"
+ size="xs"
+ isDisabled={!isAllowed || hasInFlightReport}
+ onClick={() => handlePopUpOpen("requestOrgReport")}
+ >
+ <PlusIcon />
+ Generate Report
+ </Button>
+ );
+ if (!hasInFlightReport) return generateButton;
+ return (
+ <TooltipProvider>
+ <Tooltip>
+ <TooltipTrigger asChild>
+ <span className="inline-flex">{generateButton}</span>
+ </TooltipTrigger>
+ <TooltipContent>
+ A report is already being generated. Please wait for it to finish.
+ </TooltipContent>
+ </Tooltip>
+ </TooltipProvider>
+ );
+ }}
+ </OrgPermissionCan>
+ </div>
</PageHeader>
{renderStatStrip("mb-6 flex justify-start dashboard:hidden")}
<div className="flex flex-col gap-4 pb-8">
@@ -143,6 +209,11 @@ export const SecretInsightsPage = withPermission(
</div>
</div>
</div>
+ <RequestOrgAuditReportModal
+ isOpen={popUp.requestOrgReport.isOpen}
+ onOpenChange={(isOpen) => handlePopUpToggle("requestOrgReport", isOpen)}
+ isAuditLogSupported={Boolean(accessVolume?.isSupported)}
+ />
</>
);
},
diff --git a/frontend/src/pages/organization/SecretInsightsPage/components/RequestOrgAuditReportModal.tsx b/frontend/src/pages/organization/SecretInsightsPage/components/RequestOrgAuditReportModal.tsx
new file mode 100644
index 0000000000..e071d9ab16
--- /dev/null
+++ b/frontend/src/pages/organization/SecretInsightsPage/components/RequestOrgAuditReportModal.tsx
@@ -0,0 +1,191 @@
+import { Controller, useForm } from "react-hook-form";
+import { zodResolver } from "@hookform/resolvers/zod";
+import { z } from "zod";
+
+import { createNotification } from "@app/components/notifications";
+import {
+ Button,
+ Checkbox,
+ Dialog,
+ DialogContent,
+ DialogDescription,
+ DialogFooter,
+ DialogHeader,
+ DialogTitle,
+ Field,
+ FieldContent,
+ FieldDescription,
+ FieldError,
+ FieldLabel,
+ TextArea
+} from "@app/components/v3";
+import { OrgAuditReportType, useRequestOrgAuditReport } from "@app/hooks/api/auditReports";
+
+import {
+ ORG_AUDIT_REPORT_TYPE_DESCRIPTIONS,
+ ORG_AUDIT_REPORT_TYPE_LABELS,
+ ORG_AUDIT_REPORT_TYPES_ORDERED,
+ ORG_AUDIT_REPORT_TYPES_REQUIRING_AUDIT_LOG
+} from "./orgAuditReportMeta";
+
+const parseEmails = (raw?: string): string[] =>
+ (raw ?? "")
+ .split(/[\s,]+/)
+ .map((email) => email.trim())
+ .filter(Boolean);
+
+const formSchema = z.object({
+ reportTypes: z.nativeEnum(OrgAuditReportType).array().min(1, "Select at least one report type"),
+ emailRecipients: z
+ .string()
+ .optional()
+ .refine(
+ (value) => parseEmails(value).every((email) => z.string().email().safeParse(email).success),
+ {
+ message: "Enter valid, comma-separated email addresses"
+ }
+ )
+});
+
+type TFormSchema = z.infer<typeof formSchema>;
+
+type Props = {
+ isOpen: boolean;
+ onOpenChange: (isOpen: boolean) => void;
+ isAuditLogSupported: boolean;
+};
+
+export const RequestOrgAuditReportModal = ({
+ isOpen,
+ onOpenChange,
+ isAuditLogSupported
+}: Props) => {
+ const requestOrgAuditReport = useRequestOrgAuditReport();
+
+ const availableReportTypes = ORG_AUDIT_REPORT_TYPES_ORDERED.filter(
+ (type) => isAuditLogSupported || !ORG_AUDIT_REPORT_TYPES_REQUIRING_AUDIT_LOG.includes(type)
+ );
+
+ const {
+ control,
+ handleSubmit,
+ reset,
+ formState: { isSubmitting }
+ } = useForm<TFormSchema>({
+ resolver: zodResolver(formSchema),
+ defaultValues: { reportTypes: [], emailRecipients: "" }
+ });
+
+ const handleClose = (open: boolean) => {
+ onOpenChange(open);
+ if (!open) reset();
+ };
+
+ const onSubmit = async (data: TFormSchema) => {
+ const recipients = parseEmails(data.emailRecipients);
+ await requestOrgAuditReport.mutateAsync({
+ reports: data.reportTypes.map((type) => ({ type })),
+ emailRecipients: recipients.length ? recipients : undefined
+ });
+ createNotification({
+ type: "success",
+ text: "Report requested. Recipients will receive an email once it's ready."
+ });
+ reset();
+ onOpenChange(false);
+ };
+
+ return (
+ <Dialog open={isOpen} onOpenChange={handleClose}>
+ <DialogContent className="max-w-2xl">
+ <DialogHeader>
+ <DialogTitle>Generate Report</DialogTitle>
+ <DialogDescription>
+ Select the reports to generate. They will be emailed as CSV attachments once ready.
+ </DialogDescription>
+ </DialogHeader>
+ <form onSubmit={handleSubmit(onSubmit)} className="space-y-4">
+ <Controller
+ control={control}
+ name="reportTypes"
+ render={({ field, fieldState: { error } }) => {
+ const allSelected = field.value.length === availableReportTypes.length;
+ return (
+ <Field>
+ <div className="flex items-center justify-between">
+ <FieldLabel>Reports</FieldLabel>
+ <button
+ type="button"
+ className="cursor-pointer text-xs font-medium text-muted transition-colors hover:text-mineshaft-300"
+ onClick={() => field.onChange(allSelected ? [] : [...availableReportTypes])}
+ >
+ {allSelected ? "Deselect All" : "Select All"}
+ </button>
+ </div>
+ <FieldContent>
+ <div className="flex flex-col gap-3">
+ {availableReportTypes.map((type) => {
+ const checkboxId = `org-audit-report-type-${type}`;
+ return (
+ <div key={type} className="flex items-start gap-3">
+ <Checkbox
+ id={checkboxId}
+ variant="org"
+ className="mt-0.5"
+ isChecked={field.value.includes(type)}
+ onCheckedChange={(isChecked) => {
+ if (isChecked) field.onChange([...field.value, type]);
+ else field.onChange(field.value.filter((value) => value !== type));
+ }}
+ />
+ <label htmlFor={checkboxId} className="cursor-pointer leading-tight">
+ <span className="block text-sm text-foreground">
+ {ORG_AUDIT_REPORT_TYPE_LABELS[type]}
+ </span>
+ <span className="block text-xs text-muted">
+ {ORG_AUDIT_REPORT_TYPE_DESCRIPTIONS[type]}
+ </span>
+ </label>
+ </div>
+ );
+ })}
+ </div>
+ <FieldError errors={[error]} />
+ </FieldContent>
+ </Field>
+ );
+ }}
+ />
+ <Controller
+ control={control}
+ name="emailRecipients"
+ render={({ field, fieldState: { error } }) => (
+ <Field>
+ <FieldLabel>Email recipients</FieldLabel>
+ <FieldContent>
+ <TextArea
+ {...field}
+ isError={Boolean(error)}
+ />
+ <FieldDescription>
+ Comma-separated emails. Defaults to your own email when left blank.
+ </FieldDescription>
+ <FieldError errors={[error]} />
+ </FieldContent>
+ </Field>
+ )}
+ />
+ <DialogFooter className="gap-2 sm:gap-2">
+ <Button type="button" variant="ghost" onClick={() => handleClose(false)}>
+ Cancel
+ </Button>
+ <Button type="submit" variant="org" isPending={isSubmitting} isDisabled={isSubmitting}>
+ Generate Report
+ </Button>
+ </DialogFooter>
+ </form>
+ </DialogContent>
+ </Dialog>
+ );
+};
diff --git a/frontend/src/pages/organization/SecretInsightsPage/components/index.ts b/frontend/src/pages/organization/SecretInsightsPage/components/index.ts
index 51cdae0140..bc2524dc1c 100644
--- a/frontend/src/pages/organization/SecretInsightsPage/components/index.ts
+++ b/frontend/src/pages/organization/SecretInsightsPage/components/index.ts
@@ -1,5 +1,6 @@
export { AuthMethodsCard } from "./AuthMethodsCard";
export { NeedsAttentionCard } from "./NeedsAttentionCard";
+export { RequestOrgAuditReportModal } from "./RequestOrgAuditReportModal";
export { SecretAccessVolumeCard } from "./SecretAccessVolumeCard";
export { StaticSecretPresenceCard } from "./StaticSecretPresenceCard";
export { SummaryCard } from "./SummaryCard";
diff --git a/frontend/src/pages/organization/SecretInsightsPage/components/orgAuditReportMeta.ts b/frontend/src/pages/organization/SecretInsightsPage/components/orgAuditReportMeta.ts
new file mode 100644
index 0000000000..a309180a70
--- /dev/null
+++ b/frontend/src/pages/organization/SecretInsightsPage/components/orgAuditReportMeta.ts
@@ -0,0 +1,36 @@
+import { OrgAuditReportType } from "@app/hooks/api/auditReports";
+
+export const ORG_AUDIT_REPORT_TYPE_LABELS: Record<OrgAuditReportType, string> = {
+ [OrgAuditReportType.OrgUsageSummary]: "Usage Summary",
+ [OrgAuditReportType.OrgNeedsAttention]: "Needs Attention",
+ [OrgAuditReportType.OrgAuthMethods]: "Auth Methods (Past 7 Days)",
+ [OrgAuditReportType.OrgStaticSecretUsage]: "Static Secret Usage (Past 12 Weeks)",
+ [OrgAuditReportType.OrgSecretAccessVolume]: "Secret Access Volume (Past 7 Days)"
+};
+
+export const ORG_AUDIT_REPORT_TYPE_DESCRIPTIONS: Record<OrgAuditReportType, string> = {
+ [OrgAuditReportType.OrgUsageSummary]:
+ "Organization-wide counts of active leases, users, and machine identities.",
+ [OrgAuditReportType.OrgNeedsAttention]:
+ "Projects ranked by severity: duplicated secrets, stale secrets, failed rotations and syncs, orphaned leases.",
+ [OrgAuditReportType.OrgAuthMethods]:
+ "How often each machine identity authentication method accessed a secret value over the past week.",
+ [OrgAuditReportType.OrgStaticSecretUsage]:
+ "Static secrets created per week over the last twelve weeks.",
+ [OrgAuditReportType.OrgSecretAccessVolume]: "Secret access events per day over the past week."
+};
+
+export const ORG_AUDIT_REPORT_TYPES_ORDERED: OrgAuditReportType[] = [
+ OrgAuditReportType.OrgUsageSummary,
+ OrgAuditReportType.OrgNeedsAttention,
+ OrgAuditReportType.OrgAuthMethods,
+ OrgAuditReportType.OrgStaticSecretUsage,
+ OrgAuditReportType.OrgSecretAccessVolume
+];
+
+// These reports read from the audit log analytics store (ClickHouse); hide them when the
+// instance doesn't support it, since the backend rejects requests for them up front.
+export const ORG_AUDIT_REPORT_TYPES_REQUIRING_AUDIT_LOG: OrgAuditReportType[] = [
+ OrgAuditReportType.OrgAuthMethods,
+ OrgAuditReportType.OrgSecretAccessVolume
+];