Skip to content

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

feat(insights): Unused Access card grouped by principal with a sheet of their unread secrets

Dimitris Staratzis89c5f25259df
diff --git a/frontend/src/hooks/api/auditLogs/constants.tsx b/frontend/src/hooks/api/auditLogs/constants.tsx
index db0d0506dc..808efec75b 100644
--- a/frontend/src/hooks/api/auditLogs/constants.tsx
+++ b/frontend/src/hooks/api/auditLogs/constants.tsx
@@ -303,8 +303,8 @@ export const eventToNameMap: { [K in EventType]: string } = {
"View Secrets Management Calendar Insights",
[EventType.VIEW_INSIGHTS_SECRETS_MANAGEMENT_ACCESS_VOLUME]:
"View Secrets Management Access Volume Insights",
- [EventType.VIEW_INSIGHTS_SECRETS_MANAGEMENT_SECRET_EXPOSURE]:
- "View Secrets Management Secret Exposure Insights",
+ [EventType.VIEW_INSIGHTS_SECRETS_MANAGEMENT_UNUSED_ACCESS]:
+ "View Secrets Management Unused Access Insights",
[EventType.VIEW_INSIGHTS_SECRETS_MANAGEMENT_ORG_AUTH_METHOD_DISTRIBUTION]:
"View Organization Secrets Management Auth Method Distribution Insights",
[EventType.VIEW_INSIGHTS_SECRETS_MANAGEMENT_ACCESS_LOCATIONS]:
diff --git a/frontend/src/hooks/api/auditLogs/enums.tsx b/frontend/src/hooks/api/auditLogs/enums.tsx
index c50f9c3040..3e4aa4aec7 100644
--- a/frontend/src/hooks/api/auditLogs/enums.tsx
+++ b/frontend/src/hooks/api/auditLogs/enums.tsx
@@ -296,7 +296,7 @@ export enum EventType {
VIEW_INSIGHTS_SECRETS_MANAGEMENT_CALENDAR = "view-insights-secrets-management-calendar",
VIEW_INSIGHTS_SECRETS_MANAGEMENT_ACCESS_VOLUME = "view-insights-secrets-management-access-volume",
- VIEW_INSIGHTS_SECRETS_MANAGEMENT_SECRET_EXPOSURE = "view-insights-secrets-management-secret-exposure",
+ VIEW_INSIGHTS_SECRETS_MANAGEMENT_UNUSED_ACCESS = "view-insights-secrets-management-unused-access",
VIEW_INSIGHTS_SECRETS_MANAGEMENT_ORG_AUTH_METHOD_DISTRIBUTION = "view-insights-secrets-management-org-auth-method-distribution",
VIEW_INSIGHTS_SECRETS_MANAGEMENT_ACCESS_LOCATIONS = "view-insights-secrets-management-access-locations",
VIEW_INSIGHTS_SECRETS_MANAGEMENT_SUMMARY = "view-insights-secrets-management-summary",
diff --git a/frontend/src/hooks/api/secretInsights/index.ts b/frontend/src/hooks/api/secretInsights/index.ts
index fd2c92a691..055c0b837d 100644
--- a/frontend/src/hooks/api/secretInsights/index.ts
+++ b/frontend/src/hooks/api/secretInsights/index.ts
@@ -14,8 +14,9 @@ export {
// useGetSecretAccessLocations,
useGetSecretAccessVolume,
useGetSecretBlindIndexStatus,
- useGetSecretExposure,
- useGetSecretsDuplication
+ useGetSecretsDuplication,
+ useGetUnusedAccess,
+ useGetUnusedAccessPrincipal
} from "./queries";
export type {
TAccessLocation,
@@ -24,7 +25,6 @@ export type {
TCalendarRotation,
TDuplicatedSecretEntry,
TDuplicatedSecretGroup,
- TExposedSecret,
TGetAuthMethodDistributionDTO,
TGetAuthMethodDistributionResponse,
TGetCalendarInsightsDTO,
@@ -36,10 +36,12 @@ export type {
TGetSecretAccessLocationsResponse,
TGetSecretAccessVolumeDTO,
TGetSecretAccessVolumeResponse,
- TGetSecretExposureDTO,
- TGetSecretExposureResponse,
TGetSecretsDuplicationDTO,
TGetSecretsDuplicationResponse,
+ TGetUnusedAccessDTO,
+ TGetUnusedAccessPrincipalDTO,
+ TGetUnusedAccessPrincipalResponse,
+ TGetUnusedAccessResponse,
TOrgAuthMethodUsage,
TOrgDuplicatedSecretEntry,
TOrgDuplicatedSecretGroup,
@@ -54,6 +56,8 @@ export type {
TSecretAccessVolumeDay,
TSecretExposure,
TSecretExposureCounts,
- TSecretValueMatch
+ TSecretValueMatch,
+ TUnusedAccessPrincipal,
+ TUnusedSecret
} from "./types";
-export { SecretExposureBand, SecretExposureDriver, SecretExposureOrderBy } from "./types";
+export { SecretExposureBand, SecretExposureDriver, UnusedAccessPrincipalType } from "./types";
diff --git a/frontend/src/hooks/api/secretInsights/queries.tsx b/frontend/src/hooks/api/secretInsights/queries.tsx
index 682eb2722a..14fa9cfe0c 100644
--- a/frontend/src/hooks/api/secretInsights/queries.tsx
+++ b/frontend/src/hooks/api/secretInsights/queries.tsx
@@ -20,10 +20,12 @@ import {
TGetSecretAccessVolumeResponse,
TGetSecretBlindIndexStatusDTO,
TGetSecretBlindIndexStatusResponse,
- TGetSecretExposureDTO,
- TGetSecretExposureResponse,
TGetSecretsDuplicationDTO,
TGetSecretsDuplicationResponse,
+ TGetUnusedAccessDTO,
+ TGetUnusedAccessPrincipalDTO,
+ TGetUnusedAccessPrincipalResponse,
+ TGetUnusedAccessResponse,
TOrgAuthMethodUsage,
TOrgProjectsInsights,
TOrgSecretAccessVolume,
@@ -37,8 +39,10 @@ export const secretInsightsKeys = {
[...secretInsightsKeys.all(), "calendar-events", params] as const,
accessVolume: (params: TGetSecretAccessVolumeDTO) =>
[...secretInsightsKeys.all(), "access-volume", params] as const,
- secretExposure: (params: TGetSecretExposureDTO) =>
- [...secretInsightsKeys.all(), "secret-exposure", params] as const,
+ unusedAccess: (params: TGetUnusedAccessDTO) =>
+ [...secretInsightsKeys.all(), "unused-access", params] as const,
+ unusedAccessPrincipal: (params: TGetUnusedAccessPrincipalDTO) =>
+ [...secretInsightsKeys.all(), "unused-access-principal", params] as const,
// accessLocations: (params: TGetSecretAccessLocationsDTO) =>
// [...secretInsightsKeys.all(), "access-locations", params] as const,
authMethodDistribution: (params: TGetAuthMethodDistributionDTO) =>
@@ -127,24 +131,24 @@ export const useGetSecretAccessVolume = (
});
};
-export const useGetSecretExposure = (
- params: TGetSecretExposureDTO,
+export const useGetUnusedAccess = (
+ params: TGetUnusedAccessDTO,
options?: Omit<
UseQueryOptions<
- TGetSecretExposureResponse,
+ TGetUnusedAccessResponse,
unknown,
- TGetSecretExposureResponse,
- ReturnType<typeof secretInsightsKeys.secretExposure>
+ TGetUnusedAccessResponse,
+ ReturnType<typeof secretInsightsKeys.unusedAccess>
>,
"queryKey" | "queryFn"
>
) => {
return useQuery({
- queryKey: secretInsightsKeys.secretExposure(params),
+ queryKey: secretInsightsKeys.unusedAccess(params),
queryFn: async () => {
const { projectId, ...query } = params;
- const res = await apiRequest.get<Omit<TGetSecretExposureResponse, "remainingTtl">>(
- `/api/v1/insights/${projectId}/secrets/exposure`,
+ const res = await apiRequest.get<Omit<TGetUnusedAccessResponse, "remainingTtl">>(
+ `/api/v1/insights/${projectId}/secrets/unused-access`,
{ params: query }
);
const remainingTtl = Number(res.headers["x-cache-ttl"] ?? -1);
@@ -157,6 +161,32 @@ export const useGetSecretExposure = (
});
};
+export const useGetUnusedAccessPrincipal = (
+ params: TGetUnusedAccessPrincipalDTO,
+ options?: Omit<
+ UseQueryOptions<
+ TGetUnusedAccessPrincipalResponse,
+ unknown,
+ TGetUnusedAccessPrincipalResponse,
+ ReturnType<typeof secretInsightsKeys.unusedAccessPrincipal>
+ >,
+ "queryKey" | "queryFn"
+ >
+) => {
+ return useQuery({
+ queryKey: secretInsightsKeys.unusedAccessPrincipal(params),
+ queryFn: async () => {
+ const res = await apiRequest.get<Omit<TGetUnusedAccessPrincipalResponse, "remainingTtl">>(
+ `/api/v1/insights/${params.projectId}/secrets/unused-access/${params.principalType}/${params.principalId}`
+ );
+ const remainingTtl = Number(res.headers["x-cache-ttl"] ?? -1);
+ return { ...res.data, remainingTtl };
+ },
+ staleTime: (query) => cachedInsightsRefreshMs(query.state.data),
+ ...options
+ });
+};
+
export const useGetAuthMethodDistribution = (
params: TGetAuthMethodDistributionDTO,
options?: Omit<
diff --git a/frontend/src/hooks/api/secretInsights/types.ts b/frontend/src/hooks/api/secretInsights/types.ts
index fca213b2c3..597f84325b 100644
--- a/frontend/src/hooks/api/secretInsights/types.ts
+++ b/frontend/src/hooks/api/secretInsights/types.ts
@@ -1,4 +1,3 @@
-import { OrderByDirection } from "../generic/types";
import { IdentityAuthMethod } from "../identities/enums";
export type TCalendarRotation = {
@@ -80,32 +79,57 @@ export type TSecretExposure = {
drivers: { kind: SecretExposureDriver; points: number; label: string }[];
};
-export enum SecretExposureOrderBy {
- SecretKey = "secretKey",
- Environment = "environment",
- SecretPath = "secretPath"
+export enum UnusedAccessPrincipalType {
+ User = "user",
+ Identity = "identity",
+ Group = "group"
}
-export type TGetSecretExposureDTO = {
+// A user, group or machine identity that can read secrets it has not read in the tracked period.
+export type TUnusedAccessPrincipal = {
+ principalType: UnusedAccessPrincipalType;
+ principalId: string;
+ name: string;
+ // Groups only.
+ memberCount: number | null;
+ entitledCount: number;
+ unreadCount: number;
+ environments: string[];
+ lastReadAt: string | null;
+ accessVia: string[];
+};
+
+export type TGetUnusedAccessDTO = {
projectId: string;
offset: number;
limit: number;
- orderBy?: SecretExposureOrderBy;
- orderDirection?: OrderByDirection;
+ search?: string;
};
-export type TExposedSecret = TSecretExposureCounts & {
+export type TGetUnusedAccessResponse = {
+ principals: TUnusedAccessPrincipal[];
+ totalCount: number;
+ trackingStartedAt: string;
+ preliminaryUntil: string;
+ remainingTtl: number;
+};
+
+export type TGetUnusedAccessPrincipalDTO = {
+ projectId: string;
+ principalType: UnusedAccessPrincipalType;
+ principalId: string;
+};
+
+export type TUnusedSecret = {
secretKey: string;
environment: string;
secretPath: string;
- exposure: TSecretExposure;
};
-export type TGetSecretExposureResponse = {
- secrets: TExposedSecret[];
- totalCount: number;
+export type TGetUnusedAccessPrincipalResponse = {
+ principal: TUnusedAccessPrincipal;
+ secrets: TUnusedSecret[];
unlistedCount: number;
- bands: Record<SecretExposureBand, number>;
trackingStartedAt: string;
preliminaryUntil: string;
remainingTtl: number;
diff --git a/frontend/src/pages/secret-manager/InsightsPage/InsightsPage.tsx b/frontend/src/pages/secret-manager/InsightsPage/InsightsPage.tsx
index 5e8261deb8..ca926973a8 100644
--- a/frontend/src/pages/secret-manager/InsightsPage/InsightsPage.tsx
+++ b/frontend/src/pages/secret-manager/InsightsPage/InsightsPage.tsx
@@ -34,7 +34,7 @@ import {
DuplicatedSecretsCard,
InsightsSummaryCards,
SecretAccessChart,
- SecretExposureCard
+ UnusedAccessCard
} from "./components";
export const InsightsPage = withProjectPermission(
@@ -137,7 +137,7 @@ export const InsightsPage = withProjectPermission(
<AuditReportsCard />
</div>
<div className="mt-6">
- <SecretExposureCard />
+ <UnusedAccessCard />
</div>
<div className="mt-6 grid items-start gap-6 xl:grid-cols-[1.3fr_1fr]">
<div className="flex flex-col gap-6">
diff --git a/frontend/src/pages/secret-manager/InsightsPage/components/UnusedAccessCard.tsx b/frontend/src/pages/secret-manager/InsightsPage/components/UnusedAccessCard.tsx
new file mode 100644
index 0000000000..2d0f5d46b2
--- /dev/null
+++ b/frontend/src/pages/secret-manager/InsightsPage/components/UnusedAccessCard.tsx
@@ -0,0 +1,226 @@
+import { useState } from "react";
+import axios from "axios";
+import { format } from "date-fns";
+import { ChevronRightIcon, InfoIcon, SearchIcon } from "lucide-react";
+
+import { formatReadDay } from "@app/components/secrets/SecretReadStatusBadge";
+import {
+ Badge,
+ Card,
+ CardContent,
+ CardDescription,
+ CardHeader,
+ CardTitle,
+ Empty,
+ EmptyDescription,
+ EmptyHeader,
+ EmptyTitle,
+ InputGroup,
+ InputGroupAddon,
+ InputGroupInput,
+ Pagination,
+ Skeleton,
+ Table,
+ TableBody,
+ TableCell,
+ TableHead,
+ TableHeader,
+ TableRow
+} from "@app/components/v3";
+import { useProject, useSubscription } from "@app/context";
+import { usePagination, useResetPageHelper } from "@app/hooks";
+import { TUnusedAccessPrincipal, useGetUnusedAccess } from "@app/hooks/api/secretInsights";
+
+import {
+ describeReadPeriod,
+ formatRemainingTtl,
+ PRINCIPAL_TYPE_CONFIG
+} from "./unusedAccessHelpers";
+import { UnusedAccessPrincipalSheet } from "./UnusedAccessPrincipalSheet";
+
+export const UnusedAccessCard = () => {
+ const { currentProject, projectId } = useProject();
+ const { subscription } = useSubscription();
+ const { page, setPage, perPage, setPerPage, offset, limit, search, setSearch, debouncedSearch } =
+ usePagination("", { initPerPage: 10 });
+ const [selected, setSelected] = useState<TUnusedAccessPrincipal | null>(null);
+
+ const { data, isPending, error } = useGetUnusedAccess(
+ { projectId, offset, limit, search: debouncedSearch || undefined },
+ { enabled: Boolean(subscription?.secretAccessInsights) }
+ );
+ const totalCount = data?.totalCount ?? 0;
+ useResetPageHelper({ totalCount, offset, setPage });
+
+ const updatesIn =
+ data?.remainingTtl != null && data.remainingTtl >= 0
+ ? formatRemainingTtl(data.remainingTtl)
+ : null;
+ const environmentNames = new Map(currentProject.environments.map((env) => [env.slug, env.name]));
+ const readPeriod = data
+ ? describeReadPeriod(data.trackingStartedAt, data.preliminaryUntil)
+ : "in the last 30 days";
+ const isPreliminary = Boolean(data && new Date(data.preliminaryUntil) > new Date());
+
+ const renderBody = () => {
+ if (isPending) return <Skeleton className="h-[200px] w-full" />;
+
+ if (!data) {
+ return (
+ <Empty className="border">
+ <EmptyHeader>
+ <EmptyTitle>Could not load unused access</EmptyTitle>
+ <EmptyDescription>
+ {(axios.isAxiosError(error) &&
+ (error.response?.data as { message?: string })?.message) ||
+ "Try again in a moment."}
+ </EmptyDescription>
+ </EmptyHeader>
+ </Empty>
+ );
+ }
+
+ if (totalCount === 0) {
+ return (
+ <Empty className="border">
+ <EmptyHeader>
+ <EmptyTitle>
+ {debouncedSearch ? "No matching identity" : "No unused access found"}
+ </EmptyTitle>
+ <EmptyDescription>
+ {debouncedSearch
+ ? "No user, group or machine identity with unused access matches your search."
+ : `Every identity has read the secrets it can access ${readPeriod}.`}
+ </EmptyDescription>
+ </EmptyHeader>
+ </Empty>
+ );
+ }
+
+ return (
+ <>
+ <Table>
+ <TableHeader>
+ <TableRow>
+ <TableHead>Identity</TableHead>
+ <TableHead className="whitespace-nowrap">Unused</TableHead>
+ <TableHead className="whitespace-nowrap">Unused In</TableHead>
+ <TableHead className="whitespace-nowrap">Last Read</TableHead>
+ <TableHead className="whitespace-nowrap">Access Via</TableHead>
+ <TableHead variant="action" />
+ </TableRow>
+ </TableHeader>
+ <TableBody>
+ {data.principals.map((row) => {
+ const { icon: TypeIcon, label } = PRINCIPAL_TYPE_CONFIG[row.principalType];
+ const typeLine =
+ row.memberCount != null
+ ? `${label} · ${row.memberCount} ${row.memberCount === 1 ? "member" : "members"}`
+ : label;
+ return (
+ <TableRow
+ key={`${row.principalType}-${row.principalId}`}
+ className="group/row cursor-pointer"
+ onClick={() => setSelected(row)}
+ >
+ <TableCell isTruncatable className="max-w-64">
+ <div className="flex items-center gap-2">
+ <TypeIcon className="size-4 shrink-0 text-accent" />
+ <div className="min-w-0">
+ <div className="truncate font-medium">{row.name}</div>
+ <div className="truncate text-xs text-muted">{typeLine}</div>
+ </div>
+ </div>
+ </TableCell>
+ <TableCell className="whitespace-nowrap">
+ <span className="font-medium">{row.unreadCount}</span>
+ <span className="text-muted">
+ {" "}
+ of {row.entitledCount} {row.entitledCount === 1 ? "secret" : "secrets"}
+ </span>
+ </TableCell>
+ <TableCell>
+ <div className="flex flex-wrap gap-1">
+ {row.environments.map((environment) => (
+ <Badge key={environment} variant="neutral">
+ {environmentNames.get(environment) ?? environment}
+ </Badge>
+ ))}
+ </div>
+ </TableCell>
+ <TableCell className="whitespace-nowrap">
+ {row.lastReadAt ? (
+ formatReadDay(row.lastReadAt)
+ ) : (
+ <span className="text-muted">None {readPeriod}</span>
+ )}
+ </TableCell>
+ <TableCell isTruncatable className="max-w-56">
+ <span className="truncate">{row.accessVia.join(" · ")}</span>
+ </TableCell>
+ <TableCell variant="action">
+ <ChevronRightIcon className="size-4 text-muted" />
+ </TableCell>
+ </TableRow>
+ );
+ })}
+ </TableBody>
+ </Table>
+ <Pagination
+ count={totalCount}
+ page={page}
+ perPage={perPage}
+ onChangePage={setPage}
+ onChangePerPage={setPerPage}
+ />
+ </>
+ );
+ };
+
+ return (
+ <>
+ <Card>
+ <CardHeader>
+ <CardTitle>
+ Unused Access
+ {updatesIn && (
+ <Badge variant="neutral" className="ml-2">
+ Updates in {updatesIn}
+ </Badge>
+ )}
+ </CardTitle>
+ <CardDescription>
+ Users, groups, and machine identities that can read secrets they have not read{" "}
+ {readPeriod}. Select one to see which secrets.
+ </CardDescription>
+ </CardHeader>
+ <CardContent className="flex flex-col gap-4">
+ {isPreliminary && (
+ <p className="flex items-center gap-1.5 text-xs text-muted">
+ <InfoIcon className="size-3.5 shrink-0" />
+ Reads have been tracked since {format(new Date(data!.trackingStartedAt), "PP")}, so
+ access counts as unused once it has gone that long without a read; the full 30-day
+ window applies from {format(new Date(data!.preliminaryUntil), "PP")}.
+ </p>
+ )}
+ <InputGroup className="max-w-sm">
+ <InputGroupAddon>
+ <SearchIcon />
+ </InputGroupAddon>
+ <InputGroupInput
+ id="unused-access-search"
+ value={search}
+ onChange={(event) => {
+ setSearch(event.target.value);
+ setPage(1);
+ }}
+ placeholder="Search by name..."
+ />
+ </InputGroup>
+ {renderBody()}
+ </CardContent>
+ </Card>
+ <UnusedAccessPrincipalSheet principal={selected} onClose={() => setSelected(null)} />
+ </>
+ );
+};
diff --git a/frontend/src/pages/secret-manager/InsightsPage/components/UnusedAccessPrincipalSheet.tsx b/frontend/src/pages/secret-manager/InsightsPage/components/UnusedAccessPrincipalSheet.tsx
new file mode 100644
index 0000000000..c08ab98860
--- /dev/null
+++ b/frontend/src/pages/secret-manager/InsightsPage/components/UnusedAccessPrincipalSheet.tsx
@@ -0,0 +1,199 @@
+import { useState } from "react";
+import { useParams } from "@tanstack/react-router";
+import axios from "axios";
+
+import { GoToSecretButton } from "@app/components/secrets/GoToSecretButton";
+import {
+ Badge,
+ Button,
+ Empty,
+ EmptyDescription,
+ EmptyHeader,
+ EmptyTitle,
+ Sheet,
+ SheetContent,
+ SheetDescription,
+ SheetHeader,
+ SheetTitle,
+ Skeleton,
+ Table,
+ TableBody,
+ TableCell,
+ TableRow
+} from "@app/components/v3";
+import { useProject } from "@app/context";
+import {
+ TGetUnusedAccessPrincipalResponse,
+ TUnusedAccessPrincipal,
+ UnusedAccessPrincipalType,
+ useGetUnusedAccessPrincipal
+} from "@app/hooks/api/secretInsights";
+
+import { describeReadPeriod, PRINCIPAL_TYPE_CONFIG } from "./unusedAccessHelpers";
+
+// Rows shown per environment before "N more" opens the rest.
+const PREVIEW_ROWS = 5;
+
+type SecretsProps = {
+ data: TGetUnusedAccessPrincipalResponse;
+};
+
+const PrincipalSecrets = ({ data }: SecretsProps) => {
+ const { currentProject, projectId } = useProject();
+ const { orgId } = useParams({ strict: false });
+ const [expanded, setExpanded] = useState<Set<string>>(() => new Set());
+
+ const environmentNames = new Map(currentProject.environments.map((env) => [env.slug, env.name]));
+ const byEnvironment = new Map<string, typeof data.secrets>();
+ data.secrets.forEach((secret) => {
+ byEnvironment.set(secret.environment, [
+ ...(byEnvironment.get(secret.environment) ?? []),
+ secret
+ ]);
+ });
+
+ if (data.secrets.length === 0) {
+ return (
+ <Empty className="border">
+ <EmptyHeader>
+ <EmptyTitle>Nothing to show</EmptyTitle>
+ <EmptyDescription>
+ {data.unlistedCount > 0
+ ? "The unread secrets are ones you cannot see."
+ : "This principal has no unread secrets anymore."}
+ </EmptyDescription>
+ </EmptyHeader>
+ </Empty>
+ );
+ }
+
+ return (
+ <div className="flex flex-col gap-6">
+ {[...byEnvironment.entries()].map(([environment, secrets]) => {
+ const isExpanded = expanded.has(environment);
+ const shown = isExpanded ? secrets : secrets.slice(0, PREVIEW_ROWS);
+ const hidden = secrets.length - shown.length;
+ return (
+ <div key={environment} className="flex flex-col gap-2">
+ <div className="flex items-baseline gap-2">
+ <h3 className="text-sm font-medium">
+ {environmentNames.get(environment) ?? environment}
+ </h3>
+ <span className="text-xs text-muted">{secrets.length} unused</span>
+ </div>
+ <Table>
+ <TableBody>
+ {shown.map((secret) => (
+ <TableRow key={`${secret.secretPath}/${secret.secretKey}`}>
+ <TableCell isTruncatable className="max-w-64 font-mono">
+ <span className="truncate">{secret.secretKey}</span>
+ </TableCell>
+ <TableCell isTruncatable className="max-w-48 text-muted">
+ <span className="truncate">{secret.secretPath}</span>
+ </TableCell>
+ <TableCell variant="action">
+ <GoToSecretButton
+ orgId={orgId as string}
+ projectId={projectId}
+ secretKey={secret.secretKey}
+ secretPath={secret.secretPath}
+ environmentSlug={environment}
+ isProjectMember
+ />
+ </TableCell>
+ </TableRow>
+ ))}
+ </TableBody>
+ </Table>
+ {hidden > 0 && (
+ <Button
+ variant="ghost"
+ size="xs"
+ className="self-start"
+ onClick={() => setExpanded((previous) => new Set(previous).add(environment))}
+ >
+ {hidden} more
+ </Button>
+ )}
+ </div>
+ );
+ })}
+ {data.unlistedCount > 0 && (
+ <p className="text-xs text-muted">
+ {data.unlistedCount} more unread {data.unlistedCount === 1 ? "secret is" : "secrets are"}{" "}
+ not listed.
+ </p>
+ )}
+ </div>
+ );
+};
+
+type Props = {
+ principal: TUnusedAccessPrincipal | null;
+ onClose: () => void;
+};
+
+export const UnusedAccessPrincipalSheet = ({ principal, onClose }: Props) => {
+ const { projectId } = useProject();
+ const { data, isPending, error } = useGetUnusedAccessPrincipal(
+ {
+ projectId,
+ principalType: principal?.principalType ?? UnusedAccessPrincipalType.User,
+ principalId: principal?.principalId ?? ""
+ },
+ { enabled: Boolean(principal) }
+ );
+
+ const renderBody = () => {
+ if (!principal) return null;
+ if (isPending) return <Skeleton className="h-48 w-full" />;
+ if (!data) {
+ return (
+ <Empty className="border">
+ <EmptyHeader>
+ <EmptyTitle>Could not load unused secrets</EmptyTitle>
+ <EmptyDescription>
+ {(axios.isAxiosError(error) &&
+ (error.response?.data as { message?: string })?.message) ||
+ "Try again in a moment."}
+ </EmptyDescription>
+ </EmptyHeader>
+ </Empty>
+ );
+ }
+ return (
+ <PrincipalSecrets key={`${principal.principalType}-${principal.principalId}`} data={data} />
+ );
+ };
+
+ const readPeriod = data
+ ? describeReadPeriod(data.trackingStartedAt, data.preliminaryUntil)
+ : "in the last 30 days";
+
+ return (
+ <Sheet
+ open={principal !== null}
+ onOpenChange={(isOpen) => {
+ if (!isOpen) onClose();
+ }}
+ >
+ <SheetContent size="form" side="right" onOpenAutoFocus={(event) => event.preventDefault()}>
+ {principal && (
+ <SheetHeader>
+ <SheetTitle className="flex items-center gap-2">
+ <span className="truncate">{principal.name}</span>
+ <Badge variant="neutral">
+ {PRINCIPAL_TYPE_CONFIG[principal.principalType].label}
+ </Badge>
+ </SheetTitle>
+ <SheetDescription>
+ Has not read {principal.unreadCount} of the {principal.entitledCount}{" "}
+ {principal.entitledCount === 1 ? "secret" : "secrets"} it can access {readPeriod}.
+ </SheetDescription>
+ </SheetHeader>
+ )}
+ <div className="flex thin-scrollbar flex-col overflow-y-auto p-4">{renderBody()}</div>
+ </SheetContent>
+ </Sheet>
+ );
+};
diff --git a/frontend/src/pages/secret-manager/InsightsPage/components/index.ts b/frontend/src/pages/secret-manager/InsightsPage/components/index.ts
index 96dba6d882..ad54ba194c 100644
--- a/frontend/src/pages/secret-manager/InsightsPage/components/index.ts
+++ b/frontend/src/pages/secret-manager/InsightsPage/components/index.ts
@@ -6,6 +6,6 @@ export { CalendarLegend } from "./CalendarLegend";
export { DuplicatedSecretsCard } from "./DuplicatedSecretsCard";
export { InsightsSummaryCards } from "./InsightsSummaryCards";
export { SecretAccessChart } from "./SecretAccessChart";
-export { SecretExposureCard } from "./SecretExposureCard";
export type { CalendarEvent } from "./types";
+export { UnusedAccessCard } from "./UnusedAccessCard";
// export { WorldMap } from "./WorldMap";
diff --git a/frontend/src/pages/secret-manager/InsightsPage/components/unusedAccessHelpers.ts b/frontend/src/pages/secret-manager/InsightsPage/components/unusedAccessHelpers.ts
new file mode 100644
index 0000000000..2079283df6
--- /dev/null
+++ b/frontend/src/pages/secret-manager/InsightsPage/components/unusedAccessHelpers.ts
@@ -0,0 +1,32 @@
+import { format } from "date-fns";
+import { HardDriveIcon, UserIcon, UsersIcon } from "lucide-react";
+
+import { UnusedAccessPrincipalType } from "@app/hooks/api/secretInsights";
+
+export const PRINCIPAL_TYPE_CONFIG: Record<
+ UnusedAccessPrincipalType,
+ { icon: typeof UserIcon; label: string }
+> = {
+ [UnusedAccessPrincipalType.User]: { icon: UserIcon, label: "User" },
+ [UnusedAccessPrincipalType.Identity]: { icon: HardDriveIcon, label: "Machine Identity" },
+ [UnusedAccessPrincipalType.Group]: { icon: UsersIcon, label: "Group" }
+};
+
+// The period the reads are judged on: the full window once tracking is that old, else since it began.
+export const describeReadPeriod = (trackingStartedAt: string, preliminaryUntil: string) =>
+ new Date(preliminaryUntil) > new Date()
+ ? `since ${format(new Date(trackingStartedAt), "PP")}`
+ : "in the last 30 days";
+
+export const formatRemainingTtl = (seconds: number) => {
+ if (seconds < 60) {
+ const remainingSeconds = Math.max(1, seconds);
+ return `${remainingSeconds} ${remainingSeconds === 1 ? "second" : "seconds"}`;
+ }
+ if (seconds < 60 * 60) {
+ const minutes = Math.ceil(seconds / 60);
+ return `${minutes} ${minutes === 1 ? "minute" : "minutes"}`;
+ }
+ const hours = Math.ceil(seconds / (60 * 60));
+ return `${hours} ${hours === 1 ? "hour" : "hours"}`;
+};