Skip to content

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

fix(audit-log): treat "No limit" retention as unlimited instead of dropping every log

Scott Wilson4c5f680503a6
diff --git a/backend/CLAUDE.md b/backend/CLAUDE.md
index 8716a42af7..7a89b83463 100644
--- a/backend/CLAUDE.md
+++ b/backend/CLAUDE.md
@@ -535,8 +535,9 @@ line by returning `adoptedFromUsername: null` for the yield, and the caller keys
it.
That trail is best-effort, not guaranteed. `audit-log-queue.ts` drops every entry at push time when
-`plan.auditLogsRetentionDays` is falsy, which is the default for a self-hosted instance with no
+`plan.auditLogsRetentionDays` is 0, which is the default for a self-hosted instance with no
audit-log entitlement, so on those deployments only the `logger.info` line survives an adoption.
+(`null` is the License Server's "No limit" and keeps everything; see `audit-log-retention-fns.ts`.)
Do not special-case this event past the retention gate; treat the application log as the floor and
the audit event as the addition for licensed instances.
diff --git a/backend/src/ee/services/audit-log/audit-log-queue.test.ts b/backend/src/ee/services/audit-log/audit-log-queue.test.ts
index 56522b4ea9..fdc453cee5 100644
--- a/backend/src/ee/services/audit-log/audit-log-queue.test.ts
+++ b/backend/src/ee/services/audit-log/audit-log-queue.test.ts
@@ -3,6 +3,7 @@ import { beforeEach, describe, expect, test, vi } from "vitest";
import { QueueName } from "@app/queue";
import { auditLogQueueServiceFactory } from "./audit-log-queue";
+import { MAX_AUDIT_LOG_EXPIRES_AT } from "./audit-log-retention-fns";
// Mutable config the mocked getConfig() returns. CLICKHOUSE_AUDIT_LOG_ENABLED is read once at
// factory construction; AUDIT_LOG_STREAMS_ENABLED is read per consumer run.
@@ -91,7 +92,7 @@ const createHarness = async ({ clickhouse = false, streamsEnabled = false, gener
findById: vi.fn<(id: string) => Promise<Record<string, unknown> | undefined>>(async () => undefined)
};
const licenseService = {
- getPlan: vi.fn<(orgId: string) => Promise<{ auditLogsRetentionDays: number }>>(async () => ({
+ getPlan: vi.fn<(orgId: string) => Promise<{ auditLogsRetentionDays: number | null }>>(async () => ({
auditLogsRetentionDays: 30
}))
};
@@ -230,6 +231,27 @@ describe("audit-log-queue pushToLog", () => {
expect(keyStore.streamAdd).not.toHaveBeenCalled();
});
+ test("keeps logs until the expiry cap when the plan's retention is unlimited (null)", async () => {
+ const { service, keyStore, licenseService } = await createHarness();
+ licenseService.getPlan.mockResolvedValueOnce({ auditLogsRetentionDays: null });
+
+ await service.pushToLog(dto({ orgId: "org-unlimited" }) as never);
+
+ expect(pushedEntry(keyStore).expiresAt).toBe(MAX_AUDIT_LOG_EXPIRES_AT.toISOString());
+ });
+
+ test("applies the project-level retention under an unlimited plan", async () => {
+ const { service, keyStore, projectDAL, licenseService } = await createHarness();
+ projectDAL.findById.mockResolvedValueOnce({ id: "p1", orgId: "org-1", name: "proj", auditLogsRetentionDays: 5 });
+ licenseService.getPlan.mockResolvedValueOnce({ auditLogsRetentionDays: null });
+
+ await service.pushToLog(dto({ orgId: undefined, projectId: "p1" }) as never);
+
+ const parsed = pushedEntry(keyStore);
+ const ttl = new Date(parsed.expiresAt as string).getTime() - new Date(parsed.createdAt as string).getTime();
+ expect(ttl).toBe(5 * MS_IN_DAY);
+ });
+
test("never throws when streamAdd fails", async () => {
const { service, keyStore } = await createHarness();
keyStore.streamAdd.mockRejectedValueOnce(new Error("redis down"));
diff --git a/backend/src/ee/services/audit-log/audit-log-queue.ts b/backend/src/ee/services/audit-log/audit-log-queue.ts
index ebe6be0bc4..1c0e9f3259 100644
--- a/backend/src/ee/services/audit-log/audit-log-queue.ts
+++ b/backend/src/ee/services/audit-log/audit-log-queue.ts
@@ -20,6 +20,7 @@ import { TProjectDALFactory } from "@app/services/project/project-dal";
import { TLicenseServiceFactory } from "../license/license-service";
import { TAuditLogDALFactory } from "./audit-log-dal";
import { getAuditLogEventClass, isAlwaysRecordedEventClass } from "./audit-log-event-classes";
+import { getAuditLogExpiresAt, hasAuditLogRetention } from "./audit-log-retention-fns";
import { isAuditLogEventEnabled, TAuditLogSettingsServiceFactory } from "./audit-log-settings-service";
import { TAuditLogStreamEntry, TCreateAuditLogDTO } from "./audit-log-types";
@@ -64,7 +65,6 @@ export const AUDIT_LOG_STREAM_TIMEOUT = 5 * 1000;
// batch deliveries can carry up to AUDIT_LOG_STREAM_BATCH_SIZE events to remote intakes;
// give them more headroom than the single-event ping timeout above.
export const AUDIT_LOG_STREAM_BATCH_TIMEOUT = 30 * 1000;
-const MS_IN_DAY = 24 * 60 * 60 * 1000;
const AUDIT_LOG_STREAM_KEY = "audit-log-stream";
const AUDIT_LOG_STREAM_BATCH_SIZE = 10_000;
@@ -116,13 +116,7 @@ export const auditLogQueueServiceFactory = async ({
}
const plan = await requestMemoize(requestMemoKeys.licensePlan(orgId), () => licenseService.getPlan(orgId));
- if (!plan?.auditLogsRetentionDays) return null;
-
- const ttlInDays =
- project?.auditLogsRetentionDays && project.auditLogsRetentionDays < plan.auditLogsRetentionDays
- ? project.auditLogsRetentionDays
- : plan.auditLogsRetentionDays;
- const ttl = ttlInDays * MS_IN_DAY;
+ if (!plan || !hasAuditLogRetention(plan)) return null;
const createdAt = new Date();
const id = isClickHouseBatchEnabled ? uuidv7({ msecs: createdAt.getTime() }) : randomUUID();
@@ -132,7 +126,7 @@ export const auditLogQueueServiceFactory = async ({
id,
orgId,
createdAt: createdAt.toISOString(),
- expiresAt: new Date(createdAt.getTime() + ttl).toISOString(),
+ expiresAt: getAuditLogExpiresAt(createdAt, plan, project?.auditLogsRetentionDays).toISOString(),
projectName: project?.name
};
};
diff --git a/backend/src/ee/services/audit-log/audit-log-retention-fns.test.ts b/backend/src/ee/services/audit-log/audit-log-retention-fns.test.ts
new file mode 100644
index 0000000000..0ad93bce92
--- /dev/null
+++ b/backend/src/ee/services/audit-log/audit-log-retention-fns.test.ts
@@ -0,0 +1,55 @@
+import { describe, expect, test } from "vitest";
+
+import {
+ getAuditLogExpiresAt,
+ hasAuditLogRetention,
+ isWithinPlanAuditLogRetention,
+ MAX_AUDIT_LOG_EXPIRES_AT
+} from "./audit-log-retention-fns";
+
+const MS_IN_DAY = 24 * 60 * 60 * 1000;
+const createdAt = new Date("2026-10-13T00:00:00.000Z");
+
+describe("hasAuditLogRetention", () => {
+ test("treats null as unlimited and 0 as no retention", () => {
+ expect(hasAuditLogRetention({ auditLogsRetentionDays: null })).toBe(true);
+ expect(hasAuditLogRetention({ auditLogsRetentionDays: 30 })).toBe(true);
+ expect(hasAuditLogRetention({ auditLogsRetentionDays: 0 })).toBe(false);
+ });
+});
+
+describe("isWithinPlanAuditLogRetention", () => {
+ test("accepts any value under an unlimited plan and caps a finite one", () => {
+ expect(isWithinPlanAuditLogRetention(10_000, { auditLogsRetentionDays: null })).toBe(true);
+ expect(isWithinPlanAuditLogRetention(90, { auditLogsRetentionDays: 90 })).toBe(true);
+ expect(isWithinPlanAuditLogRetention(91, { auditLogsRetentionDays: 90 })).toBe(false);
+ });
+});
+
+describe("getAuditLogExpiresAt", () => {
+ test("uses the plan retention when the project sets none", () => {
+ expect(getAuditLogExpiresAt(createdAt, { auditLogsRetentionDays: 30 }, null).getTime()).toBe(
+ createdAt.getTime() + 30 * MS_IN_DAY
+ );
+ });
+
+ test("uses a project retention lower than the plan, and ignores a higher one", () => {
+ expect(getAuditLogExpiresAt(createdAt, { auditLogsRetentionDays: 30 }, 5).getTime()).toBe(
+ createdAt.getTime() + 5 * MS_IN_DAY
+ );
+ expect(getAuditLogExpiresAt(createdAt, { auditLogsRetentionDays: 30 }, 60).getTime()).toBe(
+ createdAt.getTime() + 30 * MS_IN_DAY
+ );
+ });
+
+ test("expires at the cap under an unlimited plan", () => {
+ expect(getAuditLogExpiresAt(createdAt, { auditLogsRetentionDays: null })).toEqual(MAX_AUDIT_LOG_EXPIRES_AT);
+ });
+
+ test("clamps a retention that would run past the cap", () => {
+ expect(getAuditLogExpiresAt(createdAt, { auditLogsRetentionDays: null }, 1_000_000)).toEqual(
+ MAX_AUDIT_LOG_EXPIRES_AT
+ );
+ expect(getAuditLogExpiresAt(createdAt, { auditLogsRetentionDays: 1_000_000 })).toEqual(MAX_AUDIT_LOG_EXPIRES_AT);
+ });
+});
diff --git a/backend/src/ee/services/audit-log/audit-log-retention-fns.ts b/backend/src/ee/services/audit-log/audit-log-retention-fns.ts
new file mode 100644
index 0000000000..d1195ba2e0
--- /dev/null
+++ b/backend/src/ee/services/audit-log/audit-log-retention-fns.ts
@@ -0,0 +1,32 @@
+import { TFeatureSet } from "../license/license-types";
+
+const MS_IN_DAY = 24 * 60 * 60 * 1000;
+
+// Unlimited retention still needs a concrete expiry: ClickHouse stores expiresAt as a non-nullable
+// DateTime64 and its TTL casts it with toDateTime, which overflows after 2106-02-07. Every expiry is
+// capped here so no retention value can reach that overflow.
+export const MAX_AUDIT_LOG_EXPIRES_AT = new Date("2100-01-01T00:00:00.000Z");
+
+type TAuditLogRetentionPlan = Pick<TFeatureSet, "auditLogsRetentionDays">;
+
+// A null retention is the License Server's "No limit"; 0 means the plan keeps no audit logs.
+export const hasAuditLogRetention = (plan: TAuditLogRetentionPlan) =>
+ plan.auditLogsRetentionDays === null || plan.auditLogsRetentionDays > 0;
+
+export const isWithinPlanAuditLogRetention = (days: number, plan: TAuditLogRetentionPlan) =>
+ plan.auditLogsRetentionDays === null || days <= plan.auditLogsRetentionDays;
+
+export const getAuditLogExpiresAt = (
+ createdAt: Date,
+ plan: TAuditLogRetentionPlan,
+ projectRetentionDays?: number | null
+) => {
+ const retentionDays =
+ projectRetentionDays && isWithinPlanAuditLogRetention(projectRetentionDays, plan)
+ ? projectRetentionDays
+ : plan.auditLogsRetentionDays;
+
+ if (retentionDays === null) return MAX_AUDIT_LOG_EXPIRES_AT;
+
+ return new Date(Math.min(createdAt.getTime() + retentionDays * MS_IN_DAY, MAX_AUDIT_LOG_EXPIRES_AT.getTime()));
+};
diff --git a/backend/src/ee/services/audit-log/audit-log-service.ts b/backend/src/ee/services/audit-log/audit-log-service.ts
index 6e5b4e17f5..4b7767b45a 100644
--- a/backend/src/ee/services/audit-log/audit-log-service.ts
+++ b/backend/src/ee/services/audit-log/audit-log-service.ts
@@ -25,6 +25,7 @@ import { TClickHouseAuditLogDALFactory } from "./audit-log-clickhouse-dal";
import { TAuditLogDALFactory, TPamAuditLogScope } from "./audit-log-dal";
import { getAuditLogEventClass, resolveEventClassFilter } from "./audit-log-event-classes";
import { TAuditLogQueueServiceFactory } from "./audit-log-queue";
+import { hasAuditLogRetention } from "./audit-log-retention-fns";
import { isAuditLogEventEnabled, TAuditLogSettingsServiceFactory } from "./audit-log-settings-service";
import {
ACTOR_TYPE_TO_METADATA_ID_KEY,
@@ -311,7 +312,7 @@ export const auditLogServiceFactory = ({
if (!isAuditLogEventEnabled(settings, EventType.PERMISSION_DENIED, projectId)) return;
const plan = await requestMemoize(requestMemoKeys.licensePlan(orgId), () => licenseService.getPlan(orgId));
- if (!plan?.auditLogsRetentionDays) return;
+ if (!plan || !hasAuditLogRetention(plan)) return;
const actorIdKey = ACTOR_TYPE_TO_METADATA_ID_KEY[auditLogInfo.actor.type];
const actorId = actorIdKey ? (auditLogInfo.actor.metadata as Record<string, unknown>)[actorIdKey] : undefined;
diff --git a/backend/src/ee/services/license/license-types.ts b/backend/src/ee/services/license/license-types.ts
index ae68b59d7c..f45592f993 100644
--- a/backend/src/ee/services/license/license-types.ts
+++ b/backend/src/ee/services/license/license-types.ts
@@ -73,7 +73,7 @@ export type TFeatureSet = {
customRateLimits: false;
customAlerts: false;
auditLogs: false;
- auditLogsRetentionDays: 0;
+ auditLogsRetentionDays: number | null;
auditLogStreams: false;
auditLogStreamLimit: 3;
githubOrgSync: false;
diff --git a/backend/src/services/license-client/entitlement-projection.ts b/backend/src/services/license-client/entitlement-projection.ts
index 7204b663b8..de898cad69 100644
--- a/backend/src/services/license-client/entitlement-projection.ts
+++ b/backend/src/services/license-client/entitlement-projection.ts
@@ -24,7 +24,8 @@ const projectNotices = (rawNotices: unknown[]): TPlanNotice[] =>
// Builds a plan-shaped TFeatureSet from the License Server entitlement set so getPlan can serve it
// without changing its callers. Starts from the passed base (free-tier defaults) and overlays each
-// mapped feature; a key v2 omits or returns null for keeps the base value. Base is passed in (not
+// mapped feature; a key v2 omits keeps the base value, while a null is written through because that is
+// how v2 says "no limit" (eg unlimited audit log retention). Base is passed in (not
// imported from license-fns) to avoid a license-service <-> license-fns import cycle.
export const projectV2ToFeatureSet = (base: TFeatureSet, entitlements: TEntitlementsResponse): TFeatureSet => {
const plan = JSON.parse(JSON.stringify(base)) as Record<string, unknown> & { rateLimits: Record<string, unknown> };
diff --git a/backend/src/services/project/project-service.ts b/backend/src/services/project/project-service.ts
index 92548c8f55..c8adb368f9 100644
--- a/backend/src/services/project/project-service.ts
+++ b/backend/src/services/project/project-service.ts
@@ -16,6 +16,7 @@ import {
TProjectEnvironments,
TProjects
} from "@app/db/schemas";
+import { isWithinPlanAuditLogRetention } from "@app/ee/services/audit-log/audit-log-retention-fns";
import { TLicenseServiceFactory } from "@app/ee/services/license/license-service";
import {
OrgPermissionActions,
@@ -1041,7 +1042,7 @@ export const projectServiceFactory = ({
});
}
- if (update.auditLogsRetentionDays > plan.auditLogsRetentionDays) {
+ if (!isWithinPlanAuditLogRetention(update.auditLogsRetentionDays, plan)) {
throw new BadRequestError({
message: `Failed to update the audit logs retention period because your current plan allows a maximum of ${plan.auditLogsRetentionDays} days. Upgrade your plan to increase this limit.`
});
@@ -1196,7 +1197,7 @@ export const projectServiceFactory = ({
);
const plan = await licenseService.getPlan(project.orgId);
- if (!plan.auditLogs || auditLogsRetentionDays > plan.auditLogsRetentionDays) {
+ if (!plan.auditLogs || !isWithinPlanAuditLogRetention(auditLogsRetentionDays, plan)) {
throw new BadRequestError({
message: "Failed to update audit logs retention due to plan limit reached. Upgrade plan to increase."
});
diff --git a/frontend/src/hooks/api/subscriptions/types.ts b/frontend/src/hooks/api/subscriptions/types.ts
index 06502f1336..2969aac755 100644
--- a/frontend/src/hooks/api/subscriptions/types.ts
+++ b/frontend/src/hooks/api/subscriptions/types.ts
@@ -33,7 +33,7 @@ export type SubscriptionPlan = {
identityLimit: number;
auditLogs: boolean;
dynamicSecret: boolean;
- auditLogsRetentionDays: number;
+ auditLogsRetentionDays: number | null;
auditLogStreamLimit: number;
auditLogStreams: boolean;
customAlerts: boolean;
diff --git a/frontend/src/pages/cert-manager/PkiSyncDetailsByIDPage/components/PkiSyncAuditLogsSection.tsx b/frontend/src/pages/cert-manager/PkiSyncDetailsByIDPage/components/PkiSyncAuditLogsSection.tsx
index 0f6d2cd561..0216b505ff 100644
--- a/frontend/src/pages/cert-manager/PkiSyncDetailsByIDPage/components/PkiSyncAuditLogsSection.tsx
+++ b/frontend/src/pages/cert-manager/PkiSyncDetailsByIDPage/components/PkiSyncAuditLogsSection.tsx
@@ -33,7 +33,10 @@ export const PkiSyncAuditLogsSection = ({ pkiSync }: Props) => {
const { subscription } = useSubscription();
const { currentProject } = useProject();
const { currentOrg } = useOrganization();
- const auditLogsRetentionDays = subscription?.auditLogsRetentionDays ?? 30;
+ const auditLogsRetentionDays =
+ subscription?.auditLogsRetentionDays === null
+ ? Infinity
+ : (subscription?.auditLogsRetentionDays ?? 30);
return (
<Card className="max-h-full min-w-0">
diff --git a/frontend/src/pages/project/AuditLogsPage/components/AuditLogsRetentionSection/AuditLogsRetentionSection.tsx b/frontend/src/pages/project/AuditLogsPage/components/AuditLogsRetentionSection/AuditLogsRetentionSection.tsx
index 0c9a19e499..a4c2016115 100644
--- a/frontend/src/pages/project/AuditLogsPage/components/AuditLogsRetentionSection/AuditLogsRetentionSection.tsx
+++ b/frontend/src/pages/project/AuditLogsPage/components/AuditLogsRetentionSection/AuditLogsRetentionSection.tsx
@@ -13,6 +13,7 @@ import {
CardHeader,
CardTitle,
Field,
+ FieldDescription,
FieldError,
FieldLabel,
Input
@@ -57,6 +58,9 @@ export const AuditLogsRetentionSection = () => {
if (!currentProject) return null;
+ // A project value of 0 falls back to the plan, so under a plan with no limit it reads as unlimited.
+ const isPlanRetentionUnlimited = subscription?.auditLogsRetentionDays === null;
+
const handleAuditLogsRetentionSubmit = async ({ auditLogsRetentionDays }: TForm) => {
if (!subscription?.auditLogs) {
handlePopUpOpen("upgradePlan", {
@@ -66,7 +70,10 @@ export const AuditLogsRetentionSection = () => {
return;
}
- if (subscription && auditLogsRetentionDays > subscription?.auditLogsRetentionDays) {
+ if (
+ subscription?.auditLogsRetentionDays != null &&
+ auditLogsRetentionDays > subscription.auditLogsRetentionDays
+ ) {
handlePopUpOpen("upgradePlan", {
text: "Updating audit logs retention period to a higher value can be unlocked if you upgrade to Infisical Pro plan."
});
@@ -115,12 +122,19 @@ export const AuditLogsRetentionSection = () => {
<Input
id="audit-logs-retention-days"
{...field}
+ value={isPlanRetentionUnlimited && !field.value ? "" : field.value}
+ placeholder={isPlanRetentionUnlimited ? "Unlimited" : undefined}
type="number"
min={1}
step={1}
disabled={!canEdit}
isError={Boolean(error)}
/>
+ {isPlanRetentionUnlimited && (
+ <FieldDescription>
+ Leave empty to use your plan&apos;s retention, which has no limit.
+ </FieldDescription>
+ )}
<FieldError>{error?.message}</FieldError>
</Field>
)}
diff --git a/frontend/src/pages/secret-manager/IntegrationsDetailsByIDPage/components/IntegrationAuditLogsSection.tsx b/frontend/src/pages/secret-manager/IntegrationsDetailsByIDPage/components/IntegrationAuditLogsSection.tsx
index 3216da7b0d..adf04a9b54 100644
--- a/frontend/src/pages/secret-manager/IntegrationsDetailsByIDPage/components/IntegrationAuditLogsSection.tsx
+++ b/frontend/src/pages/secret-manager/IntegrationsDetailsByIDPage/components/IntegrationAuditLogsSection.tsx
@@ -30,7 +30,10 @@ export const IntegrationAuditLogsSection = ({ integration }: Props) => {
const { currentOrg } = useOrganization();
const { currentProject } = useProject();
- const auditLogsRetentionDays = subscription?.auditLogsRetentionDays ?? 30;
+ const auditLogsRetentionDays =
+ subscription?.auditLogsRetentionDays === null
+ ? Infinity
+ : (subscription?.auditLogsRetentionDays ?? 30);
return (
<Card className="min-w-0">
diff --git a/frontend/src/pages/secret-manager/SecretSyncDetailsByIDPage/components/SecretSyncAuditLogsSection.tsx b/frontend/src/pages/secret-manager/SecretSyncDetailsByIDPage/components/SecretSyncAuditLogsSection.tsx
index a1b94f8574..7ec1232594 100644
--- a/frontend/src/pages/secret-manager/SecretSyncDetailsByIDPage/components/SecretSyncAuditLogsSection.tsx
+++ b/frontend/src/pages/secret-manager/SecretSyncDetailsByIDPage/components/SecretSyncAuditLogsSection.tsx
@@ -44,7 +44,10 @@ export const SecretSyncAuditLogsSection = ({ secretSync }: Props) => {
const destinationName = SECRET_SYNC_MAP[secretSync.destination].name;
const permissionSubject = getSecretSyncPermissionSubject(secretSync);
- const auditLogsRetentionDays = subscription?.auditLogsRetentionDays ?? 30;
+ const auditLogsRetentionDays =
+ subscription?.auditLogsRetentionDays === null
+ ? Infinity
+ : (subscription?.auditLogsRetentionDays ?? 30);
const handleTriggerSync = async () => {
await triggerSyncSecrets.mutateAsync({