Skip to content

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

Add docs for CA renewal

Tuan Dang88a4390ea044
diff --cc backend/src/lib/api-docs/constants.ts
index 575af97f93,aa7d2fc510..bca04a7582
--- a/backend/src/lib/api-docs/constants.ts
+++ b/backend/src/lib/api-docs/constants.ts
@@@ -1048,23 -1048,15 +1048,30 @@@ export const CERTIFICATE_AUTHORITIES =
caId: "The ID of the CA to generate CSR from",
csr: "The generated CSR from the CA"
},
+ RENEW_CA_CERT: {
+ caId: "The ID of the CA to renew the CA certificate for",
+ type: "The type of behavior to use for the renewal operation. Currently Infisical is only able to renew a CA certificate with the same key pair.",
- notAfter: "The expiry date and time for the renewed CA certificatre in YYYY-MM-DDTHH:mm:ss.sssZ format",
++ notAfter: "The expiry date and time for the renewed CA certificate in YYYY-MM-DDTHH:mm:ss.sssZ format",
+ certificate: "The renewed CA certificate body",
+ certificateChain: "The certificate chain of the CA",
+ serialNumber: "The serial number of the renewed CA certificate"
+ },
GET_CERT: {
caId: "The ID of the CA to get the certificate body and certificate chain from",
certificate: "The certificate body of the CA",
certificateChain: "The certificate chain of the CA",
serialNumber: "The serial number of the CA certificate"
},
++ GET_CA_CERTS: {
++ caId: "The ID of the CA to get the CA certificates for",
++ certificate: "The certificate body of the CA certificate",
++ certificateChain: "The certificate chain of the CA certificate",
++ serialNumber: "The serial number of the CA certificate",
++ version: "The version of the CA certificate. The version is incremented for each CA renewal operation."
++ },
SIGN_INTERMEDIATE: {
caId: "The ID of the CA to sign the intermediate certificate with",
- csr: "The CSR to sign with the CA",
+ csr: "The pem-encoded CSR to sign with the CA",
notBefore: "The date and time when the intermediate CA becomes valid in YYYY-MM-DDTHH:mm:ss.sssZ format",
notAfter: "The date and time when the intermediate CA expires in YYYY-MM-DDTHH:mm:ss.sssZ format",
maxPathLength:
diff --cc backend/src/server/routes/v1/certificate-authority-router.ts
index e39c5702ea,1a6e303021..bc5294f059
--- a/backend/src/server/routes/v1/certificate-authority-router.ts
+++ b/backend/src/server/routes/v1/certificate-authority-router.ts
@@@ -275,113 -275,9 +275,112 @@@ export const registerCaRouter = async (
}
});
+ server.route({
+ method: "POST",
+ url: "/:caId/renew",
+ config: {
+ rateLimit: writeLimit
+ },
+ onRequest: verifyAuth([AuthMode.JWT, AuthMode.IDENTITY_ACCESS_TOKEN]),
+ schema: {
+ description: "Renew CA certificate for CA",
+ params: z.object({
+ caId: z.string().trim().describe(CERTIFICATE_AUTHORITIES.RENEW_CA_CERT.caId)
+ }),
+ body: z.object({
+ type: z.nativeEnum(CaRenewalType).describe(CERTIFICATE_AUTHORITIES.RENEW_CA_CERT.type),
+ notAfter: validateCaDateField.describe(CERTIFICATE_AUTHORITIES.RENEW_CA_CERT.notAfter)
+ }),
+ response: {
+ 200: z.object({
+ certificate: z.string().trim().describe(CERTIFICATE_AUTHORITIES.RENEW_CA_CERT.certificate),
+ certificateChain: z.string().trim().describe(CERTIFICATE_AUTHORITIES.RENEW_CA_CERT.certificateChain),
+ serialNumber: z.string().trim().describe(CERTIFICATE_AUTHORITIES.RENEW_CA_CERT.serialNumber)
+ })
+ }
+ },
+ handler: async (req) => {
+ const { certificate, certificateChain, serialNumber, ca } =
+ await server.services.certificateAuthority.renewCaCert({
+ caId: req.params.caId,
+ actor: req.permission.type,
+ actorId: req.permission.id,
+ actorAuthMethod: req.permission.authMethod,
+ actorOrgId: req.permission.orgId,
+ ...req.body
+ });
+
+ await server.services.auditLog.createAuditLog({
+ ...req.auditLogInfo,
+ projectId: ca.projectId,
+ event: {
+ type: EventType.RENEW_CA,
+ metadata: {
+ caId: ca.id,
+ dn: ca.dn
+ }
+ }
+ });
+
+ return {
+ certificate,
+ certificateChain,
+ serialNumber
+ };
+ }
+ });
+
+ server.route({
+ method: "GET",
+ url: "/:caId/ca-certificates",
+ config: {
+ rateLimit: readLimit
+ },
+ onRequest: verifyAuth([AuthMode.JWT, AuthMode.IDENTITY_ACCESS_TOKEN]),
+ schema: {
+ description: "Get list of past and current CA certificates for a CA",
+ params: z.object({
- caId: z.string().trim().describe(CERTIFICATE_AUTHORITIES.GET_CERT.caId)
++ caId: z.string().trim().describe(CERTIFICATE_AUTHORITIES.GET_CA_CERTS.caId)
+ }),
+ response: {
+ 200: z.array(
+ z.object({
- // TODO: consider not before and not after dates
- certificate: z.string().describe(CERTIFICATE_AUTHORITIES.GET_CERT.certificate),
- certificateChain: z.string().describe(CERTIFICATE_AUTHORITIES.GET_CERT.certificateChain),
- serialNumber: z.string().describe(CERTIFICATE_AUTHORITIES.GET_CERT.serialNumber),
- version: z.number()
++ certificate: z.string().describe(CERTIFICATE_AUTHORITIES.GET_CA_CERTS.certificate),
++ certificateChain: z.string().describe(CERTIFICATE_AUTHORITIES.GET_CA_CERTS.certificateChain),
++ serialNumber: z.string().describe(CERTIFICATE_AUTHORITIES.GET_CA_CERTS.serialNumber),
++ version: z.number().describe(CERTIFICATE_AUTHORITIES.GET_CA_CERTS.version)
+ })
+ )
+ }
+ },
+ handler: async (req) => {
+ const { caCerts, ca } = await server.services.certificateAuthority.getCaCerts({
+ caId: req.params.caId,
+ actor: req.permission.type,
+ actorId: req.permission.id,
+ actorAuthMethod: req.permission.authMethod,
+ actorOrgId: req.permission.orgId
+ });
+
+ await server.services.auditLog.createAuditLog({
+ ...req.auditLogInfo,
+ projectId: ca.projectId,
+ event: {
+ type: EventType.GET_CA_CERTS,
+ metadata: {
+ caId: ca.id,
+ dn: ca.dn
+ }
+ }
+ });
+
+ return caCerts;
+ }
+ });
+
server.route({
method: "GET",
- url: "/:caId/certificate",
+ url: "/:caId/certificate", // TODO: consider updating endpoint structure considering CA certificates
config: {
rateLimit: readLimit
},
diff --cc backend/src/services/certificate-authority/certificate-authority-service.ts
index 21cd5a9301,49bb209efe..0e356a4aea
--- a/backend/src/services/certificate-authority/certificate-authority-service.ts
+++ b/backend/src/services/certificate-authority/certificate-authority-service.ts
@@@ -20,10 -20,10 +20,11 @@@ import { TCertificateAuthorityCertDALFa
import { TCertificateAuthorityDALFactory } from "./certificate-authority-dal";
import {
createDistinguishedName,
- getCaCertChain,
+ getCaCertChain, // TODO: consider rename
+ getCaCertChains,
getCaCredentials,
- keyAlgorithmToAlgCfg
+ keyAlgorithmToAlgCfg,
+ parseDistinguishedName
} from "./certificate-authority-fns";
import { TCertificateAuthorityQueueFactory } from "./certificate-authority-queue";
import { TCertificateAuthoritySecretDALFactory } from "./certificate-authority-secret-dal";
@@@ -38,7 -37,7 +39,8 @@@ import
TGetCaDTO,
TImportCertToCaDTO,
TIssueCertFromCaDTO,
+ TRenewCaCertDTO,
+ TSignCertFromCaDTO,
TSignIntermediateDTO,
TUpdateCaDTO
} from "./certificate-authority-types";
diff --cc docs/api-reference/endpoints/certificate-authorities/list-ca-certs.mdx
index 0000000000,0000000000..ce253807cd
new file mode 100644
--- /dev/null
+++ b/docs/api-reference/endpoints/certificate-authorities/list-ca-certs.mdx
@@@ -1,0 -1,0 +1,4 @@@
++---
++title: "List CA certificates"
++openapi: "GET /api/v1/pki/ca/{caId}/ca-certificates"
++---
diff --cc docs/api-reference/endpoints/certificate-authorities/renew.mdx
index 0000000000,0000000000..901811f2d8
new file mode 100644
--- /dev/null
+++ b/docs/api-reference/endpoints/certificate-authorities/renew.mdx
@@@ -1,0 -1,0 +1,4 @@@
++---
++title: "Renew"
++openapi: "POST /api/v1/pki/ca/{caId}/renew"
++---
diff --cc docs/documentation/platform/pki/private-ca.mdx
index 0ebb31e2c9,0ebb31e2c9..3a7191a1da
--- a/docs/documentation/platform/pki/private-ca.mdx
+++ b/docs/documentation/platform/pki/private-ca.mdx
@@@ -36,7 -36,7 +36,7 @@@ A typical workflow for setting up a Pri
intermediate certificate back to the intermediate CA as part of Step 2.
</Note>
--## Guide
++## Guide to Creating a CA Hierarchy
In the following steps, we explore how to create a simple Private CA hierarchy
consisting of a root CA and an intermediate CA.
@@@ -240,6 -240,6 +240,51 @@@
</Tab>
</Tabs>
++## Guide to CA Renewal
++
++In the following steps, we explore how to renew a CA certificate via same key pair.
++
++<Tabs>
++ <Tab title="Infisical UI">
++ Head to the CA Page of the CA you wish you renew and press **Renew CA** on
++ the left side. ![pki ca renewal
++ page](/images/platform/pki/ca-renewal-page.png) Input a new **Valid Until**
++ date to be used for the renewed CA certificate and press **Renew** to renew
++ the CA. ![pki ca renewal. modal](/images/platform/pki/ca-renewal-modal.png)
++ <Note>
++ The new **Valid Until** date must be within the validity period of the
++ parent CA.
++ </Note>
++ </Tab>
++ <Tab title="API">
++
++ To renew a CA certificate, make an API request to the [Renew CA](/api-reference/endpoints/certificate-authorities/renew) API endpoint, specifying the new `notAfter` date for the CA.
++
++ ### Sample request
++
++ ```bash Request
++ curl --location --request POST 'https://app.infisical.com/api/v1/pki/ca/<ca-id>/renew' \
++ --header 'Authorization: Bearer <access-token>' \
++ --header 'Content-Type: application/json' \
++ --data-raw '{
++ "type": "existing",
++ "notAfter": "2029-06-12"
++ }'
++ ```
++
++ ### Sample response
++
++ ```bash Response
++ {
++ certificate: "...",
++ certificateChain: "...",
++ serialNumber: "..."
++ }
++ ```
++
++ </Tab>
++</Tabs>
++
## FAQ
<AccordionGroup>
@@@ -247,4 -247,4 +292,8 @@@
Infisical supports `RSA 2048`, `RSA 4096`, `ECDSA P-256`, `ECDSA P-384` key
algorithms specified at the time of creating a CA.
</Accordion>
++ <Accordion title="Does Infisical support CA renewal via new key pair">
++ At the moment, Infisical only supports CA renewal via same key pair. We
++ anticipate supporting CA renewal via new key pair in the coming month.
++ </Accordion>
</AccordionGroup>
diff --cc docs/images/platform/pki/ca-renewal-modal.png
index 0000000000,0000000000..c86d944f33
new file mode 100644
Binary files differ
diff --cc docs/images/platform/pki/ca-renewal-page.png
index 0000000000,0000000000..43c690ae77
new file mode 100644
Binary files differ
diff --cc docs/mint.json
index f6bc0e5e9a,ed824284b0..5146084fb2
--- a/docs/mint.json
+++ b/docs/mint.json
@@@ -667,6 -667,6 +667,8 @@@
"api-reference/endpoints/certificate-authorities/read",
"api-reference/endpoints/certificate-authorities/update",
"api-reference/endpoints/certificate-authorities/delete",
++ "api-reference/endpoints/certificate-authorities/renew",
++ "api-reference/endpoints/certificate-authorities/list-ca-certs",
"api-reference/endpoints/certificate-authorities/csr",
"api-reference/endpoints/certificate-authorities/cert",
"api-reference/endpoints/certificate-authorities/sign-intermediate",
diff --cc frontend/src/views/Project/CaPage/components/CaRenewalModal.tsx
index d66e0b71bd,0000000000..6f9cf3a1c3
mode 100644,000000..100644
--- a/frontend/src/views/Project/CaPage/components/CaRenewalModal.tsx
+++ b/frontend/src/views/Project/CaPage/components/CaRenewalModal.tsx
@@@ -1,182 -1,0 +1,182 @@@
+// import { useEffect } from "react";
+import { Controller, useForm } from "react-hook-form";
+import { zodResolver } from "@hookform/resolvers/zod";
+import { z } from "zod";
+
+import { createNotification } from "@app/components/notifications";
+import {
+ Button,
+ FormControl,
+ Input,
+ Modal,
+ ModalContent,
+ Select,
+ SelectItem
+} from "@app/components/v2";
+import { useWorkspace } from "@app/context";
+import {
+ CaRenewalType,
+ useRenewCa
+ // useGetCaById,
+ // CaType,
+ // CaStatus
+} from "@app/hooks/api/ca";
+import { UsePopUpState } from "@app/hooks/usePopUp";
+
+const caRenewalTypes = [{ label: "Renew with same key pair", value: CaRenewalType.EXISTING }];
+
+const isValidDate = (dateString: string) => {
+ const date = new Date(dateString);
+ return !Number.isNaN(date.getTime());
+};
+
+const schema = z
+ .object({
+ type: z.enum([CaRenewalType.EXISTING]),
+ notAfter: z.string().trim().refine(isValidDate, { message: "Invalid date format" })
+ })
+ .required();
+
+export type FormData = z.infer<typeof schema>;
+
+type Props = {
+ popUp: UsePopUpState<["renewCa"]>;
+ handlePopUpToggle: (popUpName: keyof UsePopUpState<["renewCa"]>, state?: boolean) => void;
+};
+
+export const CaRenewalModal = ({ popUp, handlePopUpToggle }: Props) => {
+ const { currentWorkspace } = useWorkspace();
+ const projectSlug = currentWorkspace?.slug || "";
+
+ const popUpData = popUp?.renewCa?.data as {
+ caId: string;
+ };
+
+ // const { data: ca } = useGetCaById(popUpData?.caId || "");
+ // const { data: parentCa } = useGetCaById(ca?.parentCaId || "");
+ const { mutateAsync: renewCa } = useRenewCa();
+
+ const {
+ control,
+ handleSubmit,
+ reset,
+ formState: { isSubmitting }
+ // setValue
+ } = useForm<FormData>({
+ resolver: zodResolver(schema),
+ defaultValues: {
+ type: CaRenewalType.EXISTING,
+ notAfter: "" // TODO: consider setting a default value
+ }
+ });
+
+ // useEffect(() => {
+ // if (ca && ca.status === CaStatus.ACTIVE) {
+ // const notBeforeDate = new Date(ca.notBefore as string);
+ // const notAfterDate = new Date(ca.notAfter as string);
+
+ // const newNotAfterDate = new Date(
+ // notAfterDate.getTime() + notAfterDate.getTime() - notBeforeDate.getTime()
+ // );
+
+ // setValue("notAfter", newNotAfterDate.toISOString().split("T")[0]);
+ // }
+ // }, [ca, parentCa]);
+
+ const onFormSubmit = async ({ type, notAfter }: FormData) => {
+ try {
+ if (!projectSlug || !popUpData.caId) return;
+
+ await renewCa({
+ projectSlug,
+ caId: popUpData.caId,
+ notAfter,
+ type
+ });
+
+ handlePopUpToggle("renewCa", false);
+
+ createNotification({
+ text: "Successfully renewed CA",
+ type: "success"
+ });
+
+ reset();
+ } catch (err) {
+ console.error(err);
+ }
+ };
+
+ return (
+ <Modal
+ isOpen={popUp?.renewCa?.isOpen}
+ onOpenChange={(isOpen) => {
+ handlePopUpToggle("renewCa", isOpen);
+ reset();
+ }}
+ >
+ <ModalContent title="Renew CA">
+ <form onSubmit={handleSubmit(onFormSubmit)}>
+ <Controller
+ control={control}
+ name="type"
+ defaultValue={CaRenewalType.EXISTING}
+ render={({ field: { onChange, ...field }, fieldState: { error } }) => (
+ <FormControl
+ label="CA Renewal Method"
+ errorText={error?.message}
+ isError={Boolean(error)}
+ >
+ <Select
+ defaultValue={field.value}
+ {...field}
+ onValueChange={(e) => onChange(e)}
+ className="w-full"
+ >
+ {caRenewalTypes.map(({ label, value }) => (
+ <SelectItem value={String(value || "")} key={label}>
+ {label}
+ </SelectItem>
+ ))}
+ </Select>
+ </FormControl>
+ )}
+ />
+ <Controller
+ control={control}
+ defaultValue=""
+ name="notAfter"
+ render={({ field, fieldState: { error } }) => (
+ <FormControl
+ label="Valid Until"
+ isError={Boolean(error)}
+ errorText={error?.message}
+ isRequired
+ >
+ <Input {...field} placeholder="YYYY-MM-DD" />
+ </FormControl>
+ )}
+ />
+ <div className="flex items-center">
+ <Button
+ className="mr-4"
+ size="sm"
+ type="submit"
+ isLoading={isSubmitting}
+ isDisabled={isSubmitting}
+ >
- Create
++ Renew
+ </Button>
+ <Button
+ colorSchema="secondary"
+ variant="plain"
+ onClick={() => handlePopUpToggle("renewCa", false)}
+ >
+ Cancel
+ </Button>
+ </div>
+ </form>
+ </ModalContent>
+ </Modal>
+ );
+};