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): skip stale-file cleanup when the original host is unknown
bernie-gcc9b2f191cc8
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 ba2db0af82..7554f65691 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,7 +277,7 @@ describe("getStaleCertificateFiles", () => {).toEqual([]);});- test("treats a record with no saved host as written to the current host", () => {+ test("returns nothing when the previous host was not recorded", () => {expect(getStaleCertificateFiles({currentHost: "host-a",@@ -285,6 +285,6 @@ describe("getStaleCertificateFiles", () => {writtenPaths: ["/certs/app.jks"],deliveredPaths: new Set(["/certs/app.jks"])})- ).toEqual(["/certs/app.pem", "/certs/app.key"]);+ ).toEqual([]);});});diff --git a/backend/src/services/pki-sync/pki-sync-export-fns.ts b/backend/src/services/pki-sync/pki-sync-export-fns.tsindex 1e55373141..f81da14330 100644--- a/backend/src/services/pki-sync/pki-sync-export-fns.ts+++ b/backend/src/services/pki-sync/pki-sync-export-fns.ts@@ -23,8 +23,7 @@ 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. Records from before hosts were saved-// have no host and are treated as the current one.+// returned unless the files are known to have been written to the current host.export const getStaleCertificateFiles = ({previousFiles,previousHost,@@ -40,7 +39,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)));