Skip to content

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

fix(pki): block jks in fips mode, gate stale-file cleanup on removal, reject unused keystore options

bernie-g63d1cc49be64
diff --git a/backend/src/services/pki-sync/linux-server/linux-server-pki-sync-fns.ts b/backend/src/services/pki-sync/linux-server/linux-server-pki-sync-fns.ts
index 727710c3c1..d09b7939c6 100644
--- a/backend/src/services/pki-sync/linux-server/linux-server-pki-sync-fns.ts
+++ b/backend/src/services/pki-sync/linux-server/linux-server-pki-sync-fns.ts
@@ -28,11 +28,15 @@ import { TSyncMetadata } from "@app/services/certificate-sync/certificate-sync-s
import { PkiSyncError } from "../pki-sync-errors";
import {
buildFileCollisionMessage,
+ buildStaleFileWarning,
exportCertificateForSync,
getStaleCertificateFiles,
+ isExportFormatBlockedByFips,
isKeystoreExportFormat,
+ JKS_FIPS_UNSUPPORTED_MESSAGE,
PemCertificateExtension,
- PkiSyncExportFormat
+ PkiSyncExportFormat,
+ splitStaleCertificateFiles
} from "../pki-sync-export-fns";
import {
buildHealthCheckCommandFailureMessage,
@@ -445,8 +449,13 @@ export const linuxServerPkiSyncFactory = ({
const certificateMode = parseFileMode(options.fileMode, CERTIFICATE_FILE_MODE);
const exportPassword = pkiSync.syncCredentials?.exportPassword;
+ if (isExportFormatBlockedByFips(format)) {
+ throw new PkiSyncError({ shouldRetry: false, message: JKS_FIPS_UNSUPPORTED_MESSAGE });
+ }
+
const failedUploads: Array<{ name: string; error: string }> = [];
const failedRemovals: Array<{ name: string; error: string }> = [];
+ const staleFileFailures: Array<{ path: string; error: string }> = [];
const skippedCertificates: Array<{ name: string; reason: string }> = [];
// Paths confirmed on the host this run. Keeps the removal pass from deleting a file a renewal
// just rewrote under the same name, and tells the post-sync command what landed.
@@ -571,19 +580,20 @@ export const linuxServerPkiSyncFactory = ({
writtenPaths,
deliveredPaths
});
+ const { filesToRemove, filesToKeep } = splitStaleCertificateFiles(staleFiles, canRemoveCertificates);
const staleFilesToRetry: string[] = [];
- for (const staleFile of staleFiles) {
+ for (const staleFile of filesToRemove) {
try {
await unlinkOrThrow(sftp, staleFile);
} catch (removeErr) {
staleFilesToRetry.push(staleFile);
- failedRemovals.push({
- name: staleFile,
+ staleFileFailures.push({
+ path: staleFile,
error: (removeErr as Error)?.message ?? "Unknown error"
});
}
}
- const removedCount = staleFiles.length - staleFilesToRetry.length;
+ const removedCount = filesToRemove.length - staleFilesToRetry.length;
if (removedCount > 0) {
logger.info(
`Linux Server PKI sync [syncId=${pkiSync.id}]: removed ${removedCount} file(s) "${baseName}" no longer uses`
@@ -591,7 +601,7 @@ export const linuxServerPkiSyncFactory = ({
}
await certificateSyncDAL.updateById(record.id, {
externalIdentifier: primaryPath,
- syncMetadata: { files: [...writtenPaths, ...staleFilesToRetry], host: targetHost }
+ syncMetadata: { files: [...writtenPaths, ...filesToKeep, ...staleFilesToRetry], host: targetHost }
});
}
}
@@ -650,6 +660,7 @@ export const linuxServerPkiSyncFactory = ({
skipped: skippedCertificates.length,
healthCheck,
postSyncCommand,
+ warningMessage: buildStaleFileWarning(staleFileFailures),
details: {
failedUploads: failedUploads.length > 0 ? failedUploads : undefined,
failedRemovals: failedRemovals.length > 0 ? failedRemovals : undefined,
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.ts
index 7554f65691..84878e83c6 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
@@ -1,12 +1,17 @@
import forge from "node-forge";
+import { crypto } from "@app/lib/crypto/cryptography";
+
import {
+ buildStaleFileWarning,
exportCertificateForSync,
getExportedCertificateFileSuffixes,
getStaleCertificateFiles,
+ getUnusedKeystoreOptionMessage,
+ isExportFormatBlockedByFips,
PemCertificateExtension,
PkiSyncExportFormat,
- stripUnusedKeystoreOptions,
+ splitStaleCertificateFiles,
TExportedCertificateFile
} from "./pki-sync-export-fns";
@@ -208,25 +213,78 @@ describe("getExportedCertificateFileSuffixes matches the real export", () => {
});
});
-describe("stripUnusedKeystoreOptions", () => {
- test("drops keystore-only options a format does not use", () => {
- const base = { keystoreAlias: "tomcat", includeTruststore: true, certificateNameSchema: "{{commonName}}" };
- expect(stripUnusedKeystoreOptions({ ...base, exportFormat: PkiSyncExportFormat.Pem })).toEqual({
- exportFormat: PkiSyncExportFormat.Pem,
- certificateNameSchema: "{{commonName}}"
- });
- expect(stripUnusedKeystoreOptions({ ...base, exportFormat: PkiSyncExportFormat.Pkcs12 })).toEqual({
- exportFormat: PkiSyncExportFormat.Pkcs12,
- keystoreAlias: "tomcat",
- certificateNameSchema: "{{commonName}}"
- });
- expect(stripUnusedKeystoreOptions({ ...base, exportFormat: PkiSyncExportFormat.Jks })).toEqual({
- ...base,
- exportFormat: PkiSyncExportFormat.Jks
+describe("getUnusedKeystoreOptionMessage", () => {
+ test("rejects keystore-only options a format does not use", () => {
+ expect(
+ getUnusedKeystoreOptionMessage({ exportFormat: PkiSyncExportFormat.Pem, keystoreAlias: "tomcat" })
+ ).toContain("keystoreAlias");
+ expect(
+ getUnusedKeystoreOptionMessage({ exportFormat: PkiSyncExportFormat.Pkcs12, includeTruststore: true })
+ ).toContain("includeTruststore");
+ });
+
+ test("accepts options that match the format", () => {
+ expect(
+ getUnusedKeystoreOptionMessage({
+ exportFormat: PkiSyncExportFormat.Jks,
+ keystoreAlias: "tomcat",
+ includeTruststore: true
+ })
+ ).toBeUndefined();
+ expect(
+ getUnusedKeystoreOptionMessage({ exportFormat: PkiSyncExportFormat.Pkcs12, keystoreAlias: "tomcat" })
+ ).toBeUndefined();
+ expect(
+ getUnusedKeystoreOptionMessage({ exportFormat: PkiSyncExportFormat.Pem, includeTruststore: false })
+ ).toBeUndefined();
+ });
+});
+
+describe("isExportFormatBlockedByFips", () => {
+ afterEach(() => {
+ vi.restoreAllMocks();
+ });
+
+ test("blocks only JKS when FIPS mode is on", () => {
+ vi.spyOn(crypto, "isFipsModeEnabled").mockReturnValue(true);
+ expect(isExportFormatBlockedByFips(PkiSyncExportFormat.Jks)).toBe(true);
+ expect(isExportFormatBlockedByFips(PkiSyncExportFormat.Pkcs12)).toBe(false);
+ expect(isExportFormatBlockedByFips(PkiSyncExportFormat.Pem)).toBe(false);
+ });
+
+ test("allows JKS when FIPS mode is off", () => {
+ vi.spyOn(crypto, "isFipsModeEnabled").mockReturnValue(false);
+ expect(isExportFormatBlockedByFips(PkiSyncExportFormat.Jks)).toBe(false);
+ });
+});
+
+describe("splitStaleCertificateFiles", () => {
+ const stale = ["/certs/app.pem", "/certs/app.key", "/certs/app.truststore.jks"];
+
+ test("removes every stale file when certificate removal is allowed", () => {
+ expect(splitStaleCertificateFiles(stale, true)).toEqual({ filesToRemove: stale, filesToKeep: [] });
+ });
+
+ test("only removes a stale truststore when certificate removal is off", () => {
+ expect(splitStaleCertificateFiles(stale, false)).toEqual({
+ filesToRemove: ["/certs/app.truststore.jks"],
+ filesToKeep: ["/certs/app.pem", "/certs/app.key"]
});
});
});
+describe("buildStaleFileWarning", () => {
+ test("returns nothing when every removal succeeded", () => {
+ expect(buildStaleFileWarning([])).toBeUndefined();
+ });
+
+ test("names the files that could not be removed", () => {
+ const warning = buildStaleFileWarning([{ path: "/certs/app.truststore.jks", error: "Permission denied" }]);
+ expect(warning).toContain("/certs/app.truststore.jks");
+ expect(warning).toContain("Permission denied");
+ });
+});
+
describe("getStaleCertificateFiles", () => {
test("returns files written last time that this run no longer writes", () => {
expect(
diff --git a/backend/src/services/pki-sync/pki-sync-export-fns.ts b/backend/src/services/pki-sync/pki-sync-export-fns.ts
index f81da14330..eaab4eb5bc 100644
--- a/backend/src/services/pki-sync/pki-sync-export-fns.ts
+++ b/backend/src/services/pki-sync/pki-sync-export-fns.ts
@@ -1,3 +1,4 @@
+import { crypto } from "@app/lib/crypto/cryptography";
import { generatePkcs12FromCertificate } from "@app/services/certificate/certificate-fns";
import {
generateJksFromCertificate,
@@ -14,13 +15,22 @@ export enum PkiSyncExportFormat {
export const isKeystoreExportFormat = (format: unknown): boolean =>
format === PkiSyncExportFormat.Pkcs12 || format === PkiSyncExportFormat.Jks;
-export const stripUnusedKeystoreOptions = (syncOptions: Record<string, unknown>): Record<string, unknown> => {
- const stripped = { ...syncOptions };
- if (!isKeystoreExportFormat(stripped.exportFormat)) delete stripped.keystoreAlias;
- if (stripped.exportFormat !== PkiSyncExportFormat.Jks) delete stripped.includeTruststore;
- return stripped;
+export const getUnusedKeystoreOptionMessage = (syncOptions: Record<string, unknown>): string | undefined => {
+ if (!isKeystoreExportFormat(syncOptions.exportFormat) && syncOptions.keystoreAlias !== undefined) {
+ return "keystoreAlias only applies when exportFormat is pkcs12 or jks. Remove it or change the export format.";
+ }
+ if (syncOptions.exportFormat !== PkiSyncExportFormat.Jks && syncOptions.includeTruststore === true) {
+ return "includeTruststore only applies when exportFormat is jks. Remove it or change the export format.";
+ }
+ return undefined;
};
+export const JKS_FIPS_UNSUPPORTED_MESSAGE =
+ "Java KeyStore (JKS) export is not supported in FIPS mode of operation. Use PEM instead.";
+
+export const isExportFormatBlockedByFips = (format: unknown): boolean =>
+ format === PkiSyncExportFormat.Jks && crypto.isFipsModeEnabled();
+
// 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 unless the files are known to have been written to the current host.
@@ -57,6 +67,27 @@ export const KEYSTORE_PASSWORD_REQUIRED_MESSAGE = "A password is required when t
export const JKS_KEYSTORE_SUFFIX = ".jks";
export const JKS_TRUSTSTORE_SUFFIX = ".truststore.jks";
+const isTruststoreFile = (filePath: string) => filePath.toLowerCase().endsWith(JKS_TRUSTSTORE_SUFFIX);
+
+// A stale truststore still grants trust, so it is always removed. Other stale files may still be read
+// by a server, so they are only removed when the sync is allowed to remove certificates.
+export const splitStaleCertificateFiles = (staleFiles: string[], canRemoveCertificates: boolean) => ({
+ filesToRemove: canRemoveCertificates ? staleFiles : staleFiles.filter(isTruststoreFile),
+ filesToKeep: canRemoveCertificates ? [] : staleFiles.filter((filePath) => !isTruststoreFile(filePath))
+});
+
+const MAX_LISTED_STALE_FILES = 3;
+
+export const buildStaleFileWarning = (failures: Array<{ path: string; error: string }>): string | undefined => {
+ if (failures.length === 0) return undefined;
+ const listed = failures
+ .slice(0, MAX_LISTED_STALE_FILES)
+ .map(({ path, error }) => `"${path}" (${error})`)
+ .join(", ");
+ const more = failures.length > MAX_LISTED_STALE_FILES ? ` and ${failures.length - MAX_LISTED_STALE_FILES} more` : "";
+ return `Could not remove ${failures.length} file(s) this sync no longer writes: ${listed}${more}. Removal will be retried on the next sync.`;
+};
+
export enum PemCertificateExtension {
Pem = "pem",
Crt = "crt"
diff --git a/backend/src/services/pki-sync/pki-sync-queue.ts b/backend/src/services/pki-sync/pki-sync-queue.ts
index 37faa443ef..af3d08e18f 100644
--- a/backend/src/services/pki-sync/pki-sync-queue.ts
+++ b/backend/src/services/pki-sync/pki-sync-queue.ts
@@ -420,6 +420,7 @@ export const pkiSyncQueueFactory = ({
? `${certSyncFailureCount} certificate(s) failed to sync to the destination`
: null,
syncResult.partialFailureMessage ?? null,
+ syncResult.warningMessage ?? null,
postSyncCommandResult?.status === PkiSyncStatus.Failed
? buildPostSyncCommandFailureMessage(postSyncCommandResult)
: null
diff --git a/backend/src/services/pki-sync/pki-sync-service.ts b/backend/src/services/pki-sync/pki-sync-service.ts
index 124fcfab95..d5f89cb043 100644
--- a/backend/src/services/pki-sync/pki-sync-service.ts
+++ b/backend/src/services/pki-sync/pki-sync-service.ts
@@ -38,10 +38,12 @@ import { TPkiSyncDALFactory } from "./pki-sync-dal";
import { HEALTH_CHECK_COMMAND_OPTION_KEY, PkiSync, PkiSyncStatus } from "./pki-sync-enums";
import {
EXPORT_PASSWORD_BLANK_MESSAGE,
+ getUnusedKeystoreOptionMessage,
isBlankExportPassword,
+ isExportFormatBlockedByFips,
isKeystoreExportFormat,
- KEYSTORE_PASSWORD_REQUIRED_MESSAGE,
- stripUnusedKeystoreOptions
+ JKS_FIPS_UNSUPPORTED_MESSAGE,
+ KEYSTORE_PASSWORD_REQUIRED_MESSAGE
} from "./pki-sync-export-fns";
import { hasAnyPkiSyncFilter, PKI_SYNC_FILTER_KINDS, PKI_SYNC_PREVIEW_PAGE_SIZE } from "./pki-sync-filter-fns";
import {
@@ -605,6 +607,14 @@ export const pkiSyncServiceFactory = ({
}
};
+ const $assertExportOptionsAllowed = (syncOptions: Record<string, unknown>) => {
+ const unusedOptionMessage = getUnusedKeystoreOptionMessage(syncOptions);
+ if (unusedOptionMessage) throw new BadRequestError({ message: unusedOptionMessage });
+ if (isExportFormatBlockedByFips(syncOptions.exportFormat)) {
+ throw new BadRequestError({ message: JKS_FIPS_UNSUPPORTED_MESSAGE });
+ }
+ };
+
const $withFilterLock = <T>(syncId: string, run: () => Promise<T>): Promise<T> =>
withPkiSyncFilterLock(keyStore, syncId, run);
@@ -690,14 +700,13 @@ export const pkiSyncServiceFactory = ({
});
const providerCapabilities = getPkiSyncProviderCapabilities(destination);
- const resolvedSyncOptions = stripUnusedKeystoreOptions(
- normalizeNewHealthCheckCommand(
- normalizeNewPostSyncCommand({
- ...providerCapabilities,
- ...syncOptions
- })
- )
+ const resolvedSyncOptions = normalizeNewHealthCheckCommand(
+ normalizeNewPostSyncCommand({
+ ...providerCapabilities,
+ ...syncOptions
+ })
);
+ $assertExportOptionsAllowed(resolvedSyncOptions);
await $assertHostCommandWrite({
destination,
@@ -930,12 +939,11 @@ export const pkiSyncServiceFactory = ({
});
}
- resolvedSyncOptions = stripUnusedKeystoreOptions(
- applyHealthCheckCommandUpdate(
- applyPostSyncCommandUpdate({ ...providerCapabilities, ...syncOptions }, storedSyncOptions?.postSyncCommand),
- storedSyncOptions?.healthCheckCommand
- )
+ resolvedSyncOptions = applyHealthCheckCommandUpdate(
+ applyPostSyncCommandUpdate({ ...providerCapabilities, ...syncOptions }, storedSyncOptions?.postSyncCommand),
+ storedSyncOptions?.healthCheckCommand
);
+ $assertExportOptionsAllowed(resolvedSyncOptions);
}
if (isConnectionChanging || isDestinationConfigChanging) {
diff --git a/backend/src/services/pki-sync/pki-sync-types.ts b/backend/src/services/pki-sync/pki-sync-types.ts
index 97766a8bbc..707f2d40dc 100644
--- a/backend/src/services/pki-sync/pki-sync-types.ts
+++ b/backend/src/services/pki-sync/pki-sync-types.ts
@@ -151,6 +151,7 @@ export type TPkiSyncSyncResult = {
validationErrors?: Array<{ name: string; error: string }>;
};
partialFailureMessage?: string;
+ warningMessage?: string;
};
export type TCreatePkiSyncDTO = {
diff --git a/backend/src/services/pki-sync/windows-server/windows-server-pki-sync-fns.ts b/backend/src/services/pki-sync/windows-server/windows-server-pki-sync-fns.ts
index 2a86fc5954..79e48154e3 100644
--- a/backend/src/services/pki-sync/windows-server/windows-server-pki-sync-fns.ts
+++ b/backend/src/services/pki-sync/windows-server/windows-server-pki-sync-fns.ts
@@ -19,11 +19,15 @@ import { TSyncMetadata } from "@app/services/certificate-sync/certificate-sync-s
import { PkiSyncError } from "../pki-sync-errors";
import {
buildFileCollisionMessage,
+ buildStaleFileWarning,
exportCertificateForSync,
getStaleCertificateFiles,
+ isExportFormatBlockedByFips,
isKeystoreExportFormat,
+ JKS_FIPS_UNSUPPORTED_MESSAGE,
PemCertificateExtension,
- PkiSyncExportFormat
+ PkiSyncExportFormat,
+ splitStaleCertificateFiles
} from "../pki-sync-export-fns";
import {
buildHealthCheckCommandFailureMessage,
@@ -323,8 +327,13 @@ export const windowsServerPkiSyncFactory = ({
const canRemoveCertificates = options.canRemoveCertificates ?? false;
const exportPassword = pkiSync.syncCredentials?.exportPassword;
+ if (isExportFormatBlockedByFips(format)) {
+ throw new PkiSyncError({ shouldRetry: false, message: JKS_FIPS_UNSUPPORTED_MESSAGE });
+ }
+
const failedUploads: Array<{ name: string; error: string }> = [];
const failedRemovals: Array<{ name: string; error: string }> = [];
+ const staleFileFailures: Array<{ path: string; error: string }> = [];
const skippedCertificates: Array<{ name: string; reason: string }> = [];
// Paths confirmed on the host this run. Keeps the removal pass from deleting a file a renewal
// just rewrote under the same name, and tells the post-sync command what landed.
@@ -429,22 +438,24 @@ export const windowsServerPkiSyncFactory = ({
deliveredPaths,
caseInsensitive: true
});
+ const { filesToRemove, filesToKeep } = splitStaleCertificateFiles(staleFiles, canRemoveCertificates);
let staleFilesToRetry: string[] = [];
- if (staleFiles.length > 0) {
+ if (filesToRemove.length > 0) {
try {
await executeWinRMGatewayOperation(
- { ...target, endpoint: WinRmRpcEndpoint.RemoveFiles, params: { paths: staleFiles } },
+ { ...target, endpoint: WinRmRpcEndpoint.RemoveFiles, params: { paths: filesToRemove } },
gatewayDeps
);
} catch (removeErr) {
// Keep tracking them so a later run can retry the delete.
- staleFilesToRetry = staleFiles;
- failedRemovals.push({ name: baseName, error: describeFailure(removeErr) });
+ staleFilesToRetry = filesToRemove;
+ const error = describeFailure(removeErr);
+ filesToRemove.forEach((staleFile) => staleFileFailures.push({ path: staleFile, error }));
}
}
await certificateSyncDAL.updateById(record.id, {
externalIdentifier: paths[0],
- syncMetadata: { files: [...paths, ...staleFilesToRetry], host: target.credentials.host }
+ syncMetadata: { files: [...paths, ...filesToKeep, ...staleFilesToRetry], host: target.credentials.host }
});
}
}
@@ -496,6 +507,7 @@ export const windowsServerPkiSyncFactory = ({
skipped: skippedCertificates.length,
healthCheck,
postSyncCommand,
+ warningMessage: buildStaleFileWarning(staleFileFailures),
details: {
failedUploads: failedUploads.length > 0 ? failedUploads : undefined,
failedRemovals: failedRemovals.length > 0 ? failedRemovals : undefined,
diff --git a/docs/documentation/platform/pki/applications/certificate-syncs/linux-server.mdx b/docs/documentation/platform/pki/applications/certificate-syncs/linux-server.mdx
index dca9687b3c..7434b309e4 100644
--- a/docs/documentation/platform/pki/applications/certificate-syncs/linux-server.mdx
+++ b/docs/documentation/platform/pki/applications/certificate-syncs/linux-server.mdx
@@ -152,6 +152,12 @@ Infisical writes a new keystore on every sync instead of adding to the file on t
Java KeyStore stores aliases in lowercase, so an alias of `Tomcat` is saved as `tomcat`. Java looks up aliases without regard to case, so configuring `Tomcat` in your server still finds the entry.
</Note>
+When you change the export format or turn off **Include Truststore**, the next sync removes a truststore it no longer writes. Other files it no longer writes, such as the `.pem` and `.key` files after a switch to Java KeyStore, are removed only when **Enable Removal of Certificates** is on. If a file can't be removed, the sync still succeeds, shows a warning, and tries again on the next sync.
+
+<Warning>
+ Java KeyStore isn't available when Infisical runs in FIPS mode, because the format can only protect private keys with cryptography that isn't FIPS-approved. Use PEM instead.
+</Warning>
+
For a certificate whose common name is `app.example.com`, synced to `/etc/ssl/certs` with the default `{{commonName}}` name schema, the delivered files are:
```text
diff --git a/docs/documentation/platform/pki/applications/certificate-syncs/windows-server.mdx b/docs/documentation/platform/pki/applications/certificate-syncs/windows-server.mdx
index 22542e11a3..788f45be12 100644
--- a/docs/documentation/platform/pki/applications/certificate-syncs/windows-server.mdx
+++ b/docs/documentation/platform/pki/applications/certificate-syncs/windows-server.mdx
@@ -161,6 +161,12 @@ Infisical writes a new keystore on every sync instead of adding to the file on t
Java KeyStore stores aliases in lowercase, so an alias of `Tomcat` is saved as `tomcat`. Java looks up aliases without regard to case, so configuring `Tomcat` in your server still finds the entry.
</Note>
+When you change the export format or turn off **Include Truststore**, the next sync removes a truststore it no longer writes. Other files it no longer writes, such as the `.pem` and `.key` files after a switch to Java KeyStore, are removed only when **Enable Removal of Certificates** is on. If a file can't be removed, the sync still succeeds, shows a warning, and tries again on the next sync.
+
+<Warning>
+ Java KeyStore isn't available when Infisical runs in FIPS mode, because the format can only protect private keys with cryptography that isn't FIPS-approved. Use PEM instead.
+</Warning>
+
For a certificate whose common name is `app.example.com`, synced to `C:\certs` with the default `{{commonName}}` name schema, the delivered files are:
```text
diff --git a/frontend/src/components/pki-syncs/PkiSyncStatusBadge.tsx b/frontend/src/components/pki-syncs/PkiSyncStatusBadge.tsx
index f019038e4b..e2f050c89d 100644
--- a/frontend/src/components/pki-syncs/PkiSyncStatusBadge.tsx
+++ b/frontend/src/components/pki-syncs/PkiSyncStatusBadge.tsx
@@ -16,7 +16,7 @@ import {
HoverCardTrigger,
TBadgeProps
} from "@app/components/v3";
-import { getPkiSyncFailureMessage } from "@app/helpers/pkiSyncs";
+import { getPkiSyncFailureMessage, getPkiSyncWarningMessage } from "@app/helpers/pkiSyncs";
import { PkiSyncStatus } from "@app/hooks/api/pkiSyncs";
type Props = {
@@ -55,6 +55,7 @@ export const PkiSyncStatusBadge = ({ status, lastSyncedAt, lastSyncMessage }: Pr
}
const failureMessage = getPkiSyncFailureMessage(status, lastSyncMessage);
+ const warningMessage = getPkiSyncWarningMessage(status, lastSyncMessage);
const badge = (
<Badge variant={variant}>
@@ -65,7 +66,7 @@ export const PkiSyncStatusBadge = ({ status, lastSyncedAt, lastSyncMessage }: Pr
if (
![PkiSyncStatus.Succeeded, PkiSyncStatus.Failed].includes(status) ||
- (!lastSyncedAt && !failureMessage)
+ (!lastSyncedAt && !failureMessage && !warningMessage)
) {
return badge;
}
@@ -88,6 +89,17 @@ export const PkiSyncStatusBadge = ({ status, lastSyncedAt, lastSyncMessage }: Pr
</div>
</div>
)}
+ {warningMessage && (
+ <div>
+ <div className="mb-2 flex items-center gap-1.5 self-start text-warning">
+ <AlertTriangleIcon className="size-3" />
+ <div className="text-xs">Warning</div>
+ </div>
+ <div className="rounded-sm bg-surface-active p-2 text-xs break-words">
+ {warningMessage}
+ </div>
+ </div>
+ )}
{failureMessage && (
<div>
<div className="mb-2 flex items-center gap-1.5 self-start text-danger">
diff --git a/frontend/src/components/pki-syncs/forms/CreatePkiSyncForm.tsx b/frontend/src/components/pki-syncs/forms/CreatePkiSyncForm.tsx
index adfbb05df7..96ea6e90fd 100644
--- a/frontend/src/components/pki-syncs/forms/CreatePkiSyncForm.tsx
+++ b/frontend/src/components/pki-syncs/forms/CreatePkiSyncForm.tsx
@@ -45,7 +45,11 @@ import {
import { KEYSTORE_PASSWORD_REQUIRED_MESSAGE } from "./schemas/base-pki-sync-schema";
import { KEMP_DEFAULT_CA_NAME_SCHEMA } from "./schemas/kemp-loadmaster-pki-sync-destination-schema";
-import { PkiSyncFormSchema, TPkiSyncForm } from "./schemas/pki-sync-schema";
+import {
+ PkiSyncFormSchema,
+ removeUnusedKeystoreOptions,
+ TPkiSyncForm
+} from "./schemas/pki-sync-schema";
import { PkiSyncCertificatesFields } from "./PkiSyncCertificatesFields";
import { PkiSyncDestinationFields } from "./PkiSyncDestinationFields";
import { PkiSyncDetailsFields } from "./PkiSyncDetailsFields";
@@ -260,7 +264,7 @@ export const CreatePkiSyncForm = ({
const onSubmit = async ({ connection, destinationConfig, ...formData }: TPkiSyncForm) => {
try {
const pkiSync = await createPkiSync.mutateAsync({
- ...formData,
+ ...removeUnusedKeystoreOptions(formData),
connectionId: connection.id,
projectId: currentProject.id,
applicationId,
diff --git a/frontend/src/components/pki-syncs/forms/EditPkiSyncForm.tsx b/frontend/src/components/pki-syncs/forms/EditPkiSyncForm.tsx
index c4c36879c4..3f4eb29785 100644
--- a/frontend/src/components/pki-syncs/forms/EditPkiSyncForm.tsx
+++ b/frontend/src/components/pki-syncs/forms/EditPkiSyncForm.tsx
@@ -38,7 +38,11 @@ import {
} from "@app/hooks/api/pkiSyncs";
import { TPkiSyncFilterPreview } from "@app/hooks/api/pkiSyncs/types";
-import { TUpdatePkiSyncForm, UpdatePkiSyncFormSchema } from "./schemas/pki-sync-schema";
+import {
+ removeUnusedKeystoreOptions,
+ TUpdatePkiSyncForm,
+ UpdatePkiSyncFormSchema
+} from "./schemas/pki-sync-schema";
import { PkiSyncCertificatesFields } from "./PkiSyncCertificatesFields";
import { PkiSyncDestinationFields } from "./PkiSyncDestinationFields";
import { PkiSyncDetailsFields } from "./PkiSyncDetailsFields";
@@ -249,7 +253,7 @@ export const EditPkiSyncForm = ({
try {
const updatedPkiSync = await updatePkiSync.mutateAsync({
syncId: pkiSync.id,
- ...formData,
+ ...removeUnusedKeystoreOptions(formData),
...(hasNewExportPassword ? {} : { credentials: undefined }),
connectionId: connection.id,
projectId: pkiSync.projectId,
diff --git a/frontend/src/components/pki-syncs/forms/PkiSyncOptionsFields/ServerExportFormatFields.tsx b/frontend/src/components/pki-syncs/forms/PkiSyncOptionsFields/ServerExportFormatFields.tsx
index b95c79e8e7..1c7478d457 100644
--- a/frontend/src/components/pki-syncs/forms/PkiSyncOptionsFields/ServerExportFormatFields.tsx
+++ b/frontend/src/components/pki-syncs/forms/PkiSyncOptionsFields/ServerExportFormatFields.tsx
@@ -2,6 +2,9 @@ import { Controller, useFormContext } from "react-hook-form";
import { Info } from "lucide-react";
import {
+ Alert,
+ AlertDescription,
+ AlertTitle,
Field,
FieldContent,
FieldDescription,
@@ -19,6 +22,7 @@ import {
TooltipContent,
TooltipTrigger
} from "@app/components/v3";
+import { useServerConfig } from "@app/context";
import {
isKeystoreExportFormat,
PemCertificateExtension,
@@ -34,8 +38,10 @@ type Props = {
export const ServerExportFormatFields = ({ isUpdate }: Props) => {
const { control, watch } = useFormContext<TPkiSyncForm>();
+ const { config } = useServerConfig();
const exportFormat = watch("syncOptions.exportFormat");
const isKeystore = isKeystoreExportFormat(exportFormat);
+ const isJksBlockedByFips = Boolean(config.fipsEnabled);
const keystoreLabel = exportFormat === PkiSyncExportFormat.Jks ? "JKS" : "PKCS#12";
const keystoreFile = exportFormat === PkiSyncExportFormat.Jks ? ".jks keystore" : ".pfx bundle";
@@ -68,14 +74,35 @@ export const ServerExportFormatFields = ({ isUpdate }: Props) => {
<SelectValue />
</SelectTrigger>
<SelectContent position="popper">
- {Object.values(PkiSyncExportFormat).map((format) => (
- <SelectItem key={format} value={format}>
- {PKI_SYNC_EXPORT_FORMAT_LABELS[format]}
- </SelectItem>
- ))}
+ {Object.values(PkiSyncExportFormat).map((format) => {
+ const isDisabled = format === PkiSyncExportFormat.Jks && isJksBlockedByFips;
+ return (
+ <SelectItem
+ key={format}
+ value={format}
+ disabled={isDisabled}
+ description={isDisabled ? "Not available in FIPS mode" : undefined}
+ >
+ {PKI_SYNC_EXPORT_FORMAT_LABELS[format]}
+ </SelectItem>
+ );
+ })}
</SelectContent>
</Select>
<FieldError errors={[error]} />
+ {value === PkiSyncExportFormat.Jks && isJksBlockedByFips && (
+ <Alert variant="warning">
+ <Info />
+ <AlertTitle className="line-clamp-none">
+ JKS isn&apos;t available in FIPS mode
+ </AlertTitle>
+ <AlertDescription>
+ The JKS format can only protect private keys with cryptography that is not
+ FIPS-approved, so this sync will not deliver certificates. Switch the export
+ format to PEM.
+ </AlertDescription>
+ </Alert>
+ )}
</Field>
)}
/>
diff --git a/frontend/src/components/pki-syncs/forms/schemas/linux-server-pki-sync-destination-schema.ts b/frontend/src/components/pki-syncs/forms/schemas/linux-server-pki-sync-destination-schema.ts
index c87e8d15c0..ee3b7af91f 100644
--- a/frontend/src/components/pki-syncs/forms/schemas/linux-server-pki-sync-destination-schema.ts
+++ b/frontend/src/components/pki-syncs/forms/schemas/linux-server-pki-sync-destination-schema.ts
@@ -5,7 +5,6 @@ import { PemCertificateExtension, PkiSync, PkiSyncExportFormat } from "@app/hook
import {
BasePkiSyncSchema,
HostCommandSchema,
- KeystoreAliasSchema,
PkiSyncConnectionSchema,
PkiSyncTargetHostSchema,
PkiSyncTargetPortSchema
@@ -28,7 +27,7 @@ const LinuxServerSyncOptionsSchema = z.object({
.nativeEnum(PemCertificateExtension)
.default(PemCertificateExtension.Pem),
combineCertificateChain: z.boolean().default(false),
- keystoreAlias: KeystoreAliasSchema,
+ keystoreAlias: z.string().optional(),
includeTruststore: z.boolean().optional(),
includePrivateKey: z.boolean().default(true),
fileMode: z
diff --git a/frontend/src/components/pki-syncs/forms/schemas/pki-sync-schema.ts b/frontend/src/components/pki-syncs/forms/schemas/pki-sync-schema.ts
index d7f573968c..12905d9e29 100644
--- a/frontend/src/components/pki-syncs/forms/schemas/pki-sync-schema.ts
+++ b/frontend/src/components/pki-syncs/forms/schemas/pki-sync-schema.ts
@@ -20,7 +20,11 @@ import {
AzureKeyVaultPkiSyncDestinationSchema,
UpdateAzureKeyVaultPkiSyncDestinationSchema
} from "./azure-key-vault-pki-sync-destination-schema";
-import { ExportPasswordSchema, KEYSTORE_PASSWORD_REQUIRED_MESSAGE } from "./base-pki-sync-schema";
+import {
+ ExportPasswordSchema,
+ KEYSTORE_PASSWORD_REQUIRED_MESSAGE,
+ KeystoreAliasSchema
+} from "./base-pki-sync-schema";
import {
ChefPkiSyncDestinationSchema,
UpdateChefPkiSyncDestinationSchema
@@ -139,6 +143,44 @@ const refineExportPassword = (
}
};
+// The alias is kept while switching formats, so it is only validated when a keystore format uses it.
+const refineKeystoreAlias = (
+ data: { destination: PkiSync; syncOptions?: unknown },
+ ctx: z.RefinementCtx
+) => {
+ const { exportFormat, keystoreAlias } = (data.syncOptions ?? {}) as {
+ exportFormat?: PkiSyncExportFormat;
+ keystoreAlias?: string;
+ };
+ if (
+ !isServerDestination(data.destination) ||
+ !keystoreAlias ||
+ !isKeystoreExportFormat(exportFormat)
+ )
+ return;
+ const result = KeystoreAliasSchema.safeParse(keystoreAlias);
+ if (!result.success) {
+ ctx.addIssue({
+ code: z.ZodIssueCode.custom,
+ path: ["syncOptions", "keystoreAlias"],
+ message: result.error.issues[0]?.message ?? "Invalid keystore alias"
+ });
+ }
+};
+
+// Drops keystore options the chosen format does not use, since the API rejects them.
+export const removeUnusedKeystoreOptions = <T extends { syncOptions?: unknown }>(data: T): T => {
+ if (!data.syncOptions) return data;
+ const syncOptions = { ...(data.syncOptions as Record<string, unknown>) };
+ const alias =
+ typeof syncOptions.keystoreAlias === "string" ? syncOptions.keystoreAlias.trim() : "";
+ const exportFormat = syncOptions.exportFormat as PkiSyncExportFormat | undefined;
+ if (!isKeystoreExportFormat(exportFormat) || !alias) delete syncOptions.keystoreAlias;
+ else syncOptions.keystoreAlias = alias;
+ if (exportFormat !== PkiSyncExportFormat.Jks) delete syncOptions.includeTruststore;
+ return { ...data, syncOptions };
+};
+
export const PkiSyncFormSchema = PkiSyncUnionSchema.superRefine((data, ctx) => {
if (
data.destination === PkiSync.GcpCertificateManager &&
@@ -165,11 +207,13 @@ export const PkiSyncFormSchema = PkiSyncUnionSchema.superRefine((data, ctx) => {
}
refineExportPassword(data, ctx);
+ refineKeystoreAlias(data, ctx);
refineTargetHost(data, ctx);
});
export const UpdatePkiSyncFormSchema = UpdatePkiSyncUnionSchema.superRefine((data, ctx) => {
refineExportPassword(data, ctx);
+ refineKeystoreAlias(data, ctx);
refineTargetHost(data, ctx);
});
diff --git a/frontend/src/components/pki-syncs/forms/schemas/windows-server-pki-sync-destination-schema.ts b/frontend/src/components/pki-syncs/forms/schemas/windows-server-pki-sync-destination-schema.ts
index ab94f0cb90..26c5643e41 100644
--- a/frontend/src/components/pki-syncs/forms/schemas/windows-server-pki-sync-destination-schema.ts
+++ b/frontend/src/components/pki-syncs/forms/schemas/windows-server-pki-sync-destination-schema.ts
@@ -10,7 +10,6 @@ import {
import {
BasePkiSyncSchema,
HostCommandSchema,
- KeystoreAliasSchema,
PkiSyncConnectionSchema,
PkiSyncTargetHostSchema,
PkiSyncTargetPortSchema
@@ -31,7 +30,7 @@ const WindowsServerSyncOptionsSchema = z.object({
.nativeEnum(PemCertificateExtension)
.default(PemCertificateExtension.Pem),
combineCertificateChain: z.boolean().default(false),
- keystoreAlias: KeystoreAliasSchema,
+ keystoreAlias: z.string().optional(),
includeTruststore: z.boolean().optional(),
fileAccessRules: z
.array(
diff --git a/frontend/src/helpers/pkiSyncs.ts b/frontend/src/helpers/pkiSyncs.ts
index 09ec299648..6c378ce899 100644
--- a/frontend/src/helpers/pkiSyncs.ts
+++ b/frontend/src/helpers/pkiSyncs.ts
@@ -233,3 +233,9 @@ export const getPkiSyncFailureMessage = (
return message;
}
};
+
+// A sync that succeeded can still carry a message, such as files it could not clean up.
+export const getPkiSyncWarningMessage = (
+ status: PkiSyncStatus | null | undefined,
+ message: string | null | undefined
+): string | null => (status === PkiSyncStatus.Succeeded && message ? message : null);
diff --git a/frontend/src/pages/cert-manager/PkiSyncDetailsByIDPage/components/PkiSyncDetailsSection.tsx b/frontend/src/pages/cert-manager/PkiSyncDetailsByIDPage/components/PkiSyncDetailsSection.tsx
index b476f0c6e2..079f8b5d73 100644
--- a/frontend/src/pages/cert-manager/PkiSyncDetailsByIDPage/components/PkiSyncDetailsSection.tsx
+++ b/frontend/src/pages/cert-manager/PkiSyncDetailsByIDPage/components/PkiSyncDetailsSection.tsx
@@ -3,7 +3,7 @@ import { BanIcon, RefreshCwIcon } from "lucide-react";
import { PkiSyncStatusBadge } from "@app/components/pki-syncs";
import { Badge, Detail, DetailLabel, DetailValue } from "@app/components/v3";
-import { getPkiSyncFailureMessage } from "@app/helpers/pkiSyncs";
+import { getPkiSyncFailureMessage, getPkiSyncWarningMessage } from "@app/helpers/pkiSyncs";
import { TPkiSync } from "@app/hooks/api/pkiSyncs";
import { SyncErrorDetail } from "./SyncErrorDetail";
@@ -16,6 +16,7 @@ export const PkiSyncDetailsSection = ({ pkiSync }: Props) => {
const { syncStatus, lastSyncMessage, lastSyncedAt, isAutoSyncEnabled } = pkiSync;
const failureMessage = getPkiSyncFailureMessage(syncStatus, lastSyncMessage);
+ const warningMessage = getPkiSyncWarningMessage(syncStatus, lastSyncMessage);
return (
<>
@@ -50,6 +51,9 @@ export const PkiSyncDetailsSection = ({ pkiSync }: Props) => {
</Detail>
)}
{failureMessage && <SyncErrorDetail label="Last Sync Error" message={failureMessage} />}
+ {warningMessage && (
+ <SyncErrorDetail label="Last Sync Warning" message={warningMessage} variant="warning" />
+ )}
</>
);
};
diff --git a/frontend/src/pages/cert-manager/PkiSyncDetailsByIDPage/components/SyncErrorDetail.tsx b/frontend/src/pages/cert-manager/PkiSyncDetailsByIDPage/components/SyncErrorDetail.tsx
index c2e99e0fb2..dd1f23b626 100644
--- a/frontend/src/pages/cert-manager/PkiSyncDetailsByIDPage/components/SyncErrorDetail.tsx
+++ b/frontend/src/pages/cert-manager/PkiSyncDetailsByIDPage/components/SyncErrorDetail.tsx
@@ -3,11 +3,14 @@ import { Detail, DetailLabel, DetailValue } from "@app/components/v3";
type Props = {
label: string;
message: string;
+ variant?: "danger" | "warning";
};
-export const SyncErrorDetail = ({ label, message }: Props) => (
+export const SyncErrorDetail = ({ label, message, variant = "danger" }: Props) => (
<Detail>
- <DetailLabel className="text-danger">{label}</DetailLabel>
+ <DetailLabel className={variant === "warning" ? "text-warning" : "text-danger"}>
+ {label}
+ </DetailLabel>
<DetailValue>
<p className="rounded-sm bg-surface-active p-2 text-xs break-words">{message}</p>
</DetailValue>