Skip to content

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

Improve HSM CA keyLabel

Carlos Monastyrskif2fe292c0d5b
diff --git a/backend/src/lib/api-docs/constants.ts b/backend/src/lib/api-docs/constants.ts
index 97b771aafe..6efc14a564 100644
--- a/backend/src/lib/api-docs/constants.ts
+++ b/backend/src/lib/api-docs/constants.ts
@@ -2664,7 +2664,7 @@ export const CertificateAuthorities = {
hsmConnectorId:
"The ID of the HSM Connector to generate and store the CA's signing key in. Required when keySource is 'hsm'.",
hsmKeyLabel:
- "The label of the CA's signing key on the HSM. Not user-supplied: it is the HSM Connector's configured key name prefix followed by a unique, server-generated per-CA suffix (ca-<uuid>).",
+ "The label of the CA's signing key on the HSM. Not user-supplied: it is the HSM Connector's configured key name prefix followed by a per-CA label built from the CA name and a random 5-character suffix (ca-<name>-<slug>).",
crlDistributionPointUrls:
"Additional CRL Distribution Point URLs (HTTP/HTTPS) embedded in every certificate issued by this CA. Up to 4 URLs; the Infisical-managed CRL endpoint is included by default unless disabled.",
disableManagedCrlDistributionPointUrl:
diff --git a/backend/src/services/certificate-authority/internal/internal-certificate-authority-service.ts b/backend/src/services/certificate-authority/internal/internal-certificate-authority-service.ts
index 0860fbff9f..31f26e8dd7 100644
--- a/backend/src/services/certificate-authority/internal/internal-certificate-authority-service.ts
+++ b/backend/src/services/certificate-authority/internal/internal-certificate-authority-service.ts
@@ -343,6 +343,8 @@ export const internalCertificateAuthorityServiceFactory = ({
const alg = keyAlgorithmToAlgCfg(keyAlgorithm);
+ const resolvedCaName = name || slugify(`${(friendlyName || dn).slice(0, 16)}-${alphaNumericNanoId(8)}`);
+
const keySource = dto.keySource ?? CertKeySource.Infisical;
const useHsm = keySource === CertKeySource.Hsm;
@@ -384,7 +386,7 @@ export const internalCertificateAuthorityServiceFactory = ({
const generated = await hsmConnectorService.generateKeyPair({
connectorId: dto.hsmConnectorId,
projectId,
- keyLabel: `ca-${crypto.nativeCrypto.randomUUID()}`,
+ keyLabel: `ca-${resolvedCaName}-${alphaNumericNanoId(5)}`,
keyAlgorithm: shape.hsmKeyAlgorithm
});
hsmKey = generated;
@@ -490,7 +492,7 @@ export const internalCertificateAuthorityServiceFactory = ({
const ca = await certificateAuthorityDAL.create(
{
projectId,
- name: name || slugify(`${(friendlyName || dn).slice(0, 16)}-${alphaNumericNanoId(8)}`),
+ name: resolvedCaName,
status: notAfter && type === InternalCaType.ROOT ? CaStatus.ACTIVE : CaStatus.PENDING_CERTIFICATE,
enableDirectIssuance: false
},