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
fix(pki): clean up stale files for records saved before hosts were tracked
bernie-g23a0ad96641d
diff --git a/backend/src/services/pki-sync/pki-sync-export-fns.test.ts b/backend/src/services/pki-sync/pki-sync-export-fns.test.tsindex fb8556f478..ba2db0af82 100644--- a/backend/src/services/pki-sync/pki-sync-export-fns.test.ts+++ b/backend/src/services/pki-sync/pki-sync-export-fns.test.ts@@ -277,14 +277,14 @@ describe("getStaleCertificateFiles", () => {).toEqual([]);});- test("returns nothing when the previous host was not recorded", () => {+ test("treats a record with no saved host as written to the current host", () => {expect(getStaleCertificateFiles({currentHost: "host-a",- previousFiles: ["/certs/app.jks"],- writtenPaths: ["/certs/other.jks"],- deliveredPaths: new Set(["/certs/other.jks"])+ previousFiles: ["/certs/app.pem", "/certs/app.key"],+ writtenPaths: ["/certs/app.jks"],+ deliveredPaths: new Set(["/certs/app.jks"])})- ).toEqual([]);+ ).toEqual(["/certs/app.pem", "/certs/app.key"]);});});diff --git a/backend/src/services/pki-sync/pki-sync-export-fns.ts b/backend/src/services/pki-sync/pki-sync-export-fns.tsindex 4f0e09750c..1e55373141 100644--- a/backend/src/services/pki-sync/pki-sync-export-fns.ts+++ b/backend/src/services/pki-sync/pki-sync-export-fns.ts@@ -23,7 +23,8 @@ export const stripUnusedKeystoreOptions = (syncOptions: Record<string, unknown>)// Files this sync wrote for a certificate last time but no longer writes, such as a truststore// after it is turned off. Paths another certificate wrote this run are left alone, and nothing is-// returned when the files were written to a different host (or one that was not recorded).+// returned when the files were written to a different host. Records from before hosts were saved+// have no host and are treated as the current one.export const getStaleCertificateFiles = ({previousFiles,previousHost,@@ -39,7 +40,7 @@ export const getStaleCertificateFiles = ({deliveredPaths: Set<string>;caseInsensitive?: boolean;}): string[] => {- if (!previousHost || !currentHost || previousHost.toLowerCase() !== currentHost.toLowerCase()) return [];+ if (previousHost && (!currentHost || previousHost.toLowerCase() !== currentHost.toLowerCase())) return [];const normalize = (filePath: string) => (caseInsensitive ? filePath.toLowerCase() : filePath);const current = new Set([...writtenPaths, ...deliveredPaths].map(normalize));return previousFiles.filter((filePath) => !current.has(normalize(filePath)));