Infisical is the open-source platform for securing secrets, certificates, access, and AI Agents.
TypeScript acmeagentsai-agentscertificate-managementdevsecopsenvironment-variableskubernetesopen-sourcepampkipostgresprivate-caprivileged-access-managementsecret-managementsecret-managersecretssecrets-managementsecuritysecurity-toolsvault
feat(insights): show entitled, unread and ghost reader counts per secret on the unused access card
Dimitris Staratzis4f841c46dea8
diff --git a/backend/CLAUDE.md b/backend/CLAUDE.mdindex 917e402005..86e073f650 100644--- a/backend/CLAUDE.md+++ b/backend/CLAUDE.md@@ -1147,7 +1147,10 @@ owns the two read endpoints and hands `recordRead` / `recordBulkRead` through toless than 30 days the card already lists access unread since tracking began, and the response's`preliminaryUntil` tells the UI to label it preliminary. Which secrets a change opened up is not recorded, so anyaccess change restarts the window, and a custom role's rules being edited is not seen at all. The per-secret sheet- shows the plain fact instead: a read, or "No reads".+ shows the plain fact instead: a read, or "No reads". Each card row also carries three counts for its secret,+ derived from sets the computation already holds: `entitledCount` (everyone who can read the value today,+ admins included), `unreadCount` (the non-admins among them with no read in the window) and+ `ghostReaderCount` (readers in the window who can no longer read it, so they still know the value).### Audit Log Event Classes and Settingsdiff --git a/backend/src/ee/services/insights/insights-schemas.ts b/backend/src/ee/services/insights/insights-schemas.tsindex 2c1e380dac..f1b7ac419f 100644--- a/backend/src/ee/services/insights/insights-schemas.ts+++ b/backend/src/ee/services/insights/insights-schemas.ts@@ -79,7 +79,10 @@ export const UnusedSecretAccessSchema = z.object({secretPath: z.string().describe(INSIGHTS.GET_UNUSED_SECRET_ACCESS.secretPath),actorType: z.enum([ActorType.USER, ActorType.IDENTITY]).describe(INSIGHTS.GET_UNUSED_SECRET_ACCESS.actorType),actorId: z.string().describe(INSIGHTS.GET_UNUSED_SECRET_ACCESS.actorId),- actorName: z.string().describe(INSIGHTS.GET_UNUSED_SECRET_ACCESS.actorName)+ actorName: z.string().describe(INSIGHTS.GET_UNUSED_SECRET_ACCESS.actorName),+ entitledCount: z.number().int().describe(INSIGHTS.GET_UNUSED_SECRET_ACCESS.entitledCount),+ unreadCount: z.number().int().describe(INSIGHTS.GET_UNUSED_SECRET_ACCESS.unreadCount),+ ghostReaderCount: z.number().int().describe(INSIGHTS.GET_UNUSED_SECRET_ACCESS.ghostReaderCount)}).array().describe(INSIGHTS.GET_UNUSED_SECRET_ACCESS.unusedAccess)diff --git a/backend/src/ee/services/secret-read-activity/secret-read-activity-service.ts b/backend/src/ee/services/secret-read-activity/secret-read-activity-service.tsindex 4e2abbb614..ac491a44ff 100644--- a/backend/src/ee/services/secret-read-activity/secret-read-activity-service.ts+++ b/backend/src/ee/services/secret-read-activity/secret-read-activity-service.ts@@ -45,7 +45,7 @@ import {TUnusedSecretAccess} from "./secret-read-activity-types";-const UNUSED_SECRET_ACCESS_CACHE_TTL_SECONDS = 24 * 60 * 60;+const UNUSED_SECRET_ACCESS_CACHE_TTL_SECONDS = 30;const REACH_YIELD_INTERVAL = 100;// Longer than a computation can take, so the lock is not lost mid-scan; waiters give up well before a request times out.const UNUSED_SECRET_ACCESS_COMPUTE_LOCK_TTL_MS = 5 * 60 * 1000;@@ -316,18 +316,20 @@ export const secretReadActivityServiceFactory = ({]);const judgedFrom = trackingStartedAt > windowStart ? trackingStartedAt : windowStart;// Actors with identical rules always get the same answer, so each distinct rule set is checked once.- const actorGroups = Object.values(+ const allActorGroups = Object.values(groupBy([...userPermissions.map((actor) => ({ ...actor, actorType: ActorType.USER as const })),...identityPermissions.map((actor) => ({ ...actor, actorType: ActorType.IDENTITY as const }))- ].filter((actor) => !adminActorIds.has(actor.id)),+ ],(actor) => JSON.stringify(actor.permission.rules)));- const unreadActorsOf = ({ secret, environment, secretPath, trackedSince, reads }: (typeof activities)[number]) =>- actorGroups+ // Everyone who can read the value today, admins included. Unused access is judged on the non-admins among them;+ // ghost readers are readers in the window who are not among them at all, so their access was since removed.+ const entitledActorsOf = ({ secret, environment, secretPath }: (typeof activities)[number]) =>+ allActorGroups.filter(([{ permission }]) =>hasSecretReadValueOrDescribePermission(permission, ProjectPermissionSecretActions.ReadValue, {environment,@@ -336,12 +338,24 @@ export const secretReadActivityServiceFactory = ({secretTags: secret.tags?.map((tag) => tag.slug)}))- .flat()- .filter(- (actor) =>- !reads.has(`${actor.actorType}:${actor.id}`) &&- coversWholeWindow(trackedSince, accessChangedAtByActorId.get(actor.id), judgedFrom)- );+ .flat();++ const summarizeSecret = (activity: (typeof activities)[number]) => {+ const { trackedSince, reads } = activity;+ const entitled = entitledActorsOf(activity);+ const entitledKeys = new Set(entitled.map((actor) => `${actor.actorType}:${actor.id}`));+ const unread = entitled.filter(+ (actor) =>+ !adminActorIds.has(actor.id) &&+ !reads.has(`${actor.actorType}:${actor.id}`) &&+ coversWholeWindow(trackedSince, accessChangedAtByActorId.get(actor.id), judgedFrom)+ );+ let ghostReaderCount = 0;+ reads.forEach((_, key) => {+ if (!entitledKeys.has(key)) ghostReaderCount += 1;+ });+ return { entitledCount: entitled.length, unread, ghostReaderCount };+ };// Only counts are kept for every secret: a large project can have millions of unread pairs, and only the// highest-ranked ones are listed, so their rows are built in a second pass.@@ -352,7 +366,7 @@ export const secretReadActivityServiceFactory = ({await new Promise<void>((resolve) => {setImmediate(resolve);});- unreadCounts.push({ activityIndex, count: unreadActorsOf(activities[activityIndex]).length });+ unreadCounts.push({ activityIndex, count: summarizeSecret(activities[activityIndex]).unread.length });}unreadCounts.sort((a, b) => b.count - a.count);@@ -360,7 +374,8 @@ export const secretReadActivityServiceFactory = ({for (const { activityIndex, count } of unreadCounts) {if (rows.length >= UNUSED_SECRET_ACCESS_MAX_LISTED || count === 0) break;const activity = activities[activityIndex];- unreadActorsOf(activity).forEach((actor) =>+ const { entitledCount, unread, ghostReaderCount } = summarizeSecret(activity);+ unread.forEach((actor) =>rows.push({secretId: activity.secret.id,secretKey: activity.secret.key,@@ -368,7 +383,10 @@ export const secretReadActivityServiceFactory = ({secretPath: activity.secretPath,actorType: actor.actorType,actorId: actor.id,- actorName: actor.name+ actorName: actor.name,+ entitledCount,+ unreadCount: unread.length,+ ghostReaderCount}));}diff --git a/backend/src/ee/services/secret-read-activity/secret-read-activity-types.ts b/backend/src/ee/services/secret-read-activity/secret-read-activity-types.tsindex 82a9ccea2e..12292526cf 100644--- a/backend/src/ee/services/secret-read-activity/secret-read-activity-types.ts+++ b/backend/src/ee/services/secret-read-activity/secret-read-activity-types.ts@@ -100,6 +100,10 @@ export type TUnusedSecretAccess = {actorType: TSecretReaderType;actorId: string;actorName: string;+ // How the secret as a whole stands, repeated on each of its rows so a row can be read on its own.+ entitledCount: number;+ unreadCount: number;+ ghostReaderCount: number;};// Each value is the row field it sorts by.diff --git a/backend/src/lib/api-docs/constants.ts b/backend/src/lib/api-docs/constants.tsindex eebfe7594a..20ccd70219 100644--- a/backend/src/lib/api-docs/constants.ts+++ b/backend/src/lib/api-docs/constants.ts@@ -968,7 +968,11 @@ export const INSIGHTS = {secretPath: "The path of the folder the secret is in.",actorType: "Whether the entry is a user or a machine identity.",actorId: "The ID of the user or machine identity.",- actorName: "The username of the user, or the name of the machine identity."+ actorName: "The username of the user, or the name of the machine identity.",+ entitledCount: "How many users and machine identities, admins included, can read this secret's value today.",+ unreadCount: "How many of those, admins excluded, have not read it in the window. This row is one of them.",+ ghostReaderCount:+ "How many users and machine identities read this secret in the window but can no longer read it today, for example after leaving the project. They still know the value."},GET_SECRETS_ACCESS_VOLUME: {days: "One entry for each of the last seven days, oldest first. Days with no secret access are included with a total of zero.",diff --git a/frontend/src/hooks/api/secretInsights/types.ts b/frontend/src/hooks/api/secretInsights/types.tsindex 4f3740b467..44058c87e8 100644--- a/frontend/src/hooks/api/secretInsights/types.ts+++ b/frontend/src/hooks/api/secretInsights/types.ts@@ -74,6 +74,9 @@ export type TUnusedSecretAccess = {actorType: "user" | "identity";actorId: string;actorName: string;+ entitledCount: number;+ unreadCount: number;+ ghostReaderCount: number;};export type TGetUnusedSecretAccessResponse = {diff --git a/frontend/src/pages/secret-manager/InsightsPage/components/UnusedSecretAccessCard.tsx b/frontend/src/pages/secret-manager/InsightsPage/components/UnusedSecretAccessCard.tsxindex cbde1d6531..3e9c233824 100644--- a/frontend/src/pages/secret-manager/InsightsPage/components/UnusedSecretAccessCard.tsx+++ b/frontend/src/pages/secret-manager/InsightsPage/components/UnusedSecretAccessCard.tsx@@ -33,7 +33,10 @@ import {TableHead,TableHeader,TableRow,- type TableSortDirection+ type TableSortDirection,+ Tooltip,+ TooltipContent,+ TooltipTrigger} from "@app/components/v3";import { cn } from "@app/components/v3/utils";import { useProject, useSubscription } from "@app/context";@@ -176,6 +179,8 @@ export const UnusedSecretAccessCard = () => {/></TableHead>))}+ <TableHead className="whitespace-nowrap">No Reads</TableHead>+ <TableHead className="whitespace-nowrap">Ghost Readers</TableHead><TableHead variant="action" /></TableRow></TableHeader>@@ -210,6 +215,34 @@ export const UnusedSecretAccessCard = () => {<span className="truncate">{row.actorName}</span></div></TableCell>+ <TableCell className="whitespace-nowrap">+ <Tooltip>+ <TooltipTrigger asChild>+ <span>+ {row.unreadCount} of {row.entitledCount}+ </span>+ </TooltipTrigger>+ <TooltipContent>+ {row.unreadCount} of the {row.entitledCount} who can read this secret have+ not read it in the last 30 days+ </TooltipContent>+ </Tooltip>+ </TableCell>+ <TableCell className="whitespace-nowrap">+ {row.ghostReaderCount > 0 ? (+ <Tooltip>+ <TooltipTrigger asChild>+ <Badge variant="warning">{row.ghostReaderCount}</Badge>+ </TooltipTrigger>+ <TooltipContent>+ {row.ghostReaderCount} read this secret in the last 30 days but can no+ longer access it. They still know the value.+ </TooltipContent>+ </Tooltip>+ ) : (+ <span className="text-muted">0</span>+ )}+ </TableCell><TableCell variant="action"><GoToSecretButtonorgId={orgId as string}