Skip to content

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

Merge branch 'certificate-alerting' into feature/certificate-template

Sheen Capadngan69925721cc01
diff --cc backend/src/lib/api-docs/constants.ts
index 31079f318a,90eacb9a7a..e2a9bbd387
--- a/backend/src/lib/api-docs/constants.ts
+++ b/backend/src/lib/api-docs/constants.ts
@@@ -1088,7 -1088,7 +1088,8 @@@ export const CERTIFICATE_AUTHORITIES =
},
ISSUE_CERT: {
caId: "The ID of the CA to issue the certificate from",
+ certificateTemplateId: "The ID of the certificate template to issue the certificate from",
+ pkiCollectionId: "The ID of the PKI collection to add the certificate to",
friendlyName: "A friendly name for the certificate",
commonName: "The common name (CN) for the certificate",
altNames:
diff --cc backend/src/services/certificate-authority/certificate-authority-service.ts
index 1f1ffe9e1e,88f6860891..dd122ef9c2
--- a/backend/src/services/certificate-authority/certificate-authority-service.ts
+++ b/backend/src/services/certificate-authority/certificate-authority-service.ts
@@@ -54,10 -53,12 +56,13 @@@ type TCertificateAuthorityServiceFactor
TCertificateAuthorityDALFactory,
"transaction" | "create" | "findById" | "updateById" | "deleteById" | "findOne"
>;
- certificateAuthorityCertDAL: Pick<TCertificateAuthorityCertDALFactory, "create" | "findOne" | "transaction" | "find">;
+ certificateAuthorityCertDAL: Pick<
+ TCertificateAuthorityCertDALFactory,
+ "create" | "findOne" | "transaction" | "find" | "findById"
+ >;
certificateAuthoritySecretDAL: Pick<TCertificateAuthoritySecretDALFactory, "create" | "findOne">;
certificateAuthorityCrlDAL: Pick<TCertificateAuthorityCrlDALFactory, "create" | "findOne" | "update">;
+ certificateTemplateDAL: Pick<TCertificateTemplateDALFactory, "getById">;
certificateAuthorityQueue: TCertificateAuthorityQueueFactory; // TODO: Pick
certificateDAL: Pick<TCertificateDALFactory, "transaction" | "create" | "find">;
certificateBodyDAL: Pick<TCertificateBodyDALFactory, "create">;
@@@ -73,9 -76,10 +80,11 @@@ export const certificateAuthorityServic
certificateAuthorityCertDAL,
certificateAuthoritySecretDAL,
certificateAuthorityCrlDAL,
+ certificateTemplateDAL,
certificateDAL,
certificateBodyDAL,
+ pkiCollectionDAL,
+ pkiCollectionItemDAL,
projectDAL,
kmsService,
permissionService
@@@ -1006,7 -1013,7 +1018,8 @@@
*/
const issueCertFromCa = async ({
caId,
+ certificateTemplateId,
+ pkiCollectionId,
friendlyName,
commonName,
altNames,
@@@ -1244,8 -1237,8 +1274,9 @@@
*/
const signCertFromCa = async ({
caId,
+ certificateTemplateId,
csr,
+ pkiCollectionId,
friendlyName,
commonName,
altNames,
diff --cc backend/src/services/certificate-authority/certificate-authority-types.ts
index e04e0b8a90,3fef204bf2..c6bdeae301
--- a/backend/src/services/certificate-authority/certificate-authority-types.ts
+++ b/backend/src/services/certificate-authority/certificate-authority-types.ts
@@@ -86,8 -86,8 +86,9 @@@ export type TImportCertToCaDTO =
} & Omit<TProjectPermission, "projectId">;
export type TIssueCertFromCaDTO = {
- caId: string;
+ caId?: string;
+ certificateTemplateId?: string;
+ pkiCollectionId?: string;
friendlyName?: string;
commonName: string;
altNames: string;
@@@ -97,9 -97,9 +98,10 @@@
} & Omit<TProjectPermission, "projectId">;
export type TSignCertFromCaDTO = {
- caId: string;
+ caId?: string;
csr: string;
+ certificateTemplateId?: string;
+ pkiCollectionId?: string;
friendlyName?: string;
commonName?: string;
altNames: string;
diff --cc frontend/src/hooks/api/ca/types.ts
index 697e0e84c8,6927148713..e09ae16b83
--- a/frontend/src/hooks/api/ca/types.ts
+++ b/frontend/src/hooks/api/ca/types.ts
@@@ -78,8 -79,8 +79,9 @@@ export type TImportCaCertificateRespons
export type TCreateCertificateDTO = {
projectSlug: string;
- caId: string;
+ caId?: string;
+ certificateTemplateId?: string;
+ pkiCollectionId?: string;
friendlyName?: string;
commonName: string;
altNames: string; // sans
diff --cc frontend/src/views/Project/CertificatesPage/components/CertificatesTab/CertificatesTab.tsx
index f29a0bdb79,8dcd743482..71576d39de
--- a/frontend/src/views/Project/CertificatesPage/components/CertificatesTab/CertificatesTab.tsx
+++ b/frontend/src/views/Project/CertificatesPage/components/CertificatesTab/CertificatesTab.tsx
@@@ -1,6 -1,6 +1,7 @@@
import { motion } from "framer-motion";
+ import { PkiCollectionSection } from "../PkiAlertsTab/components";
+import { CertificateTemplatesSection } from "./components/CertificateTemplatesSection";
import { CertificatesSection } from "./components";
export const CertificatesTab = () => {
@@@ -12,7 -12,7 +13,8 @@@
animate={{ opacity: 1, translateX: 0 }}
exit={{ opacity: 0, translateX: 30 }}
>
+ <PkiCollectionSection />
+ <CertificateTemplatesSection />
<CertificatesSection />
</motion.div>
);
diff --cc frontend/src/views/Project/CertificatesPage/components/CertificatesTab/components/CertificateModal.tsx
index c3275c547f,227abe02a2..40223085bd
--- a/frontend/src/views/Project/CertificatesPage/components/CertificatesTab/components/CertificateModal.tsx
+++ b/frontend/src/views/Project/CertificatesPage/components/CertificatesTab/components/CertificateModal.tsx
@@@ -18,9 -18,8 +18,10 @@@ import
CaStatus,
useCreateCertificate,
useGetCert,
+ useGetCertTemplate,
useListWorkspaceCas,
- useListWorkspaceCertificateTemplates
++ useListWorkspaceCertificateTemplates,
+ useListWorkspacePkiCollections
} from "@app/hooks/api";
import { caTypeToNameMap } from "@app/hooks/api/ca/constants";
import { UsePopUpState } from "@app/hooks/usePopUp";
@@@ -28,8 -27,8 +29,9 @@@
import { CertificateContent } from "./CertificateContent";
const schema = z.object({
+ certificateTemplateId: z.string().optional(),
caId: z.string(),
+ collectionId: z.string().optional(),
friendlyName: z.string(),
commonName: z.string().trim().min(1),
altNames: z.string(),
@@@ -64,10 -61,10 +66,14 @@@ export const CertificateModal = ({ popU
status: CaStatus.ACTIVE
});
+ const { data } = useListWorkspacePkiCollections({
+ workspaceId: currentWorkspace?.id || ""
+ });
+
+ const { data: templatesData } = useListWorkspaceCertificateTemplates({
+ workspaceId: currentWorkspace?.id || ""
+ });
+
const { mutateAsync: createCertificate } = useCreateCertificate();
const {
@@@ -110,20 -97,21 +116,28 @@@
}
}, [cert]);
+ useEffect(() => {
+ if (!cert && selectedCertTemplate) {
+ setValue("ttl", selectedCertTemplate.ttl);
+ }
+ }, [selectedCertTemplate, cert]);
+
- const onFormSubmit = async ({ caId, friendlyName, commonName, altNames, ttl }: FormData) => {
+ const onFormSubmit = async ({
+ caId,
- collectionId,
+ friendlyName,
++ collectionId,
+ commonName,
+ altNames,
+ ttl
+ }: FormData) => {
try {
if (!currentWorkspace?.slug) return;
const { serialNumber, certificate, certificateChain, privateKey } = await createCertificate({
+ caId: !selectedCertTemplate ? caId : undefined,
+ certificateTemplateId: selectedCertTemplate ? selectedCertTemplateId : undefined,
projectSlug: currentWorkspace.slug,
- caId,
+ pkiCollectionId: collectionId,
friendlyName,
commonName,
altNames,
@@@ -201,35 -186,32 +215,61 @@@
</FormControl>
)}
/>
+ {(!selectedCertTemplateId || selectedCertTemplateId === CERT_TEMPLATE_NONE_VALUE) && (
+ <Controller
+ control={control}
+ name="caId"
+ render={({ field: { onChange, ...field }, fieldState: { error } }) => (
+ <FormControl
+ label="Issuing CA"
+ errorText={error?.message}
+ isError={Boolean(error)}
+ className="mt-4"
+ isRequired
+ >
+ <Select
+ defaultValue={field.value}
+ {...field}
+ onValueChange={(e) => onChange(e)}
+ className="w-full"
+ isDisabled={Boolean(cert)}
+ >
+ {(cas || []).map(({ id, type, dn }) => (
+ <SelectItem value={id} key={`ca-${id}`}>
+ {`${caTypeToNameMap[type]}: ${dn}`}
+ </SelectItem>
+ ))}
+ </Select>
+ </FormControl>
+ )}
+ />
+ )}
+ <Controller
+ control={control}
+ name="collectionId"
+ render={({ field: { onChange, ...field }, fieldState: { error } }) => (
+ <FormControl
+ label="Certificate Collection (Optional)"
+ errorText={error?.message}
+ isError={Boolean(error)}
+ className="mt-4"
+ >
+ <Select
+ defaultValue={field.value}
+ {...field}
+ onValueChange={(e) => onChange(e)}
+ className="w-full"
+ isDisabled={Boolean(cert)}
+ >
+ {(data?.collections || []).map(({ id, name }) => (
+ <SelectItem value={id} key={`pki-collection-${id}`}>
+ {name}
+ </SelectItem>
+ ))}
+ </Select>
+ </FormControl>
+ )}
+ />
<Controller
control={control}
defaultValue=""