Skip to content

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

feat(insights): show unused access before a project has 30 days of reads, judged since tracking began

Dimitris Staratzis6c5f642d80de
diff --git a/backend/CLAUDE.md b/backend/CLAUDE.md
index ef08d7da3b..cb40a7b509 100644
--- a/backend/CLAUDE.md
+++ b/backend/CLAUDE.md
@@ -1138,16 +1138,16 @@ owns the two read endpoints and hands `recordRead` / `recordBulkRead` through to
(`UNUSED_SECRET_ACCESS_CACHE_TTL_SECONDS`), grouping actors by identical rules so each rule set is checked once
per secret. The per-secret endpoint checks the caller's access to the secret before building its reach, which
decrypts every secret that could reference it.
-- **Only a full window is judged.** Until a project's reads have been tracked for 30 days (tracking start is the
- later of the migration that created the table and the project's creation), nobody counts as unused access: the
- reads before tracking began are unknown, so `$loadSecretSummarizer` returns no unread readers or groups, the
- card is empty, and the response's `unusedAccessFrom` says when judging starts. After that, the card leaves out
- project admins (users and identities with the Admin role, directly or through a group, from
- `findAdminActorIds`): they can read everything by design. Their reads are still recorded, so the access sheet's
- Last Read stays true for them. A pair is listed once the secret (`trackedSince`) and the actor's access
- (`findAccessChangedAt`: the latest membership creation, role or privilege creation, edit or expiry) both predate
- the window start. Which secrets a change opened up is not recorded, so any access change restarts the window,
- including an edit to the rules of a custom role the reader holds. The per-secret sheet shows the plain fact
+- **The card judges a full window, or everything since tracking began.** Tracking starts at the later of the
+ migration that created the table and the project's creation. In a project tracked for less than 30 days, the
+ window starts when tracking did (`judgedFrom`), and the response's `fullWindowFrom` says when results first
+ cover 30 days, so the UI words the period "since <date>" until then. The card leaves out project admins (users
+ and identities with the Admin role, directly or through a group, from `findAdminActorIds`): they can read
+ everything by design. Their reads are still recorded, so the access sheet's Last Read stays true for them. A
+ pair is listed once the secret (`trackedSince`) and the actor's access (`findAccessChangedAt`: the latest
+ membership creation, role or privilege creation, edit or expiry) both predate `judgedFrom`. Which secrets a
+ change opened up is not recorded, so any access change restarts the window, including an edit to the rules of
+ a custom role the reader holds. The per-secret sheet shows the plain fact
instead: a read, "No reads", or "No reads yet" with the reason. 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,
project admins left out, since a secret is not exposed to someone who can read everything by design),
@@ -1157,8 +1157,7 @@ owns the two read endpoints and hands `recordRead` / `recordBulkRead` through to
to 100 score with Low, Elevated, High and Critical bands and whole-point drivers that add up to it (readers up
to 45 on a log scale saturating at 40, ghost readers up to 30 saturating at 4, unused access up to 25 by
share). It is the blast radius prototype's three read-activity terms rescaled; the terms that would need new
- queries (syncs, rotation age, cross-project destinations) are deliberately left out. Before a project has a full
- window the unused-access term is zero, since nothing is judged. The score, the graph and the ghost readers live only in the secret's access sheet
+ queries (syncs, rotation age, cross-project destinations) are deliberately left out. The score, the graph and the ghost readers live only in the secret's access sheet
(`GET /secrets/:name/read-activity`), which also returns, for every reader who can read the value, whether they
count as unused access and why not (`isAdmin`, `accessChangedAt` after `judgedFrom`, or a secret newer than it),
and names each ghost reader from the project's members, else from the user or identity row, else null.
diff --git a/backend/src/ee/routes/v1/insights-router.ts b/backend/src/ee/routes/v1/insights-router.ts
index 7781c00e1d..ee81f6b87f 100644
--- a/backend/src/ee/routes/v1/insights-router.ts
+++ b/backend/src/ee/routes/v1/insights-router.ts
@@ -493,7 +493,7 @@ export const registerInsightsRouter = async (server: FastifyZodProvider) => {
onRequest: verifyAuth([AuthMode.JWT, AuthMode.OAUTH]),
handler: async (req, reply) => {
const { projectId } = req.params;
- const { principals, totalCount, trackingStartedAt, unusedAccessFrom, remainingTTL, projectName } =
+ const { principals, totalCount, trackingStartedAt, fullWindowFrom, remainingTTL, projectName } =
await server.services.secretReadActivity.listUnusedAccess({ projectId, ...req.query }, req.permission);
await server.services.auditLog.createAuditLog({
projectId,
@@ -507,7 +507,7 @@ export const registerInsightsRouter = async (server: FastifyZodProvider) => {
if (remainingTTL && remainingTTL >= 0) {
void reply.header("X-Cache-TTL", remainingTTL);
}
- return { principals, totalCount, trackingStartedAt, unusedAccessFrom };
+ return { principals, totalCount, trackingStartedAt, fullWindowFrom };
}
});
@@ -533,7 +533,7 @@ export const registerInsightsRouter = async (server: FastifyZodProvider) => {
onRequest: verifyAuth([AuthMode.JWT, AuthMode.OAUTH]),
handler: async (req, reply) => {
const { projectId, principalType, principalId } = req.params;
- const { principal, secrets, unlistedCount, trackingStartedAt, unusedAccessFrom, remainingTTL, projectName } =
+ const { principal, secrets, unlistedCount, trackingStartedAt, fullWindowFrom, remainingTTL, projectName } =
await server.services.secretReadActivity.getUnusedAccessPrincipal(
{ projectId, principalType, principalId },
req.permission
@@ -550,7 +550,7 @@ export const registerInsightsRouter = async (server: FastifyZodProvider) => {
if (remainingTTL && remainingTTL >= 0) {
void reply.header("X-Cache-TTL", remainingTTL);
}
- return { principal, secrets, unlistedCount, trackingStartedAt, unusedAccessFrom };
+ return { principal, secrets, unlistedCount, trackingStartedAt, fullWindowFrom };
}
});
diff --git a/backend/src/ee/services/insights/insights-schemas.ts b/backend/src/ee/services/insights/insights-schemas.ts
index b5f13d29a3..08d8ae46c4 100644
--- a/backend/src/ee/services/insights/insights-schemas.ts
+++ b/backend/src/ee/services/insights/insights-schemas.ts
@@ -82,7 +82,7 @@ const UnusedAccessPrincipalRowSchema = z.object({
export const UnusedAccessSchema = z.object({
totalCount: z.number().int().describe(INSIGHTS.GET_UNUSED_ACCESS.totalCount),
trackingStartedAt: z.date().describe(INSIGHTS.GET_UNUSED_ACCESS.trackingStartedAt),
- unusedAccessFrom: z.date().describe(INSIGHTS.GET_UNUSED_ACCESS.unusedAccessFrom),
+ fullWindowFrom: z.date().describe(INSIGHTS.GET_UNUSED_ACCESS.fullWindowFrom),
principals: UnusedAccessPrincipalRowSchema.array().describe(INSIGHTS.GET_UNUSED_ACCESS.principals)
});
@@ -90,7 +90,7 @@ export const UnusedAccessPrincipalSchema = z.object({
principal: UnusedAccessPrincipalRowSchema,
unlistedCount: z.number().int().describe(INSIGHTS.GET_UNUSED_ACCESS_PRINCIPAL.unlistedCount),
trackingStartedAt: z.date().describe(INSIGHTS.GET_UNUSED_ACCESS.trackingStartedAt),
- unusedAccessFrom: z.date().describe(INSIGHTS.GET_UNUSED_ACCESS.unusedAccessFrom),
+ fullWindowFrom: z.date().describe(INSIGHTS.GET_UNUSED_ACCESS.fullWindowFrom),
secrets: z
.object({
secretKey: z.string().describe(INSIGHTS.GET_UNUSED_ACCESS_PRINCIPAL.secretKey),
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.ts
index e5b0e11c0e..e2f1c08534 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
@@ -287,7 +287,7 @@ export const secretReadActivityServiceFactory = ({
// non-admins among them, since admins can read everything by design; ghost readers are readers in the window
// who are not among them at all, so their access was since removed; and the exposure score is computed from
// those counts. Groups are judged on their own too: a group's access to a secret is unused when none of its
- // members read it. Nothing is judged until the project has a full window of reads.
+ // members read it. Until a project has a full window of reads, it is judged on the reads since tracking began.
const $loadSecretSummarizer = async (projectId: string, orgId: string, windowStart: Date) => {
const [
{ userPermissions, identityPermissions, groupPermissions },
@@ -308,10 +308,8 @@ export const secretReadActivityServiceFactory = ({
groupIds.length ? identityGroupMembershipDAL.find({ $in: { groupId: groupIds } }) : []
]);
const groupPermissionById = new Map(groupPermissions.map((group) => [group.id, group]));
+ // In a project tracked for less than the window, unused access is judged on the reads since tracking began.
const judgedFrom = trackingStartedAt > windowStart ? trackingStartedAt : windowStart;
- // Unused access is only judged on a full window of reads: until tracking has run for 30 days, the reads
- // before it began are unknown, so nobody counts as having left a secret unread.
- const isJudging = trackingStartedAt <= windowStart;
type TActor = {
id: string;
name?: string;
@@ -377,7 +375,6 @@ export const secretReadActivityServiceFactory = ({
const exposedTo = entitled.filter((actor) => !adminActorIds.has(actor.id));
const unread = exposedTo.filter(
(actor) =>
- isJudging &&
!reads.has(`${actor.actorType}:${actor.id}`) &&
coversWholeWindow(trackedSince, accessChangedAtByActorId.get(actor.id), judgedFrom)
);
@@ -387,7 +384,6 @@ export const secretReadActivityServiceFactory = ({
const entitledGroups = groups.filter((group) => canReadValue(group.permission));
const unreadGroups = entitledGroups.filter(
(group) =>
- isJudging &&
!group.memberKeys.some((key) => reads.has(key)) &&
coversWholeWindow(trackedSince, accessChangedAtByActorId.get(group.id), judgedFrom)
);
@@ -729,7 +725,7 @@ export const secretReadActivityServiceFactory = ({
remainingTTL,
projectName: project?.name ?? "",
trackingStartedAt,
- unusedAccessFrom: new Date(trackingStartedAt.getTime() + SECRET_READ_ACTIVITY_WINDOW_DAYS * DAY_IN_MS)
+ fullWindowFrom: new Date(trackingStartedAt.getTime() + SECRET_READ_ACTIVITY_WINDOW_DAYS * DAY_IN_MS)
};
};
@@ -775,7 +771,7 @@ export const secretReadActivityServiceFactory = ({
totalCount: matching.length,
projectName: tracking.projectName,
trackingStartedAt: tracking.trackingStartedAt,
- unusedAccessFrom: tracking.unusedAccessFrom,
+ fullWindowFrom: tracking.fullWindowFrom,
remainingTTL: tracking.remainingTTL
};
};
@@ -837,7 +833,7 @@ export const secretReadActivityServiceFactory = ({
unlistedCount: Math.max(0, principal.unreadCount - secrets.length),
projectName: tracking.projectName,
trackingStartedAt: tracking.trackingStartedAt,
- unusedAccessFrom: tracking.unusedAccessFrom,
+ fullWindowFrom: tracking.fullWindowFrom,
remainingTTL: tracking.remainingTTL
};
};
diff --git a/backend/src/lib/api-docs/constants.ts b/backend/src/lib/api-docs/constants.ts
index b4be6825f2..f5debe48ef 100644
--- a/backend/src/lib/api-docs/constants.ts
+++ b/backend/src/lib/api-docs/constants.ts
@@ -953,7 +953,7 @@ export const INSIGHTS = {
limit: "The maximum number of principals to return per page.",
search: "Only principals whose name contains this text, ignoring case.",
principals:
- "The users, groups and machine identities that can read secrets they have not read in the last 30 days, those with the most such secrets first. Project admins and admin groups are left out: they can read everything by design.",
+ "The users, groups and machine identities that can read secrets they have not read in the last 30 days (since tracking began, in a project tracked for less), those with the most such secrets first. Project admins and admin groups are left out: they can read everything by design.",
principalType: "Whether the principal is a user, a group or a machine identity.",
principalId: "The ID of the user, group or machine identity.",
name: "The username of the user, or the name of the group or machine identity.",
@@ -968,8 +968,8 @@ export const INSIGHTS = {
totalCount: "The number of principals the caller can page through.",
trackingStartedAt:
"When reads started being tracked for this project: the later of when read tracking was enabled on the instance and when the project was created.",
- unusedAccessFrom:
- "When unused access starts being judged: 30 days after reads started being tracked for the project. Until then nothing is listed, since reads from before tracking began are unknown."
+ fullWindowFrom:
+ "When the results first cover a full 30 days of reads: 30 days after reads started being tracked for the project. Before then they cover the reads since tracking began, and the access that existed then."
},
GET_UNUSED_ACCESS_PRINCIPAL: {
projectId: "The ID of the project.",
@@ -1516,7 +1516,7 @@ export const RAW_SECRETS = {
trackedSince:
"The start of the period reads are reported for: the later of 30 days ago, when read tracking began, and when the secret and its folder were created.",
judgedFrom:
- "The start of the period unused access is judged on: the later of 30 days ago and when read tracking began for the project. Nobody counts as unused access until it is 30 days ago, and then only readers whose access, like the secret, predates it.",
+ "The start of the period unused access is judged on: the later of 30 days ago and when read tracking began for the project. A reader only counts as unused access once the secret and their access both predate it.",
entitled:
"One entry for each user or machine identity that can read the secret's value today, project admins included so their reads can be shown, saying whether they count as unused access and, if not, why.",
readerName: "The username of the user, or the name of the machine identity. Null when it could not be resolved.",
diff --git a/frontend/src/hooks/api/secretInsights/types.ts b/frontend/src/hooks/api/secretInsights/types.ts
index 91c59d52a6..b1e4d7d688 100644
--- a/frontend/src/hooks/api/secretInsights/types.ts
+++ b/frontend/src/hooks/api/secretInsights/types.ts
@@ -110,7 +110,7 @@ export type TGetUnusedAccessResponse = {
principals: TUnusedAccessPrincipal[];
totalCount: number;
trackingStartedAt: string;
- unusedAccessFrom: string;
+ fullWindowFrom: string;
remainingTtl: number;
};
@@ -131,7 +131,7 @@ export type TGetUnusedAccessPrincipalResponse = {
secrets: TUnusedSecret[];
unlistedCount: number;
trackingStartedAt: string;
- unusedAccessFrom: string;
+ fullWindowFrom: string;
remainingTtl: number;
};
diff --git a/frontend/src/pages/secret-manager/InsightsPage/components/UnusedAccessCard.tsx b/frontend/src/pages/secret-manager/InsightsPage/components/UnusedAccessCard.tsx
index d3f2901b5b..78caedafc1 100644
--- a/frontend/src/pages/secret-manager/InsightsPage/components/UnusedAccessCard.tsx
+++ b/frontend/src/pages/secret-manager/InsightsPage/components/UnusedAccessCard.tsx
@@ -1,6 +1,5 @@
import { useState } from "react";
import axios from "axios";
-import { format } from "date-fns";
import { ChevronRightIcon, SearchIcon } from "lucide-react";
import { formatReadDay } from "@app/components/secrets/SecretReadStatusBadge";
@@ -32,7 +31,11 @@ import { useProject, useSubscription } from "@app/context";
import { usePagination, useResetPageHelper } from "@app/hooks";
import { TUnusedAccessPrincipal, useGetUnusedAccess } from "@app/hooks/api/secretInsights";
-import { formatRemainingTtl, PRINCIPAL_TYPE_CONFIG } from "./unusedAccessHelpers";
+import {
+ describeReadPeriod,
+ formatRemainingTtl,
+ PRINCIPAL_TYPE_CONFIG
+} from "./unusedAccessHelpers";
import { UnusedAccessPrincipalSheet } from "./UnusedAccessPrincipalSheet";
export const UnusedAccessCard = () => {
@@ -54,8 +57,9 @@ export const UnusedAccessCard = () => {
? formatRemainingTtl(data.remainingTtl)
: null;
const environmentNames = new Map(currentProject.environments.map((env) => [env.slug, env.name]));
- // Nothing is judged until the project has 30 days of reads.
- const isJudging = !data || new Date(data.unusedAccessFrom) <= new Date();
+ const readPeriod = data
+ ? describeReadPeriod(data.trackingStartedAt, data.fullWindowFrom)
+ : "in the last 30 days";
const renderBody = () => {
if (isPending) return <Skeleton className="h-[200px] w-full" />;
@@ -77,12 +81,9 @@ export const UnusedAccessCard = () => {
if (totalCount === 0) {
// Recent access and new secrets are not judged yet, so this cannot claim everything was read.
- let description = "No identity has gone 30 days without reading a secret it can access.";
- if (debouncedSearch) {
- description = "No overprivileged user, group or machine identity matches your search.";
- } else if (!isJudging) {
- description = `Unused access is judged on 30 days of reads, from ${format(new Date(data.unusedAccessFrom), "PP")}.`;
- }
+ const description = debouncedSearch
+ ? "No overprivileged user, group or machine identity matches your search."
+ : `No identity has left a secret it can access unread ${readPeriod}.`;
return (
<Empty className="border">
<EmptyHeader>
@@ -150,7 +151,7 @@ export const UnusedAccessCard = () => {
{row.lastReadAt ? (
formatReadDay(row.lastReadAt)
) : (
- <span className="text-muted">None in 30 days</span>
+ <span className="text-muted">None {readPeriod}</span>
)}
</TableCell>
<TableCell className="max-w-64">
@@ -193,8 +194,8 @@ export const UnusedAccessCard = () => {
)}
</CardTitle>
<CardDescription>
- Users, groups, and machine identities that can read secrets they have not read in the
- last 30 days. Select one to see which secrets.
+ 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">
diff --git a/frontend/src/pages/secret-manager/InsightsPage/components/UnusedAccessPrincipalSheet.tsx b/frontend/src/pages/secret-manager/InsightsPage/components/UnusedAccessPrincipalSheet.tsx
index c8cfd68708..97d635b71e 100644
--- a/frontend/src/pages/secret-manager/InsightsPage/components/UnusedAccessPrincipalSheet.tsx
+++ b/frontend/src/pages/secret-manager/InsightsPage/components/UnusedAccessPrincipalSheet.tsx
@@ -29,7 +29,7 @@ import {
useGetUnusedAccessPrincipal
} from "@app/hooks/api/secretInsights";
-import { PRINCIPAL_TYPE_CONFIG } from "./unusedAccessHelpers";
+import { describeReadPeriod, PRINCIPAL_TYPE_CONFIG } from "./unusedAccessHelpers";
// Rows shown per environment before "N more" opens the rest.
const PREVIEW_ROWS = 5;
@@ -185,8 +185,11 @@ export const UnusedAccessPrincipalSheet = ({ principal, onClose }: Props) => {
</SheetTitle>
<SheetDescription>
Has not read {principal.unreadCount} of the {principal.entitledCount}{" "}
- {principal.entitledCount === 1 ? "secret" : "secrets"} it can access in the last 30
- days.
+ {principal.entitledCount === 1 ? "secret" : "secrets"} it can access{" "}
+ {data
+ ? describeReadPeriod(data.trackingStartedAt, data.fullWindowFrom)
+ : "in the last 30 days"}
+ .
</SheetDescription>
</SheetHeader>
)}
diff --git a/frontend/src/pages/secret-manager/InsightsPage/components/unusedAccessHelpers.ts b/frontend/src/pages/secret-manager/InsightsPage/components/unusedAccessHelpers.ts
index a3a2d1e950..217ab00d88 100644
--- a/frontend/src/pages/secret-manager/InsightsPage/components/unusedAccessHelpers.ts
+++ b/frontend/src/pages/secret-manager/InsightsPage/components/unusedAccessHelpers.ts
@@ -1,3 +1,4 @@
+import { format } from "date-fns";
import { HardDriveIcon, UserIcon, UsersIcon } from "lucide-react";
import { UnusedAccessPrincipalType } from "@app/hooks/api/secretInsights";
@@ -11,6 +12,12 @@ export const PRINCIPAL_TYPE_CONFIG: Record<
[UnusedAccessPrincipalType.Group]: { icon: UsersIcon, label: "Group" }
};
+// The period reads are judged on: the last 30 days once tracking has run that long, else since it began.
+export const describeReadPeriod = (trackingStartedAt: string, fullWindowFrom: string) =>
+ new Date(fullWindowFrom) > 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);
diff --git a/frontend/src/pages/secret-manager/OverviewPage/components/SecretTableRow/SecretAccessInsights.tsx b/frontend/src/pages/secret-manager/OverviewPage/components/SecretTableRow/SecretAccessInsights.tsx
index 260a9598a2..d1a30ed3fd 100644
--- a/frontend/src/pages/secret-manager/OverviewPage/components/SecretTableRow/SecretAccessInsights.tsx
+++ b/frontend/src/pages/secret-manager/OverviewPage/components/SecretTableRow/SecretAccessInsights.tsx
@@ -531,25 +531,18 @@ export function SecretAccessInsights({
"Project admins can read everything by design, so they are not counted as unused access."
};
}
- // judgedFrom is the start of the last 30 days once tracking has run that long, and when it began before.
+ // judgedFrom is the start of the last 30 days, or when tracking began in a project tracked for less.
const judgedFrom = new Date(readActivity.judgedFrom);
- const judgingStartsAt = new Date(judgedFrom.getTime() + 30 * 24 * 60 * 60 * 1000);
- if (judgingStartsAt > new Date()) {
- return {
- kind: "pending",
- reason: `Reads have been tracked since ${format(judgedFrom, "PP")}. Unused access is judged on 30 days of reads, from ${format(judgingStartsAt, "PP")}.`
- };
- }
if (reader?.accessChangedAt && new Date(reader.accessChangedAt) > judgedFrom) {
return {
kind: "pending",
- reason: `Their access changed on ${format(new Date(reader.accessChangedAt), "PP")}, so they have not had 30 days to read it.`
+ reason: `Their access changed on ${format(new Date(reader.accessChangedAt), "PP")}, after reads started being counted on ${format(judgedFrom, "PP")}, so they have not had the whole period to read it.`
};
}
if (new Date(readActivity.trackedSince) > judgedFrom) {
return {
kind: "pending",
- reason: "The secret is newer than 30 days, so nobody has had 30 days to read it."
+ reason: `The secret is newer than ${format(judgedFrom, "PP")}, when reads started being counted, so nobody has had the whole period to read it.`
};
}
return { kind: "pending", reason: "Not counted as unused access." };