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
widden window to alert before and not within
Thiago Araujo da Silva41b0f6096d3f
diff --git a/backend/src/services/alert/alert-queue.ts b/backend/src/services/alert/alert-queue.tsindex ddf75827b4..84df78d116 100644--- a/backend/src/services/alert/alert-queue.ts+++ b/backend/src/services/alert/alert-queue.ts@@ -64,6 +64,8 @@ export const alertQueueServiceFactory = ({cronJob.register({name: CronJobName.DailyAlertProcessing,+ // Cadence is coupled to ALERT_SCAN_LEAD_* (alert-types.ts): providers scan one period ahead to+ // guarantee "at least alertBefore" lead. If this pattern changes, revisit that constant.pattern: appCfg.isDevelopmentMode ? "*/5 * * * *" : "0 0 * * *",runHashTtlS: 60 * 60 * 24,enabled: !appCfg.isSecondaryInstance,diff --git a/backend/src/services/alert/alert-types.ts b/backend/src/services/alert/alert-types.tsindex 42971b32da..a8c1bac20c 100644--- a/backend/src/services/alert/alert-types.ts+++ b/backend/src/services/alert/alert-types.ts@@ -36,6 +36,11 @@ export type TAlertPermissionInput = {export const DEFAULT_DEDUP_WINDOW_HOURS = 24;+// Providers scan this many days ahead of `alertBefore` so alerts fire at LEAST `alertBefore` before+// expiry despite the coarse daily poll. Keep >= the DailyAlertProcessing cadence (alert-queue.ts).+export const ALERT_SCAN_LEAD_DAYS = 1;+export const ALERT_SCAN_LEAD_INTERVAL = "1 day";+export const MAX_CHANNELS_PER_ALERT = 10;export const MAX_RECIPIENTS_PER_CHANNEL = 20;diff --git a/backend/src/services/alert/providers/identity-credential-alert-dal.ts b/backend/src/services/alert/providers/identity-credential-alert-dal.tsindex 1b98277a31..40b44b98fe 100644--- a/backend/src/services/alert/providers/identity-credential-alert-dal.ts+++ b/backend/src/services/alert/providers/identity-credential-alert-dal.ts@@ -22,12 +22,14 @@ export const identityCredentialAlertDALFactory = (db: TDbClient) => {projectId,identityId,alertBeforeInterval,+ leadInterval,asOf}: {orgId: string;projectId?: string | null;identityId?: string | null;alertBeforeInterval: string;+ leadInterval: string;asOf: Date;},tx?: Knex@@ -52,7 +54,7 @@ export const identityCredentialAlertDALFactory = (db: TDbClient) => {.where(`${TableName.IdentityUaClientSecret}.isClientSecretRevoked`, false).where(`${TableName.IdentityUaClientSecret}.clientSecretTTL`, ">", 0).whereRaw(`${expiresAtSql} > ?`, [asOf])- .whereRaw(`${expiresAtSql} <= ? + ?::interval`, [asOf, alertBeforeInterval]);+ .whereRaw(`${expiresAtSql} <= ? + ?::interval + ?::interval`, [asOf, alertBeforeInterval, leadInterval]);if (projectId) {void querydiff --git a/backend/src/services/alert/providers/identity-credential-alert-provider.test.ts b/backend/src/services/alert/providers/identity-credential-alert-provider.test.tsindex 7f5d2f0b76..b56114c4b5 100644--- a/backend/src/services/alert/providers/identity-credential-alert-provider.test.ts+++ b/backend/src/services/alert/providers/identity-credential-alert-provider.test.ts@@ -44,6 +44,7 @@ const buildProvider = (opts?: {projectId?: string | null;identityId?: string | null;alertBeforeInterval: string;+ leadInterval: string;asOf: Date;}) => void;abilityRules?: { action: string; subject: string; conditions?: Record<string, unknown> }[];@@ -57,6 +58,7 @@ const buildProvider = (opts?: {projectId?: string | null;identityId?: string | null;alertBeforeInterval: string;+ leadInterval: string;asOf: Date;}) => {opts?.onFind?.(args);@@ -90,7 +92,13 @@ describe("identity credential alert provider", () => {test("findDueTargets converts alertBefore to a postgres interval and tags credential type", async () => {let seenArgs:- | { alertBeforeInterval: string; projectId?: string | null; identityId?: string | null; asOf: Date }+ | {+ alertBeforeInterval: string;+ leadInterval: string;+ projectId?: string | null;+ identityId?: string | null;+ asOf: Date;+ }| undefined;const provider = buildProvider({secrets: [sampleSecret()],@@ -109,6 +117,7 @@ describe("identity credential alert provider", () => {});expect(seenArgs?.alertBeforeInterval).toBe("30 days");+ expect(seenArgs?.leadInterval).toBe("1 day");expect(seenArgs?.identityId).toBe("ident-1");expect(seenArgs?.asOf).toBe(asOf);expect(targets).toHaveLength(1);@@ -191,10 +200,10 @@ describe("identity credential alert provider", () => {expect(url).toBe("https://app.infisical.com/organizations/org-1/identities/ident-1");});- test("dedup window spans the lead time (30d -> 720h) with a 24h floor", () => {+ test("dedup window spans alertBefore + the scan lead (30d -> 744h, 1d -> 48h) with a 24h floor", () => {const provider = buildProvider();- expect(provider.dedupWindowHours?.({ alertBefore: "30d" })).toBe(720);- expect(provider.dedupWindowHours?.({ alertBefore: "1d" })).toBe(24);+ expect(provider.dedupWindowHours?.({ alertBefore: "30d" })).toBe(744);+ expect(provider.dedupWindowHours?.({ alertBefore: "1d" })).toBe(48);expect(provider.dedupWindowHours?.({ alertBefore: "bad" })).toBe(24);});diff --git a/backend/src/services/alert/providers/identity-credential-alert-provider.ts b/backend/src/services/alert/providers/identity-credential-alert-provider.tsindex d4a364d673..5054d5cb11 100644--- a/backend/src/services/alert/providers/identity-credential-alert-provider.ts+++ b/backend/src/services/alert/providers/identity-credential-alert-provider.ts@@ -11,6 +11,8 @@ import { ForbiddenRequestError, NotFoundError } from "@app/lib/errors";import { TAlertPayload, TAlertSeverity } from "../alert-channel-types";import {+ ALERT_SCAN_LEAD_DAYS,+ ALERT_SCAN_LEAD_INTERVAL,AlertPermissionAction,DEFAULT_DEDUP_WINDOW_HOURS,IResourceAlertProvider,@@ -133,6 +135,7 @@ export const identityCredentialAlertProviderFactory = ({projectId: input.projectId,identityId: input.resourceId,alertBeforeInterval: intervalSql,+ leadInterval: ALERT_SCAN_LEAD_INTERVAL,asOf: input.asOf});@@ -265,7 +268,11 @@ export const identityCredentialAlertProviderFactory = ({const parsed = IdentityCredentialConditionSchema.safeParse(condition);if (!parsed.success) return DEFAULT_DEDUP_WINDOW_HOURS;if (parsed.data.dailyReminder) return DAILY_REPEAT_DEDUP_WINDOW_HOURS;- return Math.max(DEFAULT_DEDUP_WINDOW_HOURS, parseAlertBefore(parsed.data.alertBefore).days * 24);+ // Span the widened scan window (alertBefore + the scan lead) so a target still fires only once.+ return Math.max(+ DEFAULT_DEDUP_WINDOW_HOURS,+ (parseAlertBefore(parsed.data.alertBefore).days + ALERT_SCAN_LEAD_DAYS) * 24+ );},assertPermission,assertResourceInScope