Skip to content

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

improvements: address feedback

Scott Wilson489ec817afab
diff --git a/backend/package.json b/backend/package.json
index f4ee1977b6..06caa52424 100644
--- a/backend/package.json
+++ b/backend/package.json
@@ -159,6 +159,7 @@
"@fastify/websocket": "^10.0.1",
"@gitbeaker/rest": "^42.5.0",
"@google-cloud/kms": "^4.5.0",
+ "@infisical/ldapjs": "3.0.11",
"@infisical/pg-view-generator": "^1.1.0",
"@infisical/quic": "^1.0.8",
"@modelcontextprotocol/sdk": "^1.24.3",
@@ -224,7 +225,6 @@
"jsrp": "^0.2.4",
"jwks-rsa": "^3.1.0",
"knex": "^3.0.1",
- "@infisical/ldapjs": "3.0.11",
"ldif": "0.5.1",
"libsodium-wrappers": "^0.7.13",
"lodash.isequal": "^4.5.0",
diff --git a/backend/src/ee/services/audit-log/audit-log-dal.ts b/backend/src/ee/services/audit-log/audit-log-dal.ts
index b2204553e4..41e66c6bbf 100644
--- a/backend/src/ee/services/audit-log/audit-log-dal.ts
+++ b/backend/src/ee/services/audit-log/audit-log-dal.ts
@@ -13,6 +13,14 @@ import { ActorType } from "@app/services/auth/auth-type";
import { ACTOR_TYPE_TO_METADATA_ID_KEY, EventType, filterableSecretEvents } from "./audit-log-types";
+type TAggregateQuery = {
+ orgId: string;
+ projectId: string;
+ eventTypes: EventType[];
+ startDate: string;
+ endDate: string;
+};
+
export interface TAuditLogDALFactory extends Omit<TOrmify<TableName.AuditLog>, "find"> {
pruneAuditLog: () => Promise<void>;
find: (
@@ -26,6 +34,18 @@ export interface TAuditLogDALFactory extends Omit<TOrmify<TableName.AuditLog>, "
},
tx?: knex.Knex
) => Promise<TAuditLogs[]>;
+ countByDateAndActor: (
+ arg: TAggregateQuery,
+ tx?: knex.Knex
+ ) => Promise<{ date: string; actor: string; actorMetadata: unknown; count: number }[]>;
+ countByIpAddress: (
+ arg: TAggregateQuery,
+ tx?: knex.Knex
+ ) => Promise<{ ipAddress: string; count: number }[]>;
+ countByAuthMethod: (
+ arg: TAggregateQuery,
+ tx?: knex.Knex
+ ) => Promise<{ actor: string; actorMetadata: unknown; count: number }[]>;
}
type TFindQuery = {
@@ -217,5 +237,102 @@ export const auditLogDALFactory = (db: TDbClient) => {
return auditLogOrm.create(tx);
};
- return { ...auditLogOrm, create, pruneAuditLog, find };
+ const countByDateAndActor = async (
+ {
+ orgId,
+ projectId,
+ eventTypes,
+ startDate,
+ endDate
+ }: {
+ orgId: string;
+ projectId: string;
+ eventTypes: EventType[];
+ startDate: string;
+ endDate: string;
+ },
+ tx?: knex.Knex
+ ) => {
+ const rows = await (tx || db.replicaNode())(TableName.AuditLog)
+ .where(`${TableName.AuditLog}.orgId`, orgId)
+ .where(`${TableName.AuditLog}.projectId`, projectId)
+ .whereIn(`${TableName.AuditLog}.eventType`, eventTypes)
+ .whereRaw(`"${TableName.AuditLog}"."createdAt" >= ?::timestamptz`, [startDate])
+ .whereRaw(`"${TableName.AuditLog}"."createdAt" < ?::timestamptz`, [endDate])
+ .select(
+ db.raw(`DATE("${TableName.AuditLog}"."createdAt") as date`),
+ `${TableName.AuditLog}.actor`,
+ `${TableName.AuditLog}.actorMetadata`
+ )
+ .groupByRaw(
+ `DATE("${TableName.AuditLog}"."createdAt"), "${TableName.AuditLog}"."actor", "${TableName.AuditLog}"."actorMetadata"`
+ )
+ .select(db.raw("COUNT(*)::int as count"))
+ .timeout(1000 * 120);
+
+ return rows as { date: string; actor: string; actorMetadata: unknown; count: number }[];
+ };
+
+ const countByIpAddress = async (
+ {
+ orgId,
+ projectId,
+ eventTypes,
+ startDate,
+ endDate
+ }: {
+ orgId: string;
+ projectId: string;
+ eventTypes: EventType[];
+ startDate: string;
+ endDate: string;
+ },
+ tx?: knex.Knex
+ ) => {
+ const rows = await (tx || db.replicaNode())(TableName.AuditLog)
+ .where(`${TableName.AuditLog}.orgId`, orgId)
+ .where(`${TableName.AuditLog}.projectId`, projectId)
+ .whereIn(`${TableName.AuditLog}.eventType`, eventTypes)
+ .whereRaw(`"${TableName.AuditLog}"."createdAt" >= ?::timestamptz`, [startDate])
+ .whereRaw(`"${TableName.AuditLog}"."createdAt" < ?::timestamptz`, [endDate])
+ .whereNotNull(`${TableName.AuditLog}.ipAddress`)
+ .select(`${TableName.AuditLog}.ipAddress`)
+ .groupBy(`${TableName.AuditLog}.ipAddress`)
+ .select(db.raw("COUNT(*)::int as count"))
+ .timeout(1000 * 120);
+
+ return rows as { ipAddress: string; count: number }[];
+ };
+
+ const countByAuthMethod = async (
+ {
+ orgId,
+ projectId,
+ eventTypes,
+ startDate,
+ endDate
+ }: {
+ orgId: string;
+ projectId: string;
+ eventTypes: EventType[];
+ startDate: string;
+ endDate: string;
+ },
+ tx?: knex.Knex
+ ) => {
+ const rows = await (tx || db.replicaNode())(TableName.AuditLog)
+ .where(`${TableName.AuditLog}.orgId`, orgId)
+ .where(`${TableName.AuditLog}.projectId`, projectId)
+ .whereIn(`${TableName.AuditLog}.eventType`, eventTypes)
+ .whereRaw(`"${TableName.AuditLog}"."createdAt" >= ?::timestamptz`, [startDate])
+ .whereRaw(`"${TableName.AuditLog}"."createdAt" < ?::timestamptz`, [endDate])
+ .select(`${TableName.AuditLog}.actor`, `${TableName.AuditLog}.actorMetadata`)
+ .groupBy(`${TableName.AuditLog}.actor`, `${TableName.AuditLog}.actorMetadata`)
+ .select(db.raw("COUNT(*)::int as count"))
+ .timeout(1000 * 120);
+
+ return rows as { actor: string; actorMetadata: unknown; count: number }[];
+ };
+
+ return { ...auditLogOrm, create, pruneAuditLog, find, countByDateAndActor, countByIpAddress, countByAuthMethod };
};
diff --git a/backend/src/ee/services/insights/insights-service.ts b/backend/src/ee/services/insights/insights-service.ts
index c4a2725b01..5f0f6186ab 100644
--- a/backend/src/ee/services/insights/insights-service.ts
+++ b/backend/src/ee/services/insights/insights-service.ts
@@ -2,7 +2,8 @@ import { ForbiddenError } from "@casl/ability";
import geoip from "geoip-lite";
import { ActionProjectType, IdentityAuthMethod } from "@app/db/schemas";
-import { EventType, TAuditLogServiceFactory } from "@app/ee/services/audit-log/audit-log-types";
+import { TAuditLogDALFactory } from "@app/ee/services/audit-log/audit-log-dal";
+import { EventType } from "@app/ee/services/audit-log/audit-log-types";
import { TPermissionServiceFactory } from "@app/ee/services/permission/permission-service-types";
import { ProjectPermissionInsightsActions, ProjectPermissionSub } from "@app/ee/services/permission/project-permission";
import { TSecretRotationV2DALFactory } from "@app/ee/services/secret-rotation-v2/secret-rotation-v2-dal";
@@ -23,7 +24,7 @@ import {
type TInsightsServiceFactoryDep = {
permissionService: Pick<TPermissionServiceFactory, "getProjectPermission">;
- auditLogService: Pick<TAuditLogServiceFactory, "listAuditLogs">;
+ auditLogDAL: Pick<TAuditLogDALFactory, "countByDateAndActor" | "countByIpAddress" | "countByAuthMethod">;
secretRotationV2DAL: Pick<TSecretRotationV2DALFactory, "findByProjectAndDateRange" | "findByProject">;
reminderDAL: Pick<TReminderDALFactory, "findByProjectAndDateRange">;
folderDAL: Pick<TSecretFolderDALFactory, "findSecretPathByFolderIds">;
@@ -61,7 +62,7 @@ const checkInsightsPermission = async (
export const insightsServiceFactory = ({
permissionService,
- auditLogService,
+ auditLogDAL,
secretRotationV2DAL,
reminderDAL,
folderDAL,
@@ -131,43 +132,36 @@ export const insightsServiceFactory = ({
const startDate = new Date(`${todayStr}T00:00:00.000Z`);
startDate.setUTCDate(startDate.getUTCDate() - 6);
- const auditLogs = await auditLogService.listAuditLogs({
- filter: {
- projectId: dto.projectId,
- eventType: VALUE_EVENT_TYPES,
- startDate: startDate.toISOString(),
- endDate: endDate.toISOString(),
- limit: 9999
- },
- actorId: actorDto.id,
- actorOrgId: actorDto.orgId,
- actorAuthMethod: actorDto.authMethod,
- actor: actorDto.type
+ const rows = await auditLogDAL.countByDateAndActor({
+ orgId: actorDto.orgId,
+ projectId: dto.projectId,
+ eventTypes: VALUE_EVENT_TYPES,
+ startDate: startDate.toISOString(),
+ endDate: endDate.toISOString()
});
+ // Pre-populate the last 7 days
const dayMap = new Map<string, Map<string, { name: string; type: string; count: number }>>();
-
for (let i = 6; i >= 0; i -= 1) {
const d = new Date(`${todayStr}T00:00:00.000Z`);
d.setUTCDate(d.getUTCDate() - i);
- const key = d.toISOString().slice(0, 10);
- dayMap.set(key, new Map());
+ dayMap.set(d.toISOString().slice(0, 10), new Map());
}
- auditLogs.forEach((log) => {
- const dateKey = log.createdAt.toISOString().slice(0, 10);
+ rows.forEach((row) => {
+ const dateKey = typeof row.date === "string" ? row.date : new Date(row.date).toISOString().slice(0, 10);
const actorMap = dayMap.get(dateKey);
if (!actorMap) return;
- const actorMeta = log.actor.metadata as Record<string, string> | null;
+ const actorMeta = row.actorMetadata as Record<string, string> | null;
const actorName = actorMeta?.email || actorMeta?.name || actorMeta?.identityId || actorMeta?.userId || "Unknown";
- const actorKey = `${log.actor.type}:${actorName}`;
+ const actorKey = `${row.actor}:${actorName}`;
const existing = actorMap.get(actorKey);
if (existing) {
- existing.count += 1;
+ existing.count += row.count;
} else {
- actorMap.set(actorKey, { name: actorName, type: log.actor.type, count: 1 });
+ actorMap.set(actorKey, { name: actorName, type: row.actor, count: row.count });
}
});
@@ -187,26 +181,12 @@ export const insightsServiceFactory = ({
const startDate = new Date();
startDate.setUTCDate(startDate.getUTCDate() - dto.days);
- const auditLogs = await auditLogService.listAuditLogs({
- filter: {
- projectId: dto.projectId,
- eventType: VALUE_EVENT_TYPES,
- startDate: startDate.toISOString(),
- endDate: endDate.toISOString(),
- limit: 9999
- },
- actorId: actorDto.id,
- actorOrgId: actorDto.orgId,
- actorAuthMethod: actorDto.authMethod,
- actor: actorDto.type
- });
-
- const ipCounts = new Map<string, number>();
- auditLogs.forEach((log) => {
- const ip = (log as { ipAddress?: string | null }).ipAddress;
- if (ip) {
- ipCounts.set(ip, (ipCounts.get(ip) || 0) + 1);
- }
+ const ipRows = await auditLogDAL.countByIpAddress({
+ orgId: actorDto.orgId,
+ projectId: dto.projectId,
+ eventTypes: VALUE_EVENT_TYPES,
+ startDate: startDate.toISOString(),
+ endDate: endDate.toISOString()
});
const locationMap = new Map<string, { lat: number; lng: number; city: string; country: string; count: number }>();
@@ -220,12 +200,21 @@ export const insightsServiceFactory = ({
ip.startsWith("172.17.") ||
ip.startsWith("172.18.") ||
ip.startsWith("172.19.") ||
- ip.startsWith("172.2") ||
+ ip.startsWith("172.20.") ||
+ ip.startsWith("172.21.") ||
+ ip.startsWith("172.22.") ||
+ ip.startsWith("172.23.") ||
+ ip.startsWith("172.24.") ||
+ ip.startsWith("172.25.") ||
+ ip.startsWith("172.26.") ||
+ ip.startsWith("172.27.") ||
+ ip.startsWith("172.28.") ||
+ ip.startsWith("172.29.") ||
ip.startsWith("172.30.") ||
ip.startsWith("172.31.") ||
ip.startsWith("192.168.");
- ipCounts.forEach((count, ip) => {
+ ipRows.forEach(({ ipAddress: ip, count }) => {
if (isPrivateIp(ip)) {
const key = "Local Network:LOCAL";
const existing = locationMap.get(key);
@@ -268,18 +257,12 @@ export const insightsServiceFactory = ({
const startDate = new Date();
startDate.setUTCDate(startDate.getUTCDate() - dto.days);
- const auditLogs = await auditLogService.listAuditLogs({
- filter: {
- projectId: dto.projectId,
- eventType: VALUE_EVENT_TYPES,
- startDate: startDate.toISOString(),
- endDate: endDate.toISOString(),
- limit: 10000
- },
- actorId: actorDto.id,
- actorOrgId: actorDto.orgId,
- actorAuthMethod: actorDto.authMethod,
- actor: actorDto.type
+ const authRows = await auditLogDAL.countByAuthMethod({
+ orgId: actorDto.orgId,
+ projectId: dto.projectId,
+ eventTypes: VALUE_EVENT_TYPES,
+ startDate: startDate.toISOString(),
+ endDate: endDate.toISOString()
});
const methodCounts = new Map<string, number>();
@@ -314,23 +297,23 @@ export const insightsServiceFactory = ({
[IdentityAuthMethod.SPIFFE_AUTH]: "SPIFFE Auth"
};
- auditLogs.forEach((log) => {
- const actorMeta = log.actor.metadata as Record<string, unknown> | null;
+ authRows.forEach((row) => {
+ const actorMeta = row.actorMetadata as Record<string, unknown> | null;
let method = "Unknown";
- if (log.actor.type === "user") {
+ if (row.actor === "user") {
const raw = (actorMeta?.authMethod as string) || "Unknown";
method = authMethodLabels[raw] || raw;
- } else if (log.actor.type === "identity") {
+ } else if (row.actor === "identity") {
const identityAuth = actorMeta?.authMethod as IdentityAuthMethod | undefined;
method = identityAuth ? identityAuthMethodLabels[identityAuth] || identityAuth : "Unknown";
- } else if (log.actor.type === "service") {
+ } else if (row.actor === "service") {
method = "Service Token";
} else {
- method = log.actor.type;
+ method = row.actor;
}
- methodCounts.set(method, (methodCounts.get(method) || 0) + 1);
+ methodCounts.set(method, (methodCounts.get(method) || 0) + (row.count || 0));
});
const methods = Array.from(methodCounts.entries())
@@ -349,18 +332,20 @@ export const insightsServiceFactory = ({
const now = new Date();
const in7Days = new Date(now);
in7Days.setDate(now.getDate() + 7);
- const staleThreshold = new Date(now);
- staleThreshold.setDate(now.getDate() - 90);
+ const lookback90Days = new Date(now);
+ lookback90Days.setDate(now.getDate() - 90);
+ const staleThreshold = lookback90Days;
// Fetch upcoming rotations (by date range) and all failed rotations (no date filter) in parallel
+ // Use 90-day lookback to capture overdue items without unbounded historical queries
const [upcomingRotationsRaw, allProjectRotations, reminders] = await Promise.all([
secretRotationV2DAL.findByProjectAndDateRange({
projectId: dto.projectId,
- startDate: new Date(0),
+ startDate: lookback90Days,
endDate: in7Days
}),
secretRotationV2DAL.findByProject(dto.projectId),
- fetchReminders(dto.projectId, new Date(0), in7Days)
+ fetchReminders(dto.projectId, lookback90Days, in7Days)
]);
const mapRotation = (r: (typeof allProjectRotations)[number]) => ({
diff --git a/backend/src/server/routes/index.ts b/backend/src/server/routes/index.ts
index 0ac8ff65b9..1a424ac652 100644
--- a/backend/src/server/routes/index.ts
+++ b/backend/src/server/routes/index.ts
@@ -2338,7 +2338,7 @@ export const registerRoutes = async (
const insightsService = insightsServiceFactory({
permissionService,
- auditLogService,
+ auditLogDAL,
secretRotationV2DAL,
reminderDAL,
folderDAL,
diff --git a/frontend/src/pages/secret-manager/InsightsPage/components/CalendarEventDetail.tsx b/frontend/src/pages/secret-manager/InsightsPage/components/CalendarEventDetail.tsx
index 29dc8ac6bf..878c60f809 100644
--- a/frontend/src/pages/secret-manager/InsightsPage/components/CalendarEventDetail.tsx
+++ b/frontend/src/pages/secret-manager/InsightsPage/components/CalendarEventDetail.tsx
@@ -124,7 +124,7 @@ export const CalendarEventDetail = ({ event }: { event: CalendarEvent }) => {
</Detail>
<Detail>
<DetailLabel>Secret Keys</DetailLabel>
- <DetailValue>{event.data.secretKeys.map((key) => <p>{key}</p>) || "—"}</DetailValue>
+ <DetailValue>{event.data.secretKeys.map((key) => <p key={key}>{key}</p>) || "—"}</DetailValue>
</Detail>
</>
)}
diff --git a/frontend/src/pages/secret-manager/InsightsPage/components/SecretAccessChart.tsx b/frontend/src/pages/secret-manager/InsightsPage/components/SecretAccessChart.tsx
index 89d24dee2a..4a0dd476d1 100644
--- a/frontend/src/pages/secret-manager/InsightsPage/components/SecretAccessChart.tsx
+++ b/frontend/src/pages/secret-manager/InsightsPage/components/SecretAccessChart.tsx
@@ -62,13 +62,13 @@ export const SecretAccessChart = () => {
<LineChart data={chartData} />
{topActors.length > 0 && (
<div className="flex flex-col gap-2">
- <span className="text-xs text-label">
+ <span className="text-xs text-accent">
Top actors — {totalRequests.toLocaleString()} total requests
</span>
<div className="flex flex-wrap gap-x-4 gap-y-1">
{topActors.map((actor) => (
<span key={`${actor.type}:${actor.name}`} className="text-xs text-foreground">
- <span className="text-label">{actor.type}:</span> {actor.name}{" "}
+ <span className="text-muted">{actor.type}:</span> {actor.name}{" "}
<span className="text-label">({actor.count.toLocaleString()})</span>
</span>
))}