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
Improve CaCrlRotation job to avoid invalid CRLs before the job is triggered
Carlos Monastyrski8414d8f9ca9e
diff --git a/backend/src/services/certificate-authority/certificate-authority-queue.ts b/backend/src/services/certificate-authority/certificate-authority-queue.tsindex ca75b5b3f9..930b88e8a2 100644--- a/backend/src/services/certificate-authority/certificate-authority-queue.ts+++ b/backend/src/services/certificate-authority/certificate-authority-queue.ts@@ -108,8 +108,8 @@ export const certificateAuthorityQueueFactory = ({const startCaCrlRebuildJob = async () => {const appCfg = getConfig();- // Every Sunday at midnight UTC (weekly, matching 7-day CRL validity)- const cronPattern = appCfg.NODE_ENV === "development" ? "*/5 * * * *" : "0 0 * * 0";+ // Daily at midnight UTC; only CRLs expiring before next run are rebuilt+ const cronPattern = appCfg.NODE_ENV === "development" ? "*/5 * * * *" : "0 0 * * *";// clear previous repeatable jobawait queueService.stopRepeatableJob(@@ -202,6 +202,10 @@ export const certificateAuthorityQueueFactory = ({let totalRebuilt = 0;let hasMore = true;+ // Rebuild any CRL whose validity expires before the next daily run (~24h from now)+ const nextRunAt = new Date();+ nextRunAt.setDate(nextRunAt.getDate() + 1);+while (hasMore) {const internalCas = await internalCertificateAuthorityDAL.find({}, { offset, limit: CRL_REBUILD_BATCH_SIZE });@@ -212,6 +216,17 @@ export const certificateAuthorityQueueFactory = ({for (const internalCa of internalCas) {try {+ const caCrls = await certificateAuthorityCrlDAL.find(+ { caId: internalCa.caId },+ { sort: [["updatedAt", "desc"]], limit: 1 }+ );+ if (caCrls.length === 0) continue;++ // Skip if CRL was recently rebuilt and won't expire before next run+ const crlExpiresAt = new Date(caCrls[0].updatedAt);+ crlExpiresAt.setDate(crlExpiresAt.getDate() + DEFAULT_CRL_VALIDITY_DAYS);+ if (crlExpiresAt > nextRunAt) continue;+const caSecret = await certificateAuthoritySecretDAL.findOne({ caId: internalCa.caId });const alg = keyAlgorithmToAlgCfg(internalCa.keyAlgorithm as CertKeyAlgorithm);@@ -262,7 +277,7 @@ export const certificateAuthorityQueueFactory = ({plainText: Buffer.from(new Uint8Array(crl.rawData))});- await certificateAuthorityCrlDAL.update({ caId: internalCa.caId }, { encryptedCrl });+ await certificateAuthorityCrlDAL.update({ caId: internalCa.caId }, { encryptedCrl, updatedAt: new Date() });totalRebuilt += 1;} catch (err) {logger.error(err, `${QueueName.CaCrlRotation}: failed to rebuild CRL for CA ${internalCa.caId}`);