Skip to content

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

feat: define a cache TTL of 15 minutes to the org insights endpoints

adilson3e9105d0182d
diff --git a/backend/src/ee/services/audit-report/audit-report-org-generators.ts b/backend/src/ee/services/audit-report/audit-report-org-generators.ts
index 6c6d16d2b0..d43e8d21b4 100644
--- a/backend/src/ee/services/audit-report/audit-report-org-generators.ts
+++ b/backend/src/ee/services/audit-report/audit-report-org-generators.ts
@@ -84,18 +84,23 @@ const needsAttentionReport: TOrgReportDefinition = {
const projectsWithIssues: TSecretsProjectWarning[] = [];
// One page beyond the row cap so a full-capacity result can still be detected as truncated.
- const maxPages = Math.ceil(MAX_AUDIT_REPORT_ROWS / NEEDS_ATTENTION_PAGE_SIZE) + 1;
+ const rowCapPages = Math.ceil(MAX_AUDIT_REPORT_ROWS / NEEDS_ATTENTION_PAGE_SIZE) + 1;
+ let maxPages = rowCapPages;
// The DAL orders by severityScore desc, so the first zero-severity project marks the end of the
// projects with outstanding issues — everything after it is clean and stays out of the report.
for (let page = 0; page < maxPages; page += 1) {
// eslint-disable-next-line no-await-in-loop
- const { projects } = await dal.insightsDAL.findProjectWarningsForOrg(orgId, {
+ const { projects, projectsWithIssues: issueCount } = await dal.insightsDAL.findProjectWarningsForOrg(orgId, {
offset: page * NEEDS_ATTENTION_PAGE_SIZE,
limit: NEEDS_ATTENTION_PAGE_SIZE,
staleBefore
});
+ if (page === 0) {
+ maxPages = Math.min(rowCapPages, Math.max(1, Math.ceil(issueCount / NEEDS_ATTENTION_PAGE_SIZE)));
+ }
+
const firstCleanIndex = projects.findIndex((project) => project.severityScore === 0);
projectsWithIssues.push(...(firstCleanIndex === -1 ? projects : projects.slice(0, firstCleanIndex)));
diff --git a/backend/src/ee/services/insights/insights-service.ts b/backend/src/ee/services/insights/insights-service.ts
index f357732e59..eae08f340b 100644
--- a/backend/src/ee/services/insights/insights-service.ts
+++ b/backend/src/ee/services/insights/insights-service.ts
@@ -604,7 +604,7 @@ export const insightsServiceFactory = ({
return withCache({
keyStore,
key: cacheKey,
- ttlSeconds: KeyStoreTtls.InsightsCacheInSeconds,
+ ttlSeconds: KeyStoreTtls.InsightsOrgCacheInSeconds,
fetcher: async () => {
const staleBefore = new Date();
staleBefore.setDate(staleBefore.getDate() - STALE_SECRET_THRESHOLD_DAYS);
@@ -632,7 +632,7 @@ export const insightsServiceFactory = ({
return withCache({
keyStore,
key: cacheKey,
- ttlSeconds: KeyStoreTtls.InsightsCacheInSeconds,
+ ttlSeconds: KeyStoreTtls.InsightsOrgCacheInSeconds,
fetcher: async () => {
const { dates, startDate, endDate } = buildAccessVolumeWindow();
@@ -665,7 +665,7 @@ export const insightsServiceFactory = ({
return withCache({
keyStore,
key: cacheKey,
- ttlSeconds: KeyStoreTtls.InsightsCacheInSeconds,
+ ttlSeconds: KeyStoreTtls.InsightsOrgCacheInSeconds,
fetcher: async () => {
const { startDate, endDate } = buildAccessVolumeWindow();
@@ -711,7 +711,7 @@ export const insightsServiceFactory = ({
return withCache({
keyStore,
key: cacheKey,
- ttlSeconds: KeyStoreTtls.InsightsCacheInSeconds,
+ ttlSeconds: KeyStoreTtls.InsightsOrgCacheInSeconds,
fetcher: () => insightsDAL.countOrgSecretsResources(dto.orgId)
});
};
@@ -743,7 +743,7 @@ export const insightsServiceFactory = ({
withCache({
keyStore,
key: KeyStorePrefixes.InsightsCache(dto.orgId, `static-secret-usage:current-week:${currentWeekStartStr}`),
- ttlSeconds: KeyStoreTtls.InsightsCacheInSeconds,
+ ttlSeconds: KeyStoreTtls.InsightsOrgCacheInSeconds,
fetcher: () => insightsDAL.countSecretCreationsForOrg(dto.orgId, { createdAtOrAfter: currentWeekStart })
})
]);
diff --git a/backend/src/keystore/keystore.ts b/backend/src/keystore/keystore.ts
index bce710e038..eaf4e4e1ce 100644
--- a/backend/src/keystore/keystore.ts
+++ b/backend/src/keystore/keystore.ts
@@ -198,9 +198,10 @@ export const KeyStoreTtls = {
RefreshTokenGraceInSeconds: 10,
EmailSignupOtpInSeconds: 300, // 5 minutes
EmailSignupResendCooldownInSeconds: 60, // 1 minute
- InsightsCacheInSeconds: 60, // 5 minutes
- InsightsDuplicationCacheInSeconds: 60, // 1 hour
- InsightsWeeklyHistoryCacheInSeconds: 60, // 24 hours
+ InsightsCacheInSeconds: 300, // 5 minutes
+ InsightsDuplicationCacheInSeconds: 3600, // 1 hour
+ InsightsWeeklyHistoryCacheInSeconds: 86400, // 24 hours
+ InsightsOrgCacheInSeconds: 900, // 15 minutes
AdminConfigInSeconds: 60,
UpdateCheckLatestVersionInSeconds: 1209600, // 14 days (survives one missed weekly check)
InvalidatingCacheInSeconds: 1800, // 30 minutes max lock for cache invalidation job
diff --git a/frontend/src/hooks/api/auditLogs/constants.tsx b/frontend/src/hooks/api/auditLogs/constants.tsx
index 117df1f9aa..603a4cf9a3 100644
--- a/frontend/src/hooks/api/auditLogs/constants.tsx
+++ b/frontend/src/hooks/api/auditLogs/constants.tsx
@@ -284,6 +284,12 @@ 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_ORG_ACCESS_VOLUME]:
+ "View Organization Secrets Management Access Volume Insights",
+ [EventType.VIEW_INSIGHTS_SECRETS_MANAGEMENT_ORG_AUTH_METHOD_DISTRIBUTION]:
+ "View Organization Secrets Management Auth Method Distribution Insights",
+ [EventType.VIEW_INSIGHTS_SECRETS_MANAGEMENT_STATIC_SECRET_USAGE]:
+ "View Organization Static Secret Usage Insights",
[EventType.VIEW_INSIGHTS_SECRETS_MANAGEMENT_ACCESS_LOCATIONS]:
"View Secrets Management Access Locations Insights",
[EventType.VIEW_INSIGHTS_AUTH_METHODS]: "View Machine Identity Auth Methods Insights",
@@ -294,6 +300,12 @@ export const eventToNameMap: { [K in EventType]: string } = {
[EventType.VIEW_INSIGHTS_SECRETS_MANAGEMENT_USAGE]: "View Secrets Management Usage Insights",
[EventType.VIEW_INSIGHTS_SECRETS_MANAGEMENT_PROJECT_WARNINGS]:
"View Secrets Management Project Warnings Insights",
+ [EventType.VIEW_INSIGHTS_SECRETS_MANAGEMENT_ORG_COUNTS]:
+ "View Organization Secrets Management Resource Counts Insights",
+
+ [EventType.CREATE_ORG_AUDIT_REPORT]: "Create Organization Audit Report",
+ [EventType.GET_ORG_AUDIT_REPORTS]: "List Organization Audit Reports",
+ [EventType.DELETE_ORG_AUDIT_REPORT]: "Delete Organization Audit Report",
[EventType.CREATE_PROJECT_ROLE]: "Create Project Role",
[EventType.UPDATE_PROJECT_ROLE]: "Update Project Role",
diff --git a/frontend/src/hooks/api/auditLogs/enums.tsx b/frontend/src/hooks/api/auditLogs/enums.tsx
index 7912c807a1..58f1840256 100644
--- a/frontend/src/hooks/api/auditLogs/enums.tsx
+++ b/frontend/src/hooks/api/auditLogs/enums.tsx
@@ -277,6 +277,9 @@ 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_ORG_ACCESS_VOLUME = "view-insights-secrets-management-org-access-volume",
+ VIEW_INSIGHTS_SECRETS_MANAGEMENT_ORG_AUTH_METHOD_DISTRIBUTION = "view-insights-secrets-management-org-auth-method-distribution",
+ VIEW_INSIGHTS_SECRETS_MANAGEMENT_STATIC_SECRET_USAGE = "view-insights-secrets-management-static-secret-usage",
VIEW_INSIGHTS_SECRETS_MANAGEMENT_ACCESS_LOCATIONS = "view-insights-secrets-management-access-locations",
VIEW_INSIGHTS_SECRETS_MANAGEMENT_SUMMARY = "view-insights-secrets-management-summary",
VIEW_INSIGHTS_AUTH_METHODS = "view-insights-auth-methods",
@@ -284,6 +287,11 @@ export enum EventType {
VIEW_INSIGHTS_SECRETS_MANAGEMENT_COUNTS = "view-insights-secrets-management-counts",
VIEW_INSIGHTS_SECRETS_MANAGEMENT_USAGE = "view-insights-secrets-management-usage",
VIEW_INSIGHTS_SECRETS_MANAGEMENT_PROJECT_WARNINGS = "view-insights-secrets-management-project-warnings",
+ VIEW_INSIGHTS_SECRETS_MANAGEMENT_ORG_COUNTS = "view-insights-secrets-management-org-counts",
+
+ CREATE_ORG_AUDIT_REPORT = "create-org-audit-report",
+ GET_ORG_AUDIT_REPORTS = "get-org-audit-reports",
+ DELETE_ORG_AUDIT_REPORT = "delete-org-audit-report",
CREATE_PROJECT_ROLE = "create-project-role",
UPDATE_PROJECT_ROLE = "update-project-role",
diff --git a/frontend/src/pages/organization/SecretInsightsPage/SecretInsightsPage.tsx b/frontend/src/pages/organization/SecretInsightsPage/SecretInsightsPage.tsx
index ca67120d56..7bf61d50d9 100644
--- a/frontend/src/pages/organization/SecretInsightsPage/SecretInsightsPage.tsx
+++ b/frontend/src/pages/organization/SecretInsightsPage/SecretInsightsPage.tsx
@@ -47,6 +47,7 @@ export const SecretInsightsPage = withPermission(
const { data: summary, isPending: isSummaryPending } = useGetOrgSecretsSummary(currentOrg.id);
// limit 100 is the endpoint maximum; orgs with more projects need real pagination later
+ // TODO: add pagination
const { data: projectsInsights, isPending: isProjectsPending } = useGetOrgSecretsProjects(
currentOrg.id,
{ limit: 100 }
diff --git a/frontend/src/pages/organization/SecretInsightsPage/components/RequestOrgAuditReportModal.tsx b/frontend/src/pages/organization/SecretInsightsPage/components/RequestOrgAuditReportModal.tsx
index e071d9ab16..af716fb988 100644
--- a/frontend/src/pages/organization/SecretInsightsPage/components/RequestOrgAuditReportModal.tsx
+++ b/frontend/src/pages/organization/SecretInsightsPage/components/RequestOrgAuditReportModal.tsx
@@ -83,10 +83,17 @@ export const RequestOrgAuditReportModal = ({
const onSubmit = async (data: TFormSchema) => {
const recipients = parseEmails(data.emailRecipients);
- await requestOrgAuditReport.mutateAsync({
- reports: data.reportTypes.map((type) => ({ type })),
- emailRecipients: recipients.length ? recipients : undefined
- });
+ try {
+ await requestOrgAuditReport.mutateAsync({
+ reports: data.reportTypes.map((type) => ({ type })),
+ emailRecipients: recipients.length ? recipients : undefined
+ });
+ } catch {
+ // The global MutationCache.onError already surfaces the server message (a report is
+ // already generating, the plan does not include it, audit logs are not enabled). Keep the
+ // modal open with the selection intact so the user can retry, and do not toast twice.
+ return;
+ }
createNotification({
type: "success",
text: "Report requested. Recipients will receive an email once it's ready."
diff --git a/frontend/src/pages/organization/SecretInsightsPage/components/StaticSecretPresenceCard.tsx b/frontend/src/pages/organization/SecretInsightsPage/components/StaticSecretPresenceCard.tsx
index 2c2eeb2a04..9aa1b1ca2a 100644
--- a/frontend/src/pages/organization/SecretInsightsPage/components/StaticSecretPresenceCard.tsx
+++ b/frontend/src/pages/organization/SecretInsightsPage/components/StaticSecretPresenceCard.tsx
@@ -39,8 +39,9 @@ type WeekPoint = {
};
const getCreationTrend = (weeks: TOrgStaticSecretUsage["weeks"]): TrendBadge | null => {
- if (weeks.length < 3) return null;
- const [a, b, c] = weeks.slice(-3).map((week) => week.totalSecrets);
+ const completeWeeks = weeks.filter((week) => !week.isPartial);
+ if (completeWeeks.length < 3) return null;
+ const [a, b, c] = completeWeeks.slice(-3).map((week) => week.totalSecrets);
if (a < b && b < c) return { label: "Increasing", variant: "warning" };
if (a > b && b > c) return { label: "Decreasing", variant: "success" };
return { label: "Steady", variant: "neutral" };