Skip to content

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

feat(insights): judge unused access only once a project has 30 days of reads

Dimitris Staratzise7d5411a94cf
diff --git a/backend/CLAUDE.md b/backend/CLAUDE.md
index ee3eb6081d..ef08d7da3b 100644
--- a/backend/CLAUDE.md
+++ b/backend/CLAUDE.md
@@ -1138,16 +1138,17 @@ 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.
-- **The card judges a full window, or everything since tracking began.** It 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 later of the window start and the project's tracking
- start (the later of the migration that created the table and the project's creation). So in a project tracked for
- less 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 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, or "No reads". Each card row also carries three counts for its secret,
+- **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
+ 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),
`unreadCount` (those among them with no read in the window) and
@@ -1156,10 +1157,8 @@ 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. The unused-access term is
- weighted by how much of the 30-day window the reads cover (`trackedDays`, from the project's `judgedFrom`), and
- its label names that period, so a project tracked for three days neither claims "30 days" nor scores three
- days of silence like thirty. 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. 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
(`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 de0ce2171d..7781c00e1d 100644
--- a/backend/src/ee/routes/v1/insights-router.ts
+++ b/backend/src/ee/routes/v1/insights-router.ts
@@ -476,7 +476,7 @@ export const registerInsightsRouter = async (server: FastifyZodProvider) => {
schema: {
operationId: "getInsightsUnusedAccess",
description:
- "List the users, groups and machine identities that can read secrets they have not read in the tracked period, those with the most such secrets first",
+ "List 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",
security: [{ bearerAuth: [] }],
params: z.object({
projectId: z.string().trim().max(36).describe(INSIGHTS.GET_UNUSED_ACCESS.projectId)
@@ -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, preliminaryUntil, remainingTTL, projectName } =
+ const { principals, totalCount, trackingStartedAt, unusedAccessFrom, 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, preliminaryUntil };
+ return { principals, totalCount, trackingStartedAt, unusedAccessFrom };
}
});
@@ -517,8 +517,7 @@ export const registerInsightsRouter = async (server: FastifyZodProvider) => {
config: { rateLimit: readLimit },
schema: {
operationId: "getInsightsUnusedAccessPrincipal",
- description:
- "List the secrets one user, group or machine identity can read but has not read in the tracked period",
+ description: "List the secrets one user, group or machine identity can read but has not read in the last 30 days",
security: [{ bearerAuth: [] }],
params: z.object({
projectId: z.string().trim().max(36).describe(INSIGHTS.GET_UNUSED_ACCESS_PRINCIPAL.projectId),
@@ -534,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, preliminaryUntil, remainingTTL, projectName } =
+ const { principal, secrets, unlistedCount, trackingStartedAt, unusedAccessFrom, remainingTTL, projectName } =
await server.services.secretReadActivity.getUnusedAccessPrincipal(
{ projectId, principalType, principalId },
req.permission
@@ -551,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, preliminaryUntil };
+ return { principal, secrets, unlistedCount, trackingStartedAt, unusedAccessFrom };
}
});
diff --git a/backend/src/ee/services/insights/insights-schemas.ts b/backend/src/ee/services/insights/insights-schemas.ts
index 3891a08009..b5f13d29a3 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),
- preliminaryUntil: z.date().describe(INSIGHTS.GET_UNUSED_ACCESS.preliminaryUntil),
+ unusedAccessFrom: z.date().describe(INSIGHTS.GET_UNUSED_ACCESS.unusedAccessFrom),
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),
- preliminaryUntil: z.date().describe(INSIGHTS.GET_UNUSED_ACCESS.preliminaryUntil),
+ unusedAccessFrom: z.date().describe(INSIGHTS.GET_UNUSED_ACCESS.unusedAccessFrom),
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-fns.test.ts b/backend/src/ee/services/secret-read-activity/secret-read-activity-fns.test.ts
index 9f20fb6fca..bdf60aaa96 100644
--- a/backend/src/ee/services/secret-read-activity/secret-read-activity-fns.test.ts
+++ b/backend/src/ee/services/secret-read-activity/secret-read-activity-fns.test.ts
@@ -189,33 +189,4 @@ describe("calculateExposureScore", () => {
"1 ghost reader can no longer read it but still knows the value"
]);
});
-
- test("weights unused access by how much of the window the reads cover, and says so", () => {
- const counts = { entitledCount: 4, unreadCount: 4, ghostReaderCount: 0 };
- const fullWindow = calculateExposureScore(counts);
- const threeDays = calculateExposureScore(counts, 3);
- const firstDay = calculateExposureScore(counts, 0.9);
- const unusedPoints = (exposure: ReturnType<typeof calculateExposureScore>) =>
- exposure.drivers.find((driver) => driver.kind === SecretExposureDriver.UnusedAccess)?.points ?? 0;
-
- expect(unusedPoints(fullWindow)).toBe(25);
- expect(unusedPoints(threeDays)).toBeLessThan(unusedPoints(fullWindow));
- expect(unusedPoints(firstDay)).toBeLessThan(unusedPoints(threeDays));
- expect(threeDays.drivers.map((driver) => driver.label)).toContain("4 of 4 have not read it in the 3 days tracked");
- expect(calculateExposureScore(counts, 1).drivers.map((driver) => driver.label)).toContain(
- "4 of 4 have not read it in the 1 day tracked"
- );
- expect(firstDay.drivers.map((driver) => driver.label)).toContain(
- "4 of 4 have not read it since tracking began today"
- );
- expect(calculateExposureScore(counts, 45).drivers.map((driver) => driver.label)).toContain(
- "4 of 4 have not read it in 30 days"
- );
- });
-
- test("drops the unused-access driver when the tracked period is too short to give it a point", () => {
- const exposure = calculateExposureScore({ entitledCount: 1, unreadCount: 1, ghostReaderCount: 0 }, 0.4);
- expect(exposure.drivers.map((driver) => driver.kind)).toEqual([SecretExposureDriver.Readers]);
- expect(pointsOf(exposure)).toBe(exposure.score);
- });
});
diff --git a/backend/src/ee/services/secret-read-activity/secret-read-activity-fns.ts b/backend/src/ee/services/secret-read-activity/secret-read-activity-fns.ts
index 563282c54a..cb0d3f1fd5 100644
--- a/backend/src/ee/services/secret-read-activity/secret-read-activity-fns.ts
+++ b/backend/src/ee/services/secret-read-activity/secret-read-activity-fns.ts
@@ -141,23 +141,12 @@ const pluralize = (count: number, singular: string, plural: string) => `${count}
// A score from 0 to 100 built from the three facts read activity gives: how many can read the value, how many
// who no longer can still know it, and how many of those who can never do. The weights follow the blast radius
-// prototype's proportions for the same three terms, rescaled to add up to 100. `trackedDays` is how much of
-// the window the reads cover: the unused-access term is weighted by it, since three days without a read is
-// weak evidence next to thirty, and its label says which period it is judged on.
-export const calculateExposureScore = (
- { entitledCount, unreadCount, ghostReaderCount }: TSecretExposureCounts,
- trackedDays = SECRET_READ_ACTIVITY_WINDOW_DAYS
-): TSecretExposure => {
- const coverage = clamp01(trackedDays / SECRET_READ_ACTIVITY_WINDOW_DAYS);
- const trackedWholeDays = Math.floor(Math.min(trackedDays, SECRET_READ_ACTIVITY_WINDOW_DAYS));
- let period = `in ${SECRET_READ_ACTIVITY_WINDOW_DAYS} days`;
- if (coverage < 1) {
- period =
- trackedWholeDays < 1
- ? "since tracking began today"
- : `in the ${pluralize(trackedWholeDays, "day", "days")} tracked`;
- }
-
+// prototype's proportions for the same three terms, rescaled to add up to 100.
+export const calculateExposureScore = ({
+ entitledCount,
+ unreadCount,
+ ghostReaderCount
+}: TSecretExposureCounts): TSecretExposure => {
const terms = [
{
kind: SecretExposureDriver.Readers,
@@ -173,8 +162,8 @@ export const calculateExposureScore = (
},
{
kind: SecretExposureDriver.UnusedAccess,
- points: 25 * coverage * (entitledCount ? unreadCount / entitledCount : 0),
- label: `${unreadCount} of ${entitledCount} ${unreadCount === 1 ? "has" : "have"} not read it ${period}`
+ points: 25 * (entitledCount ? unreadCount / entitledCount : 0),
+ label: `${unreadCount} of ${entitledCount} ${unreadCount === 1 ? "has" : "have"} not read it in ${SECRET_READ_ACTIVITY_WINDOW_DAYS} days`
}
];
const score = Math.round(terms.reduce((total, term) => total + term.points, 0));
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 4b24bf8015..159bfc459c 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,8 +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. In a project tracked for less than the window, the window starts when tracking did, so the
- // results are preliminary.
+ // members read it. Nothing is judged until the project has a full window of reads.
const $loadSecretSummarizer = async (projectId: string, orgId: string, windowStart: Date) => {
const [
{ userPermissions, identityPermissions, groupPermissions },
@@ -310,8 +309,9 @@ export const secretReadActivityServiceFactory = ({
]);
const groupPermissionById = new Map(groupPermissions.map((group) => [group.id, group.permission]));
const judgedFrom = trackingStartedAt > windowStart ? trackingStartedAt : windowStart;
- // How much of the window the reads cover, which weights the score's unused-access term and words it.
- const trackedDays = (Date.now() - judgedFrom.getTime()) / DAY_IN_MS;
+ // 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;
@@ -376,6 +376,7 @@ 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)
);
@@ -385,6 +386,7 @@ 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)
);
@@ -395,10 +397,11 @@ export const secretReadActivityServiceFactory = ({
ghostReaders,
entitledGroups,
unreadGroups,
- exposure: calculateExposureScore(
- { entitledCount: exposedTo.length, unreadCount: unread.length, ghostReaderCount: ghostReaders.length },
- trackedDays
- )
+ exposure: calculateExposureScore({
+ entitledCount: exposedTo.length,
+ unreadCount: unread.length,
+ ghostReaderCount: ghostReaders.length
+ })
};
};
return {
@@ -408,7 +411,6 @@ export const secretReadActivityServiceFactory = ({
userPermissions,
identityPermissions,
judgedFrom,
- trackedDays,
accessChangedAtByActorId,
adminActorIds
};
@@ -726,7 +728,7 @@ export const secretReadActivityServiceFactory = ({
remainingTTL,
projectName: project?.name ?? "",
trackingStartedAt,
- preliminaryUntil: new Date(trackingStartedAt.getTime() + SECRET_READ_ACTIVITY_WINDOW_DAYS * DAY_IN_MS)
+ unusedAccessFrom: new Date(trackingStartedAt.getTime() + SECRET_READ_ACTIVITY_WINDOW_DAYS * DAY_IN_MS)
};
};
@@ -772,7 +774,7 @@ export const secretReadActivityServiceFactory = ({
totalCount: matching.length,
projectName: tracking.projectName,
trackingStartedAt: tracking.trackingStartedAt,
- preliminaryUntil: tracking.preliminaryUntil,
+ unusedAccessFrom: tracking.unusedAccessFrom,
remainingTTL: tracking.remainingTTL
};
};
@@ -833,7 +835,7 @@ export const secretReadActivityServiceFactory = ({
unlistedCount: Math.max(0, principal.unreadCount - secretIds.length),
projectName: tracking.projectName,
trackingStartedAt: tracking.trackingStartedAt,
- preliminaryUntil: tracking.preliminaryUntil,
+ unusedAccessFrom: tracking.unusedAccessFrom,
remainingTTL: tracking.remainingTTL
};
};
diff --git a/backend/src/lib/api-docs/constants.ts b/backend/src/lib/api-docs/constants.ts
index 84cf37078e..c7689c69d8 100644
--- a/backend/src/lib/api-docs/constants.ts
+++ b/backend/src/lib/api-docs/constants.ts
@@ -953,30 +953,30 @@ 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 tracked period, 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, 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.",
memberCount: "How many users and machine identities the group has. Null for a user or machine identity.",
entitledCount: "How many secrets the principal can read the value of today.",
unreadCount:
- "How many of those it has not read, or an import or reference of, in the tracked period. A group has not read a secret when none of its members have. Secrets and access newer than the period are not counted.",
+ "How many of those it has not read, or an import or reference of, in the last 30 days. A group has not read a secret when none of its members have. Secrets and access newer than 30 days are not counted.",
environments: "The slugs of the environments holding the unread secrets.",
lastReadAt:
- "When the principal last read any secret in the project within the tracked period, as the first read of that day; a group's is its members' latest. Null when it read nothing.",
+ "When the principal last read any secret in the project in the last 30 days, as the first read of that day; a group's is its members' latest. Null when it read nothing.",
accessVia: "How the principal has the access: its roles, additional privileges, and the groups it belongs to.",
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.",
- preliminaryUntil:
- "When the results first cover the full 30 days. Until then they are preliminary: they cover only the reads since tracking started, and the access that existed when it started."
+ 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."
},
GET_UNUSED_ACCESS_PRINCIPAL: {
projectId: "The ID of the project.",
principalType: "Whether the principal is a user, a group or a machine identity.",
principalId: "The ID of the user, group or machine identity.",
secrets:
- "The secrets the principal can read but has not read in the tracked period, among those the caller can see, ordered by environment and path.",
+ "The secrets the principal can read but has not read in the last 30 days, among those the caller can see, ordered by environment and path.",
secretKey: "The key of the secret.",
environment: "The slug of the environment the secret is in.",
secretPath: "The path of the folder the secret is in.",
@@ -1418,7 +1418,7 @@ export const SECRET_EXPOSURE = {
driverLabel: "The term in words, with its counts.",
entitledCount:
"How many users and machine identities can read this secret's value today. Project admins are left out: they can read everything by design, so the secret is not exposed to them.",
- unreadCount: "How many of those have not read it in the tracked period, up to the last 30 days.",
+ unreadCount: "How many of those have not read it in the last 30 days.",
ghostReaderCount:
"How many users and machine identities read this secret in the last 30 days but can no longer read it today, for example after leaving the project. They still know the value."
};
@@ -1515,7 +1515,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. A reader only counts as unused access once the secret and their access both predate 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. Nobody counts as unused access until it is 30 days ago, and then only readers whose access, like the secret, predates 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/components/secrets/SecretExposureScore.tsx b/frontend/src/components/secrets/SecretExposureScore.tsx
index 0a912d5247..22066bd673 100644
--- a/frontend/src/components/secrets/SecretExposureScore.tsx
+++ b/frontend/src/components/secrets/SecretExposureScore.tsx
@@ -137,8 +137,7 @@ export const SecretExposurePanel = ({ exposure, className }: PanelProps) => {
)}
<p className="text-xs text-muted">
Up to 45 points for how many can read the value (project admins aside), 30 for ghost
- readers who still know it, and 25 for the share who have not read it in the tracked
- period, which counts in full once that period is 30 days.
+ readers who still know it, and 25 for the share who have not read it in the last 30 days.
</p>
</div>
</div>
diff --git a/frontend/src/components/secrets/SecretReadStatusBadge.tsx b/frontend/src/components/secrets/SecretReadStatusBadge.tsx
index ff621aaa5d..7be83b2ef4 100644
--- a/frontend/src/components/secrets/SecretReadStatusBadge.tsx
+++ b/frontend/src/components/secrets/SecretReadStatusBadge.tsx
@@ -32,8 +32,7 @@ export const SecretReadStatusBadge = ({ status }: Props) => {
<Badge variant="warning">No Reads</Badge>
</TooltipTrigger>
<TooltipContent className="max-w-72">
- No reads since {format(new Date(status.since), "PP")}, when reads of this secret started
- being tracked. Nothing is known about reads before that.
+ No reads since {format(new Date(status.since), "PP")}
</TooltipContent>
</Tooltip>
);
diff --git a/frontend/src/hooks/api/secretInsights/types.ts b/frontend/src/hooks/api/secretInsights/types.ts
index 597f84325b..91c59d52a6 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;
- preliminaryUntil: string;
+ unusedAccessFrom: string;
remainingTtl: number;
};
@@ -131,7 +131,7 @@ export type TGetUnusedAccessPrincipalResponse = {
secrets: TUnusedSecret[];
unlistedCount: number;
trackingStartedAt: string;
- preliminaryUntil: string;
+ unusedAccessFrom: 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 2d0f5d46b2..2f595298cf 100644
--- a/frontend/src/pages/secret-manager/InsightsPage/components/UnusedAccessCard.tsx
+++ b/frontend/src/pages/secret-manager/InsightsPage/components/UnusedAccessCard.tsx
@@ -1,7 +1,7 @@
import { useState } from "react";
import axios from "axios";
import { format } from "date-fns";
-import { ChevronRightIcon, InfoIcon, SearchIcon } from "lucide-react";
+import { ChevronRightIcon, SearchIcon } from "lucide-react";
import { formatReadDay } from "@app/components/secrets/SecretReadStatusBadge";
import {
@@ -31,11 +31,7 @@ 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 { formatRemainingTtl, PRINCIPAL_TYPE_CONFIG } from "./unusedAccessHelpers";
import { UnusedAccessPrincipalSheet } from "./UnusedAccessPrincipalSheet";
export const UnusedAccessCard = () => {
@@ -57,10 +53,8 @@ export const UnusedAccessCard = () => {
? 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());
+ // Nothing is judged until the project has 30 days of reads.
+ const isJudging = !data || new Date(data.unusedAccessFrom) <= new Date();
const renderBody = () => {
if (isPending) return <Skeleton className="h-[200px] w-full" />;
@@ -81,17 +75,19 @@ export const UnusedAccessCard = () => {
}
if (totalCount === 0) {
+ let description = "Every identity has read the secrets it can access in the last 30 days.";
+ if (debouncedSearch) {
+ description = "No user, group or machine identity with unused access matches your search.";
+ } else if (!isJudging) {
+ description = `Unused access is judged on 30 days of reads, from ${format(new Date(data.unusedAccessFrom), "PP")}.`;
+ }
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>
+ <EmptyDescription>{description}</EmptyDescription>
</EmptyHeader>
</Empty>
);
@@ -152,7 +148,7 @@ export const UnusedAccessCard = () => {
{row.lastReadAt ? (
formatReadDay(row.lastReadAt)
) : (
- <span className="text-muted">None {readPeriod}</span>
+ <span className="text-muted">None in 30 days</span>
)}
</TableCell>
<TableCell isTruncatable className="max-w-56">
@@ -190,19 +186,11 @@ export const UnusedAccessCard = () => {
)}
</CardTitle>
<CardDescription>
- Users, groups, and machine identities that can read secrets they have not read{" "}
- {readPeriod}. Select one to see which secrets.
+ Users, groups, and machine identities that can read secrets they have not read in the
+ last 30 days. 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 />
diff --git a/frontend/src/pages/secret-manager/InsightsPage/components/UnusedAccessPrincipalSheet.tsx b/frontend/src/pages/secret-manager/InsightsPage/components/UnusedAccessPrincipalSheet.tsx
index c08ab98860..f32df4b8f4 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 { describeReadPeriod, PRINCIPAL_TYPE_CONFIG } from "./unusedAccessHelpers";
+import { PRINCIPAL_TYPE_CONFIG } from "./unusedAccessHelpers";
// Rows shown per environment before "N more" opens the rest.
const PREVIEW_ROWS = 5;
@@ -166,10 +166,6 @@ export const UnusedAccessPrincipalSheet = ({ principal, onClose }: Props) => {
);
};
- const readPeriod = data
- ? describeReadPeriod(data.trackingStartedAt, data.preliminaryUntil)
- : "in the last 30 days";
-
return (
<Sheet
open={principal !== null}
@@ -188,7 +184,8 @@ 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 {readPeriod}.
+ {principal.entitledCount === 1 ? "secret" : "secrets"} it can access 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 2079283df6..a3a2d1e950 100644
--- a/frontend/src/pages/secret-manager/InsightsPage/components/unusedAccessHelpers.ts
+++ b/frontend/src/pages/secret-manager/InsightsPage/components/unusedAccessHelpers.ts
@@ -1,4 +1,3 @@
-import { format } from "date-fns";
import { HardDriveIcon, UserIcon, UsersIcon } from "lucide-react";
import { UnusedAccessPrincipalType } from "@app/hooks/api/secretInsights";
@@ -12,12 +11,6 @@ export const PRINCIPAL_TYPE_CONFIG: Record<
[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);
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 c87a073b09..3656e26c02 100644
--- a/frontend/src/pages/secret-manager/OverviewPage/components/SecretTableRow/SecretAccessInsights.tsx
+++ b/frontend/src/pages/secret-manager/OverviewPage/components/SecretTableRow/SecretAccessInsights.tsx
@@ -532,17 +532,25 @@ 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.
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 the whole tracked period to read it.`
+ reason: `Their access changed on ${format(new Date(reader.accessChangedAt), "PP")}, so they have not had 30 days to read it.`
};
}
if (new Date(readActivity.trackedSince) > judgedFrom) {
return {
kind: "pending",
- reason: `The secret has only been tracked since ${format(new Date(readActivity.trackedSince), "PP")}, so nobody has had the whole period to read it.`
+ reason: "The secret is newer than 30 days, so nobody has had 30 days to read it."
};
}
return { kind: "pending", reason: "Not counted as unused access." };