Skip to content

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

feat: add new daily cron jobs for secret version, snapshot, and audit log cleanup

Victor Hugo dos Santos064f6bf68823
diff --git a/backend/src/lib/cron/cron-job.ts b/backend/src/lib/cron/cron-job.ts
index b087339cbd..3640f0bf0b 100644
--- a/backend/src/lib/cron/cron-job.ts
+++ b/backend/src/lib/cron/cron-job.ts
@@ -12,6 +12,9 @@ export const CronJobName = {
HealthAlert: "health-alert",
DailyReminders: "daily-reminders",
DailyResourceCleanup: "daily-resource-cleanup",
+ DailySecretVersionCleanup: "daily-secret-version-cleanup",
+ DailySnapshotCleanup: "daily-snapshot-cleanup",
+ DailyAuditLogCleanup: "daily-audit-log-cleanup",
DailyResourceNotification: "daily-resource-notification",
FrequentResourceCleanup: "frequent-resource-cleanup",
CertificateCleanup: "certificate-cleanup",
diff --git a/backend/src/services/resource-cleanup/resource-cleanup-queue.ts b/backend/src/services/resource-cleanup/resource-cleanup-queue.ts
index 39438a27a3..777df64304 100644
--- a/backend/src/services/resource-cleanup/resource-cleanup-queue.ts
+++ b/backend/src/services/resource-cleanup/resource-cleanup-queue.ts
@@ -75,36 +75,76 @@ export const dailyResourceCleanUpQueueServiceFactory = ({
}
const init = () => {
- const dailyCleanupTimeoutMs = appCfg.isDailyResourceCleanUpDevelopmentMode ? 5 * 60_000 : 45 * 60_000;
- const dailyNotificationTimeoutMs = appCfg.isDailyResourceCleanUpDevelopmentMode ? 5 * 60_000 : 15 * 60_000;
- const frequentCleanupTimeoutMs = appCfg.isDailyResourceCleanUpDevelopmentMode ? 5 * 60_000 : 10 * 60_000;
+ const devMode = appCfg.isDailyResourceCleanUpDevelopmentMode;
+
+ const heavyCleanupTimeoutMs = devMode ? 5 * 60_000 : 45 * 60_000;
+ const lightCleanupTimeoutMs = devMode ? 5 * 60_000 : 15 * 60_000;
+ const dailyNotificationTimeoutMs = devMode ? 5 * 60_000 : 15 * 60_000;
+ const frequentCleanupTimeoutMs = devMode ? 5 * 60_000 : 10 * 60_000;
+
cronJob.register({
name: CronJobName.DailyResourceCleanup,
- pattern: appCfg.isDailyResourceCleanUpDevelopmentMode ? "*/5 * * * *" : "0 0 * * *",
+ pattern: devMode ? "*/5 * * * *" : "30 0 * * *",
runHashTtlS: 3 * 24 * 60 * 60,
- handlerTimeoutMs: dailyCleanupTimeoutMs,
- leaseDurationMs: dailyCleanupTimeoutMs,
+ handlerTimeoutMs: lightCleanupTimeoutMs,
+ leaseDurationMs: lightCleanupTimeoutMs,
enabled: !appCfg.isSecondaryInstance,
handler: async () => {
logger.info(`cron[${CronJobName.DailyResourceCleanup}]: task started`);
await identityUniversalAuthClientSecretDAL.removeExpiredClientSecrets();
await secretSharingDAL.pruneExpiredSharedSecrets();
await secretSharingDAL.pruneExpiredSecretRequests();
- await snapshotDAL.pruneExcessSnapshots();
- await secretVersionDAL.pruneExcessVersions();
- await secretVersionV2DAL.pruneExcessVersions();
- await secretFolderVersionDAL.pruneExcessVersions();
await userNotificationDAL.pruneNotifications();
await keyValueStoreDAL.pruneExpiredKeys();
await scepTransactionDAL.pruneExpiredTransactions();
await identityAccessTokenRevocationDAL.removeExpiredRevocations();
+ }
+ });
+
+ cronJob.register({
+ name: CronJobName.DailySecretVersionCleanup,
+ pattern: devMode ? "*/5 * * * *" : "30 1 * * *",
+ runHashTtlS: 3 * 24 * 60 * 60,
+ handlerTimeoutMs: heavyCleanupTimeoutMs,
+ leaseDurationMs: heavyCleanupTimeoutMs,
+ enabled: !appCfg.isSecondaryInstance,
+ handler: async () => {
+ logger.info(`cron[${CronJobName.DailySecretVersionCleanup}]: task started`);
+ await secretVersionDAL.pruneExcessVersions();
+ await secretVersionV2DAL.pruneExcessVersions();
+ await secretFolderVersionDAL.pruneExcessVersions();
+ }
+ });
+
+ cronJob.register({
+ name: CronJobName.DailySnapshotCleanup,
+ pattern: devMode ? "*/5 * * * *" : "30 2 * * *",
+ runHashTtlS: 3 * 24 * 60 * 60,
+ handlerTimeoutMs: heavyCleanupTimeoutMs,
+ leaseDurationMs: heavyCleanupTimeoutMs,
+ enabled: !appCfg.isSecondaryInstance,
+ handler: async () => {
+ logger.info(`cron[${CronJobName.DailySnapshotCleanup}]: task started`);
+ await snapshotDAL.pruneExcessSnapshots();
+ }
+ });
+
+ cronJob.register({
+ name: CronJobName.DailyAuditLogCleanup,
+ pattern: devMode ? "*/5 * * * *" : "30 3 * * *",
+ runHashTtlS: 3 * 24 * 60 * 60,
+ handlerTimeoutMs: heavyCleanupTimeoutMs,
+ leaseDurationMs: heavyCleanupTimeoutMs,
+ enabled: !appCfg.isSecondaryInstance,
+ handler: async () => {
+ logger.info(`cron[${CronJobName.DailyAuditLogCleanup}]: task started`);
await auditLogDAL.pruneAuditLog();
}
});
cronJob.register({
name: CronJobName.DailyResourceNotification,
- pattern: appCfg.isDailyResourceCleanUpDevelopmentMode ? "*/5 * * * *" : "0 0 * * *",
+ pattern: devMode ? "*/5 * * * *" : "0 0 * * *",
runHashTtlS: 3 * 24 * 60 * 60,
handlerTimeoutMs: dailyNotificationTimeoutMs,
leaseDurationMs: dailyNotificationTimeoutMs,
@@ -120,7 +160,7 @@ export const dailyResourceCleanUpQueueServiceFactory = ({
cronJob.register({
name: CronJobName.FrequentResourceCleanup,
- pattern: appCfg.isDailyResourceCleanUpDevelopmentMode ? "*/5 * * * *" : "0 * * * *",
+ pattern: devMode ? "*/5 * * * *" : "0 * * * *",
runHashTtlS: 1 * 24 * 60 * 60,
enabled: !appCfg.isSecondaryInstance,
handlerTimeoutMs: frequentCleanupTimeoutMs,