Skip to content

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

fix(pki): disable key pair reuse on renewal when Infisical holds neither the key nor the CSR

Devin AI2b79f2e177b9
diff --git a/backend/src/lib/api-docs/constants.ts b/backend/src/lib/api-docs/constants.ts
index 94e5b19bbc..1aa61c5cac 100644
--- a/backend/src/lib/api-docs/constants.ts
+++ b/backend/src/lib/api-docs/constants.ts
@@ -2407,6 +2407,8 @@ export const CERTIFICATES = {
id: "The ID of the certificate to preview a renewal for.",
hasOriginatingRequest:
"Whether the certificate has a recorded originating request. When false the preview falls back to the issued certificate, which is the case for imported and discovered certificates.",
+ hasOriginatingCsr:
+ "Whether the request that produced this certificate carried a CSR. When Infisical holds neither the private key nor this CSR, renewing with the existing key pair is refused.",
request:
"The values a renewal will request, taken from the request that produced this certificate including any profile defaults it recorded.",
issuerModifiedFields:
diff --git a/backend/src/server/routes/v1/certificate-router.ts b/backend/src/server/routes/v1/certificate-router.ts
index fdcfecd1eb..7398e196b8 100644
--- a/backend/src/server/routes/v1/certificate-router.ts
+++ b/backend/src/server/routes/v1/certificate-router.ts
@@ -1199,6 +1199,7 @@ export const registerCertificateRouter = async (server: FastifyZodProvider) => {
response: {
200: z.object({
hasOriginatingRequest: z.boolean().describe(CERTIFICATES.RENEWAL_PREVIEW.hasOriginatingRequest),
+ hasOriginatingCsr: z.boolean().describe(CERTIFICATES.RENEWAL_PREVIEW.hasOriginatingCsr),
request: z
.object({
commonName: z.string().optional(),
diff --git a/backend/src/services/certificate-v3/certificate-renewal-fns.test.ts b/backend/src/services/certificate-v3/certificate-renewal-fns.test.ts
index f245ede035..7e0220363f 100644
--- a/backend/src/services/certificate-v3/certificate-renewal-fns.test.ts
+++ b/backend/src/services/certificate-v3/certificate-renewal-fns.test.ts
@@ -642,6 +642,13 @@ describe("buildRenewalPreview", () => {
expect(buildRenewalPreview(requested, certificate).issuerModifiedFields).toEqual([]);
});
+ it("reports whether the originating request carried a CSR, which a key reuse without the private key needs", () => {
+ expect(buildRenewalPreview(requested, certificate).hasOriginatingCsr).toBe(false);
+ expect(
+ buildRenewalPreview({ ...requested, csr: "-----BEGIN CERTIFICATE REQUEST-----" }, certificate).hasOriginatingCsr
+ ).toBe(true);
+ });
+
it("does not read a legacy value the form cannot offer as an authority change", () => {
const legacy = "RSA_2048";
const { request, issuerModifiedFields } = buildRenewalPreview(
diff --git a/backend/src/services/certificate-v3/certificate-renewal-fns.ts b/backend/src/services/certificate-v3/certificate-renewal-fns.ts
index 2b71b51ac6..2a73754e1f 100644
--- a/backend/src/services/certificate-v3/certificate-renewal-fns.ts
+++ b/backend/src/services/certificate-v3/certificate-renewal-fns.ts
@@ -309,6 +309,7 @@ type TOriginatingRenewalRequest = {
keyAlgorithm: string | null;
signatureAlgorithm: string | null;
customExtensions: unknown;
+ csr?: string | null;
};
type TRenewalCertificateFacts = {
@@ -555,7 +556,12 @@ export const buildRenewalPreview = (requested: TOriginatingRenewalRequest, certi
});
}
- return { request, issuerModifiedFields, hasOriginatingRequest: requested.exists };
+ return {
+ request,
+ issuerModifiedFields,
+ hasOriginatingRequest: requested.exists,
+ hasOriginatingCsr: Boolean(requested.csr)
+ };
};
export const buildRenewalDistinguishedName = (certificateRequest: TCertificateRequest): string =>
diff --git a/frontend/src/hooks/api/certificates/types.ts b/frontend/src/hooks/api/certificates/types.ts
index 6c410c0bf2..3105a911ed 100644
--- a/frontend/src/hooks/api/certificates/types.ts
+++ b/frontend/src/hooks/api/certificates/types.ts
@@ -388,6 +388,7 @@ export type TIssuerModifiedField = {
export type TCertificateRenewalPreview = {
hasOriginatingRequest: boolean;
+ hasOriginatingCsr: boolean;
request: {
commonName?: string;
organization?: string;
diff --git a/frontend/src/pages/cert-manager/CertificatesPage/components/CertificateRenewalModal.tsx b/frontend/src/pages/cert-manager/CertificatesPage/components/CertificateRenewalModal.tsx
index de1c063b82..b49821f273 100644
--- a/frontend/src/pages/cert-manager/CertificatesPage/components/CertificateRenewalModal.tsx
+++ b/frontend/src/pages/cert-manager/CertificatesPage/components/CertificateRenewalModal.tsx
@@ -14,7 +14,10 @@ import {
FieldLabel,
RadioGroup,
RadioGroupItem,
- TextArea
+ TextArea,
+ Tooltip,
+ TooltipContent,
+ TooltipTrigger
} from "@app/components/v3";
import { useOrganization, useProject } from "@app/context";
import { useRenewCertificate } from "@app/hooks/api";
@@ -413,6 +416,13 @@ export const CertificateRenewalModal = ({ popUp, applicationName, handlePopUpTog
} else if (!isSelfSigned && certificate?.caType === CertificateIssuerKind.External) {
reuseRefusalReason =
"The issuing certificate authority does not support reusing an existing key pair.";
+ } else if (
+ !isSelfSigned &&
+ certificate?.hasPrivateKey === false &&
+ renewalPreview?.hasOriginatingCsr === false
+ ) {
+ reuseRefusalReason =
+ "Infisical holds neither this certificate's private key nor the signing request it was issued from. Generate a new key pair, or use a CSR generated from the existing key.";
}
const csrRefusalReason = isSelfSigned
? "A self-signed certificate is signed by its own private key, which a signing request does not carry."
@@ -658,28 +668,41 @@ export const CertificateRenewalModal = ({ popUp, applicationName, handlePopUpTog
<FieldLabel>Key pair</FieldLabel>
<FieldContent>
<RadioGroup value={value} onValueChange={onChange} className="gap-2">
- {keySourceOptions.map((option) => (
- <FieldLabel
- key={option.value}
- htmlFor={`key-source-${option.value}`}
- variant="project"
- >
- <Field orientation="horizontal" className="items-center gap-3">
- <div className="min-w-0 flex-1 text-left">
- <p className="text-sm font-medium text-foreground">{option.label}</p>
- <p className="text-xs text-muted">
- {option.isDisabled ? option.disabledReason : option.description}
- </p>
- </div>
- <RadioGroupItem
- id={`key-source-${option.value}`}
- value={option.value}
- disabled={option.isDisabled}
- className="sr-only"
- />
- </Field>
- </FieldLabel>
- ))}
+ {keySourceOptions.map((option) => {
+ const card = (
+ <FieldLabel
+ key={option.value}
+ htmlFor={`key-source-${option.value}`}
+ variant="project"
+ >
+ <Field orientation="horizontal" className="items-center gap-3">
+ <div className="min-w-0 flex-1 text-left">
+ <p className="text-sm font-medium text-foreground">{option.label}</p>
+ <p className="text-xs text-muted">
+ {option.isDisabled
+ ? "Not available for this certificate."
+ : option.description}
+ </p>
+ </div>
+ <RadioGroupItem
+ id={`key-source-${option.value}`}
+ value={option.value}
+ disabled={option.isDisabled}
+ className="sr-only"
+ />
+ </Field>
+ </FieldLabel>
+ );
+ if (!option.isDisabled) return card;
+ return (
+ <Tooltip key={option.value}>
+ <TooltipTrigger asChild>{card}</TooltipTrigger>
+ <TooltipContent side="bottom" className="max-w-80">
+ {option.disabledReason}
+ </TooltipContent>
+ </Tooltip>
+ );
+ })}
</RadioGroup>
</FieldContent>
</Field>
diff --git a/frontend/src/pages/cert-manager/CertificatesPage/components/certificateRenewalUtils.test.ts b/frontend/src/pages/cert-manager/CertificatesPage/components/certificateRenewalUtils.test.ts
index 4178034e63..3456aab8fa 100644
--- a/frontend/src/pages/cert-manager/CertificatesPage/components/certificateRenewalUtils.test.ts
+++ b/frontend/src/pages/cert-manager/CertificatesPage/components/certificateRenewalUtils.test.ts
@@ -27,6 +27,7 @@ const constraints = {
const renewalPreview = {
hasOriginatingRequest: true,
+ hasOriginatingCsr: true,
request: {
commonName: "asked-for.example.com",
altNames: [],