Skip to content

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

Addressed PR comments

Carlos Monastyrski5ada791395aa
diff --git a/backend/src/services/certificate-authority/ca-key-source/hsm-ca-key-source.test.ts b/backend/src/services/certificate-authority/ca-key-source/hsm-ca-key-source.test.ts
index 268b7e85d0..1b0aff7acd 100644
--- a/backend/src/services/certificate-authority/ca-key-source/hsm-ca-key-source.test.ts
+++ b/backend/src/services/certificate-authority/ca-key-source/hsm-ca-key-source.test.ts
@@ -87,7 +87,7 @@ describe("HSM CA key source", () => {
keyAlgorithm: CertKeyAlgorithm.ML_DSA_44,
input: { hsmConnectorId: "connector" }
})
- ).rejects.toThrow(/could not create an ML-DSA-44 key\. Update the Gateway to v0\.44\.10 or later/);
+ ).rejects.toThrow(/slot does not support ML-DSA-44 keys/);
});
test("ML-DSA certificates signed through the HSM with CKM_ML_DSA verify against the HSM public key", async ({
diff --git a/backend/src/services/certificate-authority/ca-key-source/hsm-ca-key-source.ts b/backend/src/services/certificate-authority/ca-key-source/hsm-ca-key-source.ts
index 0a41d1fe06..cbe8b3cff4 100644
--- a/backend/src/services/certificate-authority/ca-key-source/hsm-ca-key-source.ts
+++ b/backend/src/services/certificate-authority/ca-key-source/hsm-ca-key-source.ts
@@ -7,10 +7,7 @@ import { isPkcs11Error, Pkcs11ErrorCode } from "@app/lib/gateway-v2/pkcs11-rpc";
import { alphaNumericNanoId } from "@app/lib/nanoid";
import { CertKeyAlgorithm } from "@app/services/certificate/certificate-types";
import { THsmConnectorDALFactory } from "@app/services/hsm-connector/hsm-connector-dal";
-import {
- certKeyAlgorithmToHsmKeyAlgorithm,
- HSM_ML_DSA_MIN_GATEWAY_VERSION
-} from "@app/services/hsm-connector/hsm-connector-fns";
+import { certKeyAlgorithmToHsmKeyAlgorithm } from "@app/services/hsm-connector/hsm-connector-fns";
import { THsmConnectorServiceFactory } from "@app/services/hsm-connector/hsm-connector-service";
import {
@@ -74,7 +71,7 @@ export const hsmCaKeySourceFactory = ({
.catch((err: unknown) => {
if (isPqcAlgorithm(keyAlgorithm) && isPkcs11Error(err, Pkcs11ErrorCode.MechanismInvalid)) {
throw new BadRequestError({
- message: `The HSM Connector could not create an ${keyAlgorithm} key. Update the Gateway to ${HSM_ML_DSA_MIN_GATEWAY_VERSION} or later and check that your HSM's PKCS#11 driver supports ML-DSA.`
+ message: `The HSM Connector's slot does not support ${keyAlgorithm} keys. Check that your HSM's PKCS#11 driver supports ML-DSA on this slot.`
});
}
throw err;
diff --git a/backend/src/services/hsm-connector/hsm-connector-fns.ts b/backend/src/services/hsm-connector/hsm-connector-fns.ts
index 686eb2fa2b..01e9758847 100644
--- a/backend/src/services/hsm-connector/hsm-connector-fns.ts
+++ b/backend/src/services/hsm-connector/hsm-connector-fns.ts
@@ -23,8 +23,6 @@ export enum HsmGatewayCapability {
MlDsa = "pkcs11MlDsa"
}
-export const HSM_ML_DSA_MIN_GATEWAY_VERSION = "v0.44.10";
-
const HSM_KEY_ALGORITHM_BY_CERT_KEY_ALGORITHM: Partial<Record<string, HsmKeyAlgorithm>> = {
[CertKeyAlgorithm.RSA_2048]: HsmKeyAlgorithm.RSA_2048,
[CertKeyAlgorithm.RSA_3072]: HsmKeyAlgorithm.RSA_3072,
diff --git a/backend/src/services/hsm-connector/hsm-connector-routing.test.ts b/backend/src/services/hsm-connector/hsm-connector-routing.test.ts
index 5d3831e397..197683681d 100644
--- a/backend/src/services/hsm-connector/hsm-connector-routing.test.ts
+++ b/backend/src/services/hsm-connector/hsm-connector-routing.test.ts
@@ -72,11 +72,22 @@ describe("HSM Connector routing", () => {
expect(getPlatformConnectionDetailsByGatewayId.mock.calls[0][0]).toMatchObject({ gatewayId: "new-gateway" });
});
- test("explains a pool with no member that supports ML-DSA", async () => {
- const { routing } = buildRouting([{ id: "old-gateway", capabilities: { pkcs11: true } }]);
+ test("asks to update a pool whose members predate ML-DSA support", async () => {
+ const { routing } = buildRouting([
+ { id: "old-gateway", capabilities: { pkcs11: true } },
+ { id: "current-gateway", capabilities: { pkcs11: true, pkcs11MlDsa: false } }
+ ]);
+
+ await expect(signThroughPool(routing, HsmGatewayCapability.MlDsa)).rejects.toThrow(
+ /Update the pool's gateways to the latest version/
+ );
+ });
+
+ test("blames the HSMs when every current pool member reports no ML-DSA support", async () => {
+ const { routing } = buildRouting([{ id: "current-gateway", capabilities: { pkcs11: true, pkcs11MlDsa: false } }]);
await expect(signThroughPool(routing, HsmGatewayCapability.MlDsa)).rejects.toThrow(
- /No HSM-capable gateway in the pool supports ML-DSA keys/
+ /None of the HSMs attached to the pool's gateways support ML-DSA keys/
);
});
@@ -95,7 +106,18 @@ describe("HSM Connector routing", () => {
await expect(
signThroughPool(routing, HsmGatewayCapability.MlDsa, { gatewayId: "old-gateway", gatewayPoolId: null })
- ).rejects.toThrow(/The HSM Connector's gateway does not support ML-DSA keys/);
+ ).rejects.toThrow(/Update the gateway to the latest version/);
+ expect(getPlatformConnectionDetailsByGatewayId).not.toHaveBeenCalled();
+ });
+
+ test("a current single gateway whose HSM lacks ML-DSA is refused with an HSM error", async () => {
+ const { routing, getPlatformConnectionDetailsByGatewayId } = buildRouting([
+ { id: "current-gateway", capabilities: { pkcs11: true, pkcs11MlDsa: false } }
+ ]);
+
+ await expect(
+ signThroughPool(routing, HsmGatewayCapability.MlDsa, { gatewayId: "current-gateway", gatewayPoolId: null })
+ ).rejects.toThrow(/The HSM attached to the HSM Connector's gateway does not support ML-DSA keys/);
expect(getPlatformConnectionDetailsByGatewayId).not.toHaveBeenCalled();
});
diff --git a/backend/src/services/hsm-connector/hsm-connector-routing.ts b/backend/src/services/hsm-connector/hsm-connector-routing.ts
index d5d07584ce..1b8f6c13d3 100644
--- a/backend/src/services/hsm-connector/hsm-connector-routing.ts
+++ b/backend/src/services/hsm-connector/hsm-connector-routing.ts
@@ -12,7 +12,7 @@ import {
import { GatewayProxyProtocol } from "@app/lib/gateway-v2/types";
import { logger } from "@app/lib/logger";
-import { HSM_ML_DSA_MIN_GATEWAY_VERSION, HsmGatewayCapability } from "./hsm-connector-fns";
+import { HsmGatewayCapability } from "./hsm-connector-fns";
import {
THsmConnectorCredentials,
THsmConnectorTestMemberResult,
@@ -24,12 +24,22 @@ const TEST_FANOUT_MAX = 10;
const PKCS11_TARGET_HOST = "pkcs11";
const NO_CAPABLE_MEMBER_MESSAGE =
"No HSM-capable gateway available in the pool. Ensure at least one gateway in the pool has HSM support enabled.";
-const ML_DSA_DRIVER_HINT = "check that your HSM's PKCS#11 driver supports ML-DSA";
-const POOL_MISSING_CAPABILITY_MESSAGES: Record<HsmGatewayCapability, string> = {
- [HsmGatewayCapability.MlDsa]: `No HSM-capable gateway in the pool supports ML-DSA keys. Update at least one of them to ${HSM_ML_DSA_MIN_GATEWAY_VERSION} or later and ${ML_DSA_DRIVER_HINT}.`
+type TMissingCapabilityMessages = { outdatedGateway: string; unsupportedHsm: string };
+const POOL_MISSING_CAPABILITY_MESSAGES: Record<HsmGatewayCapability, TMissingCapabilityMessages> = {
+ [HsmGatewayCapability.MlDsa]: {
+ outdatedGateway:
+ "No HSM-capable gateway in the pool supports ML-DSA keys. Update the pool's gateways to the latest version.",
+ unsupportedHsm:
+ "None of the HSMs attached to the pool's gateways support ML-DSA keys. Check that your HSM's PKCS#11 driver supports ML-DSA."
+ }
};
-const GATEWAY_MISSING_CAPABILITY_MESSAGES: Record<HsmGatewayCapability, string> = {
- [HsmGatewayCapability.MlDsa]: `The HSM Connector's gateway does not support ML-DSA keys. Update it to ${HSM_ML_DSA_MIN_GATEWAY_VERSION} or later and ${ML_DSA_DRIVER_HINT}.`
+const GATEWAY_MISSING_CAPABILITY_MESSAGES: Record<HsmGatewayCapability, TMissingCapabilityMessages> = {
+ [HsmGatewayCapability.MlDsa]: {
+ outdatedGateway:
+ "The HSM Connector's gateway does not support ML-DSA keys. Update the gateway to the latest version.",
+ unsupportedHsm:
+ "The HSM attached to the HSM Connector's gateway does not support ML-DSA keys. Check that your HSM's PKCS#11 driver supports ML-DSA."
+ }
};
type TGatewayRouting = {
@@ -48,6 +58,14 @@ const isPkcs11Capable = (capabilities: unknown, requiredCapability?: HsmGatewayC
return caps.pkcs11 === true && (!requiredCapability || caps[requiredCapability] === true);
};
+const isOutdatedForCapability = (capabilities: unknown, requiredCapability: HsmGatewayCapability): boolean => {
+ const caps = (capabilities as Record<string, unknown> | null | undefined) ?? {};
+ return caps[requiredCapability] === undefined;
+};
+
+const pickMissingCapabilityMessage = (messages: TMissingCapabilityMessages, isOutdated: boolean): string =>
+ isOutdated ? messages.outdatedGateway : messages.unsupportedHsm;
+
export const hsmConnectorRoutingFactory = ({
gatewayV2Service,
gatewayV2DAL,
@@ -72,7 +90,12 @@ export const hsmConnectorRoutingFactory = ({
isPkcs11Capable(gateway.capabilities) &&
!isPkcs11Capable(gateway.capabilities, requiredCapability)
) {
- throw new BadRequestError({ message: GATEWAY_MISSING_CAPABILITY_MESSAGES[requiredCapability] });
+ throw new BadRequestError({
+ message: pickMissingCapabilityMessage(
+ GATEWAY_MISSING_CAPABILITY_MESSAGES[requiredCapability],
+ isOutdatedForCapability(gateway.capabilities, requiredCapability)
+ )
+ });
}
}
return connector.gatewayId;
@@ -94,11 +117,16 @@ export const hsmConnectorRoutingFactory = ({
.catch(async (err: unknown) => {
if (!requiredCapability || !(err instanceof BadRequestError)) throw err;
const healthyGateways = await gatewayPoolService.listHealthyGateways(poolId);
- const hasOtherPkcs11Member = healthyGateways.some(
+ const otherPkcs11Members = healthyGateways.filter(
(gateway) => !triedGatewayIds.has(gateway.id) && isPkcs11Capable(gateway.capabilities)
);
- if (hasOtherPkcs11Member) {
- throw new BadRequestError({ message: POOL_MISSING_CAPABILITY_MESSAGES[requiredCapability] });
+ if (otherPkcs11Members.length > 0) {
+ throw new BadRequestError({
+ message: pickMissingCapabilityMessage(
+ POOL_MISSING_CAPABILITY_MESSAGES[requiredCapability],
+ otherPkcs11Members.some((gateway) => isOutdatedForCapability(gateway.capabilities, requiredCapability))
+ )
+ });
}
throw err;
});
diff --git a/backend/src/services/hsm-connector/hsm-connector-service.ts b/backend/src/services/hsm-connector/hsm-connector-service.ts
index 41a0d225bb..206d5e0684 100644
--- a/backend/src/services/hsm-connector/hsm-connector-service.ts
+++ b/backend/src/services/hsm-connector/hsm-connector-service.ts
@@ -58,7 +58,7 @@ export type THsmConnectorServiceFactoryDep = {
export type THsmConnectorServiceFactory = ReturnType<typeof hsmConnectorServiceFactory>;
const OLD_GATEWAY_BAD_REQUEST_MESSAGE = "Invalid request";
-const GATEWAY_MAX_SIGN_DATA_BYTES = 64 * 1024;
+const GATEWAY_MAX_SIGN_DATA_BYTES = 16 * 1024 * 1024;
const ML_DSA_HSM_KEY_ALGORITHMS = new Set<HsmKeyAlgorithm>([
HsmKeyAlgorithm.ML_DSA_44,
HsmKeyAlgorithm.ML_DSA_65,
diff --git a/docs/documentation/platform/pki/ca/private-ca.mdx b/docs/documentation/platform/pki/ca/private-ca.mdx
index c35f4f17b9..71b5a54daa 100644
--- a/docs/documentation/platform/pki/ca/private-ca.mdx
+++ b/docs/documentation/platform/pki/ca/private-ca.mdx
@@ -265,7 +265,7 @@ Both root and intermediate CAs can be HSM-backed. HSM-backed CAs support the `RS
To use an ML-DSA key on an HSM, you need:
- An HSM whose PKCS#11 driver supports ML-DSA, such as Fortanix DSM with PKCS#11 client 5.7 or later
-- A [Gateway](/documentation/platform/gateways/overview) running v0.44.10 or later
+- A [Gateway](/documentation/platform/gateways/overview) updated to the latest version
<Note>
Set up an [HSM Connector](/documentation/platform/pki/settings/hsm-connectors) before creating an HSM-backed CA. Creating one requires the **Attach** permission on HSM Connectors in addition to permission to create Certificate Authorities.