Skip to content

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

Address PR comments

Carlos Monastyrskieaf3665d3ddf
diff --git a/backend/src/services/certificate/certificate-service.ts b/backend/src/services/certificate/certificate-service.ts
index 0fd811c341..dcf996623e 100644
--- a/backend/src/services/certificate/certificate-service.ts
+++ b/backend/src/services/certificate/certificate-service.ts
@@ -832,9 +832,65 @@ export const certificateServiceFactory = ({
};
};
- /**
- * Import certificate
- */
+ type TImportedCertificateFacts = {
+ serialNumber: string;
+ commonName: string;
+ altNames?: string;
+ keyUsages: CertKeyUsage[];
+ extendedKeyUsages: CertExtendedKeyUsage[];
+ notBefore: Date;
+ notAfter: Date;
+ fields: ReturnType<typeof extractCertificateFields>;
+ algorithms: ReturnType<typeof extractCertificateAlgorithms>;
+ };
+
+ const $buildImportCertificateVerifier =
+ ({
+ policyId,
+ profileName,
+ verifyWithProvider
+ }: {
+ policyId: string;
+ profileName: string;
+ verifyWithProvider?: (serialNumber: string) => Promise<void>;
+ }) =>
+ async (cert: TImportedCertificateFacts) => {
+ if (verifyWithProvider) {
+ await verifyWithProvider(cert.serialNumber);
+ }
+
+ const { keyAlgorithm, signatureAlgorithm } = cert.algorithms;
+ const validation = await certificatePolicyService.validateCertificateRequest(policyId, {
+ commonName: cert.commonName || undefined,
+ organization: cert.fields.subjectOrganization ?? undefined,
+ organizationalUnit: cert.fields.subjectOrganizationalUnit ?? undefined,
+ country: cert.fields.subjectCountry ?? undefined,
+ state: cert.fields.subjectState ?? undefined,
+ locality: cert.fields.subjectLocality ?? undefined,
+ domainComponents: cert.fields.subjectDomainComponents?.split(",") ?? undefined,
+ keyUsages: parseKeyUsages(cert.keyUsages),
+ extendedKeyUsages: parseExtendedKeyUsages(cert.extendedKeyUsages),
+ subjectAlternativeNames: cert.altNames ? cert.altNames.split(",").map((san) => detectSanType(san.trim())) : [],
+ validity: { ttl: certificateSpanToTtl(cert.notBefore, cert.notAfter) },
+ keyAlgorithm: Object.values(CertKeyAlgorithm).includes(keyAlgorithm as CertKeyAlgorithm)
+ ? keyAlgorithm
+ : undefined,
+ signatureAlgorithm: Object.values(CertSignatureAlgorithm).includes(signatureAlgorithm as CertSignatureAlgorithm)
+ ? signatureAlgorithm
+ : undefined,
+ ...(cert.fields.isCA && {
+ basicConstraints: { isCA: true, pathLength: cert.fields.pathLength ?? undefined }
+ })
+ });
+
+ if (!validation.isValid) {
+ const violations = validation.errors.map((error) => `- ${error}`).join("\n");
+ throw new BadRequestError({
+ message: `This certificate does not satisfy the policy of certificate profile '${profileName}':\n${violations}\nAttach a profile whose policy allows this certificate, or import it without one to track it for visibility and expiry alerts only.`
+ });
+ }
+ };
+
const $resolveImportLinkage = async ({
profileId,
projectId,
@@ -915,8 +971,10 @@ export const certificateServiceFactory = ({
profileName: profile.slug,
caName: null,
profileApiConfig: profile.apiConfig,
- policyId: profile.certificatePolicyId,
- verifyCertificate: undefined
+ verifyCertificate: $buildImportCertificateVerifier({
+ policyId: profile.certificatePolicyId,
+ profileName: profile.slug
+ })
};
}
@@ -942,8 +1000,10 @@ export const certificateServiceFactory = ({
profileName: profile.slug,
caName,
profileApiConfig: profile.apiConfig,
- policyId: profile.certificatePolicyId,
- verifyCertificate: undefined
+ verifyCertificate: $buildImportCertificateVerifier({
+ policyId: profile.certificatePolicyId,
+ profileName: profile.slug
+ })
};
}
@@ -960,7 +1020,7 @@ export const certificateServiceFactory = ({
});
}
- const caId = profile.caId;
+ const { caId } = profile;
const parsedMetadata = parsed.data as TImportExternalMetadata;
const { verifyCertificate } = linkage;
@@ -971,14 +1031,20 @@ export const certificateServiceFactory = ({
profileName: profile.slug,
caName,
profileApiConfig: profile.apiConfig,
- policyId: profile.certificatePolicyId,
- verifyCertificate: verifyCertificate
- ? (serialNumber: string) =>
- verifyCertificate({ caId, externalMetadata: parsedMetadata, serialNumber }, { digicertFns })
- : undefined
+ verifyCertificate: $buildImportCertificateVerifier({
+ policyId: profile.certificatePolicyId,
+ profileName: profile.slug,
+ verifyWithProvider: verifyCertificate
+ ? (serialNumber: string) =>
+ verifyCertificate({ caId, externalMetadata: parsedMetadata, serialNumber }, { digicertFns })
+ : undefined
+ })
};
};
+ /**
+ * Import certificate
+ */
const importCert = async ({
projectId: projectIdInput,
projectSlug,
@@ -1146,8 +1212,6 @@ export const certificateServiceFactory = ({
const { serialNumber, notBefore, notAfter } = leafCert;
- await linkage?.verifyCertificate?.(serialNumber);
-
const keyUsagesExt = leafCert.getExtension("2.5.29.15") as x509.KeyUsagesExtension;
let keyUsages: CertKeyUsage[] = [];
@@ -1168,38 +1232,17 @@ export const certificateServiceFactory = ({
const certificateFields = extractCertificateFields(certificateBuffer);
const certificateAlgorithms = extractCertificateAlgorithms(certificateBuffer);
- if (linkage) {
- const { keyAlgorithm, signatureAlgorithm } = certificateAlgorithms;
-
- const validation = await certificatePolicyService.validateCertificateRequest(linkage.policyId, {
- commonName: commonName || undefined,
- organization: certificateFields.subjectOrganization ?? undefined,
- organizationalUnit: certificateFields.subjectOrganizationalUnit ?? undefined,
- country: certificateFields.subjectCountry ?? undefined,
- state: certificateFields.subjectState ?? undefined,
- locality: certificateFields.subjectLocality ?? undefined,
- domainComponents: certificateFields.subjectDomainComponents?.split(",") ?? undefined,
- keyUsages: parseKeyUsages(keyUsages),
- extendedKeyUsages: parseExtendedKeyUsages(extendedKeyUsages),
- subjectAlternativeNames: altNames ? altNames.split(",").map((san) => detectSanType(san.trim())) : [],
- validity: { ttl: certificateSpanToTtl(notBefore, notAfter) },
- keyAlgorithm: Object.values(CertKeyAlgorithm).includes(keyAlgorithm as CertKeyAlgorithm)
- ? keyAlgorithm
- : undefined,
- signatureAlgorithm: Object.values(CertSignatureAlgorithm).includes(signatureAlgorithm as CertSignatureAlgorithm)
- ? signatureAlgorithm
- : undefined,
- ...(certificateFields.isCA && {
- basicConstraints: { isCA: true, pathLength: certificateFields.pathLength ?? undefined }
- })
- });
-
- if (!validation.isValid) {
- throw new BadRequestError({
- message: `This certificate does not satisfy the policy of certificate profile '${linkage.profileName}', so that profile could not renew it: ${validation.errors.join(", ")}. Attach a profile whose policy allows this certificate, or import it without one to track it for visibility and expiry alerts only.`
- });
- }
- }
+ await linkage?.verifyCertificate({
+ serialNumber,
+ commonName,
+ altNames,
+ keyUsages,
+ extendedKeyUsages,
+ notBefore,
+ notAfter,
+ fields: certificateFields,
+ algorithms: certificateAlgorithms
+ });
// Encrypt certificate for storage
const certificateManagerKeyId = await getProjectKmsCertificateKeyId({
diff --git a/frontend/src/pages/cert-manager/CertificatesPage/components/CertificateImportModal.tsx b/frontend/src/pages/cert-manager/CertificatesPage/components/CertificateImportModal.tsx
index a52138f8ed..f734be556e 100644
--- a/frontend/src/pages/cert-manager/CertificatesPage/components/CertificateImportModal.tsx
+++ b/frontend/src/pages/cert-manager/CertificatesPage/components/CertificateImportModal.tsx
@@ -338,7 +338,7 @@ export const CertificateImportModal = ({ popUp, handlePopUpToggle, applicationId
</ItemMedia>
<ItemContent className="min-w-0">
<ItemTitle className="truncate">{outcome.subject}</ItemTitle>
- <ItemDescription className="line-clamp-none">
+ <ItemDescription className="mt-1 line-clamp-none whitespace-pre-line">
{outcome.error ?? "Imported"}
</ItemDescription>
</ItemContent>
@@ -388,11 +388,11 @@ export const CertificateImportModal = ({ popUp, handlePopUpToggle, applicationId
/>
</TableHead>
<TableHead className={STICKY_HEAD}>SAN / CN</TableHead>
- <TableHead className={`w-40 ${STICKY_HEAD}`}>Private Key</TableHead>
- <TableHead className={`w-24 ${STICKY_HEAD}`}>Chain</TableHead>
- <TableHead className={`w-44 ${STICKY_HEAD}`}>Expires</TableHead>
+ <TableHead className={`w-28 ${STICKY_HEAD}`}>Private Key</TableHead>
+ <TableHead className={`w-20 ${STICKY_HEAD}`}>Chain</TableHead>
+ <TableHead className={`w-32 ${STICKY_HEAD}`}>Expires</TableHead>
{keystoreReference && (
- <TableHead className={`w-64 ${STICKY_HEAD}`}>{keystoreReference.label}</TableHead>
+ <TableHead className={`w-80 ${STICKY_HEAD}`}>{keystoreReference.label}</TableHead>
)}
</TableRow>
</TableHeader>
@@ -575,14 +575,14 @@ export const CertificateImportModal = ({ popUp, handlePopUpToggle, applicationId
if (entries && format === "pkcs12") {
return (
<DialogFooter>
- <Button variant="outline" onClick={() => handlePopUpToggle("certificateImport", false)}>
- Cancel
- </Button>
{isMissingKeystoreReference && keystoreReference && (
- <span className="text-sm text-mineshaft-300">
+ <span className="self-center text-sm text-mineshaft-300">
{`Enter the ${keystoreReference.label} for every selected certificate.`}
</span>
)}
+ <Button variant="outline" onClick={() => handlePopUpToggle("certificateImport", false)}>
+ Cancel
+ </Button>
<Button
variant="project"
isDisabled={!selected.size || isImportingEntries || isMissingKeystoreReference}
diff --git a/frontend/src/pages/cert-manager/CertificatesPage/components/certificate-import-fields.tsx b/frontend/src/pages/cert-manager/CertificatesPage/components/certificate-import-fields.tsx
index 4f44c7fa97..76bba85655 100644
--- a/frontend/src/pages/cert-manager/CertificatesPage/components/certificate-import-fields.tsx
+++ b/frontend/src/pages/cert-manager/CertificatesPage/components/certificate-import-fields.tsx
@@ -100,7 +100,7 @@ export const CertificateProfileSelect = ({
export const useCertificateImportReference = (profile: ProfileOption | null) => {
const reference = getCertificateImportReference(profile?.caType);
- const { data: cas = [] } = useListCasByProjectId();
+ const { data: cas = [], isPending: isCasLoading } = useListCasByProjectId();
const selectedCa = cas.find((ca) => ca.id === profile?.caId && ca.status === CaStatus.ACTIVE);
const digicertConfig =
selectedCa?.type === CaType.DIGICERT && reference?.hasLiveOptions
@@ -120,16 +120,18 @@ export const useCertificateImportReference = (profile: ProfileOption | null) =>
const referenceOptions: ReferenceOption[] = orders.map((order) => ({
value: String(order.orderId),
- label: `${order.commonName || "Certificate"} (#${order.orderId})`
+ label: `#${order.orderId} (${order.commonName || "Certificate"})`
}));
+ const isResolvingOptions =
+ Boolean(reference?.hasLiveOptions) &&
+ (isCasLoading || (Boolean(digicertConfig) && isOptionsLoading));
+
const useFreeText =
!reference?.hasLiveOptions ||
- !digicertConfig ||
- isOptionsError ||
- (!isOptionsLoading && !referenceOptions.length);
+ (!isResolvingOptions && (!digicertConfig || isOptionsError || !referenceOptions.length));
- return { reference, referenceOptions, isOptionsLoading, useFreeText };
+ return { reference, referenceOptions, isOptionsLoading: isResolvingOptions, useFreeText };
};
export type TCertificateReferenceSource = ReturnType<typeof useCertificateImportReference>;
@@ -166,6 +168,26 @@ export const CertificateReferenceField = ({
getOptionLabel={(option) => option.label}
getOptionValue={(option) => option.value}
placeholder={reference.optionsPlaceholder}
+ styles={{
+ control: (base) => ({ ...base, minHeight: "unset" }),
+ input: (base) => ({ ...base, "input:focus": { boxShadow: "none" } }),
+ menuPortal: (base) => ({ ...base, zIndex: 60, pointerEvents: "auto" }),
+ menu: (base) => ({
+ ...base,
+ width: "max-content",
+ minWidth: "100%",
+ maxWidth: "24rem",
+ overflowX: "auto"
+ }),
+ menuList: (base) => ({ ...base, width: "max-content", minWidth: "100%" }),
+ option: (base) => ({
+ ...base,
+ minWidth: "100%",
+ overflow: "visible",
+ textOverflow: "clip",
+ whiteSpace: "nowrap"
+ })
+ }}
/>
);
};