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): mark an undeployed imperva certificate failed
bernie-g6c68dc35e8f9
diff --git a/backend/src/services/pki-sync/imperva/imperva-pki-sync-fns.test.ts b/backend/src/services/pki-sync/imperva/imperva-pki-sync-fns.test.tsindex 2c841cecf4..798f34429c 100644--- a/backend/src/services/pki-sync/imperva/imperva-pki-sync-fns.test.ts+++ b/backend/src/services/pki-sync/imperva/imperva-pki-sync-fns.test.ts@@ -311,3 +311,53 @@ describe("Imperva slot ownership", () => {expect(removeCertificatesFromDal).toHaveBeenCalledWith("sync-1", ["cert-old"]);});});++describe("Imperva deployment mismatch", () => {+ test("reports the certificate as not deployed instead of succeeded", async () => {+ const { impervaPkiSyncFactory } = await import("./imperva-pki-sync-fns");++ impervaRequest.mockReset();+ impervaRequest.mockImplementation((args: unknown) => {+ const { method } = args as TRecordedRequest;+ if (method === "GET") {+ return Promise.resolve({+ data: [{ authType: ImpervaCertificateAuthType.Rsa, customCertificateDetails: { hasMismatchSite: true } }]+ });+ }+ return Promise.resolve({});+ });++ const updateById = vi.fn();+ const factory = impervaPkiSyncFactory({+ certificateSyncDAL: {+ findByPkiSyncId: vi.fn().mockResolvedValue([]),+ removeCertificates: vi.fn(),+ addCertificates: vi.fn(),+ findByPkiSyncAndCertificate: vi.fn().mockResolvedValue({ id: "row-1" }),+ updateById,+ updateSyncStatus: vi.fn(),+ findExternalIdentifiersInUse: vi.fn().mockResolvedValue(new Set<string>()),+ claimExternalIdentifier: vi.fn()+ } as never,+ certificateDAL: { findById: vi.fn().mockResolvedValue(undefined) } as never+ });++ const result = await factory.syncCertificates(+ {+ id: "sync-1",+ destination: "imperva",+ projectId: "project-1",+ destinationConfig: { siteId: "111", siteName: "waf.example.com" },+ syncOptions: { canRemoveCertificates: true },+ connection: { credentials: { apiId: "id", apiKey: "key" }, gatewayId: null, gatewayPoolId: null }+ } as never,+ { leaf: { cert: RSA_CERT_PEM, privateKey: "key", certificateId: "cert-1" } } as never+ );++ expect(result.details?.failedUploads).toEqual([+ { name: "leaf", error: expect.stringContaining("does not cover every managed domain") as unknown as string }+ ]);+ expect(result.partialFailureMessage).toContain("does not cover every managed domain");+ expect(updateById.mock.calls[0][1]).toMatchObject({ syncStatus: "failed" });+ });+});diff --git a/backend/src/services/pki-sync/imperva/imperva-pki-sync-fns.ts b/backend/src/services/pki-sync/imperva/imperva-pki-sync-fns.tsindex c8ef7d44cb..661b42fbb5 100644--- a/backend/src/services/pki-sync/imperva/imperva-pki-sync-fns.ts+++ b/backend/src/services/pki-sync/imperva/imperva-pki-sync-fns.ts@@ -297,6 +297,8 @@ export const impervaPkiSyncFactory = ({const { certificate, skippedCertificates } = await prepareCertificate(certificateMap);const failedUploads: Array<{ name: string; error: string }> = [];+ // Uploaded but not served. Reported per certificate so its row does not read Succeeded.+ const undeployedCertificates: Array<{ name: string; error: string }> = [];const failedRemovals: Array<{ name: string; error: string }> = [];const occupiedSlots = new Set<string>();let deploymentWarning = "";@@ -340,6 +342,9 @@ export const impervaPkiSyncFactory = ({uploaded += 1;deploymentWarning = await buildDeploymentWarning(makeRequest, credentials, siteId, authType);+ if (deploymentWarning) {+ undeployedCertificates.push({ name: certificate.certName, error: deploymentWarning });+ }if (certificate.certificateId) {activeCertificateIds.add(certificate.certificateId);@@ -352,8 +357,9 @@ export const impervaPkiSyncFactory = ({if (existingCertSync) {await certificateSyncDAL.updateById(existingCertSync.id, {externalIdentifier,- syncStatus: CertificateSyncStatus.Succeeded,- lastSyncMessage: `Synced ${authType} custom certificate to Imperva site ${siteLabel}`,+ syncStatus: deploymentWarning ? CertificateSyncStatus.Failed : CertificateSyncStatus.Succeeded,+ lastSyncMessage:+ deploymentWarning || `Synced ${authType} custom certificate to Imperva site ${siteLabel}`,lastSyncedAt: new Date()});} else {@@ -469,6 +475,7 @@ export const impervaPkiSyncFactory = ({skipped: skippedCertificates.length,partialFailureMessage: deploymentWarning || undefined,details: {+ failedUploads: undeployedCertificates.length > 0 ? undeployedCertificates : undefined,failedRemovals: failedRemovals.length > 0 ? failedRemovals : undefined,skippedCertificates: skippedCertificates.length > 0 ? skippedCertificates : undefined}