Infisical is the open-source platform for securing secrets, certificates, access, and AI Agents.
TypeScript acmeagentsai-agentscertificate-managementdevsecopsenvironment-variableskubernetesopen-sourcepampkipostgresprivate-caprivileged-access-managementsecret-managementsecret-managersecretssecrets-managementsecuritysecurity-toolsvault
feat: added collection selection for cert template
Sheen Capadngan97f5c33aea31
diff --git a/backend/src/db/migrations/20240815045235_add-certificate-template.ts b/backend/src/db/migrations/20240815045235_add-certificate-template.tsindex efe0daae30..9fbb606e29 100644--- a/backend/src/db/migrations/20240815045235_add-certificate-template.ts+++ b/backend/src/db/migrations/20240815045235_add-certificate-template.ts@@ -10,6 +10,8 @@ export async function up(knex: Knex): Promise<void> {tb.uuid("id", { primaryKey: true }).defaultTo(knex.fn.uuid());tb.uuid("caId").notNullable();tb.foreign("caId").references("id").inTable(TableName.CertificateAuthority).onDelete("CASCADE");+ tb.uuid("pkiCollectionId");+ tb.foreign("pkiCollectionId").references("id").inTable(TableName.PkiCollection).onDelete("SET NULL");tb.string("name").notNullable();tb.string("commonName").notNullable();tb.string("subjectAlternativeName").notNullable();diff --git a/backend/src/db/schemas/certificate-templates.ts b/backend/src/db/schemas/certificate-templates.tsindex d969d95fb1..6e19891953 100644--- a/backend/src/db/schemas/certificate-templates.ts+++ b/backend/src/db/schemas/certificate-templates.ts@@ -10,6 +10,7 @@ import { TImmutableDBKeys } from "./models";export const CertificateTemplatesSchema = z.object({id: z.string().uuid(),caId: z.string().uuid(),+ pkiCollectionId: z.string().uuid().nullable().optional(),name: z.string(),commonName: z.string(),subjectAlternativeName: z.string(),diff --git a/backend/src/server/routes/v1/certificate-router.ts b/backend/src/server/routes/v1/certificate-router.tsindex 989e794485..c492e0667c 100644--- a/backend/src/server/routes/v1/certificate-router.ts+++ b/backend/src/server/routes/v1/certificate-router.ts@@ -77,6 +77,7 @@ export const registerCertRouter = async (server: FastifyZodProvider) => {.trim().optional().describe(CERTIFICATE_AUTHORITIES.ISSUE_CERT.certificateTemplateId),+ pkiCollectionId: z.string().trim().optional().describe(CERTIFICATE_AUTHORITIES.SIGN_CERT.pkiCollectionId),friendlyName: z.string().trim().optional().describe(CERTIFICATE_AUTHORITIES.ISSUE_CERT.friendlyName),commonName: z.string().trim().min(1).describe(CERTIFICATE_AUTHORITIES.ISSUE_CERT.commonName),altNames: validateAltNamesField.describe(CERTIFICATE_AUTHORITIES.ISSUE_CERT.altNames),@@ -166,6 +167,7 @@ export const registerCertRouter = async (server: FastifyZodProvider) => {.trim().optional().describe(CERTIFICATE_AUTHORITIES.ISSUE_CERT.certificateTemplateId),+ pkiCollectionId: z.string().trim().optional().describe(CERTIFICATE_AUTHORITIES.SIGN_CERT.pkiCollectionId),csr: z.string().trim().min(1).describe(CERTIFICATE_AUTHORITIES.SIGN_CERT.csr),friendlyName: z.string().trim().optional().describe(CERTIFICATE_AUTHORITIES.SIGN_CERT.friendlyName),commonName: z.string().trim().min(1).optional().describe(CERTIFICATE_AUTHORITIES.SIGN_CERT.commonName),diff --git a/backend/src/server/routes/v1/certificate-template-router.ts b/backend/src/server/routes/v1/certificate-template-router.tsindex 90eab4521a..8a3bdd5232 100644--- a/backend/src/server/routes/v1/certificate-template-router.ts+++ b/backend/src/server/routes/v1/certificate-template-router.ts@@ -13,6 +13,7 @@ const sanitizedCertificateTemplate = CertificateTemplatesSchema.pick({name: true,commonName: true,subjectAlternativeName: true,+ pkiCollectionId: true,ttl: true});@@ -61,6 +62,7 @@ export const registerCertificateTemplateRouter = async (server: FastifyZodProvidschema: {body: z.object({caId: z.string(),+ pkiCollectionId: z.string().optional(),name: z.string().min(1),commonName: validateTemplateRegexField,subjectAlternativeName: validateTemplateRegexField,@@ -95,6 +97,7 @@ export const registerCertificateTemplateRouter = async (server: FastifyZodProvidschema: {body: z.object({caId: z.string().optional(),+ pkiCollectionId: z.string().optional(),name: z.string().min(1).optional(),commonName: validateTemplateRegexField.optional(),subjectAlternativeName: validateTemplateRegexField.optional(),diff --git a/backend/src/services/certificate-authority/certificate-authority-service.ts b/backend/src/services/certificate-authority/certificate-authority-service.tsindex dd122ef9c2..2234032089 100644--- a/backend/src/services/certificate-authority/certificate-authority-service.ts+++ b/backend/src/services/certificate-authority/certificate-authority-service.ts@@ -1033,6 +1033,7 @@ export const certificateAuthorityServiceFactory = ({}: TIssueCertFromCaDTO) => {let ca: TCertificateAuthorities | undefined;let certificateTemplate: TCertificateTemplates | undefined;+ let collectionId = pkiCollectionId;if (caId) {ca = await certificateAuthorityDAL.findById(caId);@@ -1044,6 +1045,7 @@ export const certificateAuthorityServiceFactory = ({});}+ collectionId = certificateTemplate.pkiCollectionId as string;ca = await certificateAuthorityDAL.findById(certificateTemplate.caId);}@@ -1070,8 +1072,8 @@ export const certificateAuthorityServiceFactory = ({}// check PKI collection- if (pkiCollectionId) {- const pkiCollection = await pkiCollectionDAL.findById(pkiCollectionId);+ if (collectionId) {+ const pkiCollection = await pkiCollectionDAL.findById(collectionId);if (!pkiCollection) throw new NotFoundError({ message: "PKI collection not found" });if (pkiCollection.projectId !== ca.projectId) throw new BadRequestError({ message: "Invalid PKI collection" });}@@ -1237,10 +1239,10 @@ export const certificateAuthorityServiceFactory = ({tx);- if (pkiCollectionId) {+ if (collectionId) {await pkiCollectionItemDAL.create({- pkiCollectionId,+ pkiCollectionId: collectionId,certId: cert.id},tx@@ -1290,6 +1292,7 @@ export const certificateAuthorityServiceFactory = ({}: TSignCertFromCaDTO) => {let ca: TCertificateAuthorities | undefined;let certificateTemplate: TCertificateTemplates | undefined;+ let collectionId = pkiCollectionId;if (caId) {ca = await certificateAuthorityDAL.findById(caId);@@ -1301,6 +1304,7 @@ export const certificateAuthorityServiceFactory = ({});}+ collectionId = certificateTemplate.pkiCollectionId as string;ca = await certificateAuthorityDAL.findById(certificateTemplate.caId);}@@ -1490,10 +1494,10 @@ export const certificateAuthorityServiceFactory = ({tx);- if (pkiCollectionId) {+ if (collectionId) {await pkiCollectionItemDAL.create({- pkiCollectionId,+ pkiCollectionId: collectionId,certId: cert.id},txdiff --git a/backend/src/services/certificate-template/certificate-template-service.ts b/backend/src/services/certificate-template/certificate-template-service.tsindex 3b2a5d0ed2..212fa05e48 100644--- a/backend/src/services/certificate-template/certificate-template-service.ts+++ b/backend/src/services/certificate-template/certificate-template-service.ts@@ -28,6 +28,7 @@ export const certificateTemplateServiceFactory = ({}: TCertificateTemplateServiceFactoryDep) => {const createCertTemplate = async ({caId,+ pkiCollectionId,name,commonName,subjectAlternativeName,@@ -58,6 +59,7 @@ export const certificateTemplateServiceFactory = ({const certificateTemplate = await certificateTemplateDAL.create({caId,+ pkiCollectionId,name,commonName,subjectAlternativeName,@@ -70,6 +72,7 @@ export const certificateTemplateServiceFactory = ({const updateCertTemplate = async ({id,caId,+ pkiCollectionId,name,commonName,subjectAlternativeName,@@ -110,6 +113,7 @@ export const certificateTemplateServiceFactory = ({const updatedCertTemplate = await certificateTemplateDAL.updateById(certTemplate.id, {caId,+ pkiCollectionId,commonName,subjectAlternativeName,name,diff --git a/backend/src/services/certificate-template/certificate-template-types.ts b/backend/src/services/certificate-template/certificate-template-types.tsindex 498a4cf594..c203b386cd 100644--- a/backend/src/services/certificate-template/certificate-template-types.ts+++ b/backend/src/services/certificate-template/certificate-template-types.ts@@ -2,6 +2,7 @@ import { TProjectPermission } from "@app/lib/types";export type TCreateCertTemplateDTO = {caId: string;+ pkiCollectionId?: string;name: string;commonName: string;subjectAlternativeName: string;@@ -11,6 +12,7 @@ export type TCreateCertTemplateDTO = {export type TUpdateCertTemplateDTO = {id: string;caId?: string;+ pkiCollectionId?: string;name?: string;commonName?: string;subjectAlternativeName?: string;diff --git a/frontend/src/hooks/api/certificateTemplates/types.ts b/frontend/src/hooks/api/certificateTemplates/types.tsindex 7b7d3a15f3..b7cd57a3d7 100644--- a/frontend/src/hooks/api/certificateTemplates/types.ts+++ b/frontend/src/hooks/api/certificateTemplates/types.ts@@ -8,6 +8,7 @@ export type TCertificateTemplateListEntry = {export type TCertificateTemplate = {id: string;caId: string;+ pkiCollectionId?: string;name: string;commonName: string;subjectAlternativeName: string;@@ -16,6 +17,7 @@ export type TCertificateTemplate = {export type TCreateCertificateTemplateDTO = {caId: string;+ pkiCollectionId?: string;name: string;commonName: string;subjectAlternativeName: string;@@ -26,6 +28,7 @@ export type TCreateCertificateTemplateDTO = {export type TUpdateCertificateTemplateDTO = {id: string;caId?: string;+ pkiCollectionId?: string;name?: string;commonName?: string;subjectAlternativeName?: string;diff --git a/frontend/src/views/Project/CertificatesPage/components/CertificatesTab/components/CertificateModal.tsx b/frontend/src/views/Project/CertificatesPage/components/CertificatesTab/components/CertificateModal.tsxindex 40223085bd..e5d6861346 100644--- a/frontend/src/views/Project/CertificatesPage/components/CertificatesTab/components/CertificateModal.tsx+++ b/frontend/src/views/Project/CertificatesPage/components/CertificatesTab/components/CertificateModal.tsx@@ -216,60 +216,61 @@ export const CertificateModal = ({ popUp, handlePopUpToggle }: Props) => {)}/>{(!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)}+ <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>- {(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>+ <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>+ )}+ />)}- /><Controllercontrol={control}defaultValue=""diff --git a/frontend/src/views/Project/CertificatesPage/components/CertificatesTab/components/CertificateTemplateModal.tsx b/frontend/src/views/Project/CertificatesPage/components/CertificatesTab/components/CertificateTemplateModal.tsxindex b8ef59dfa9..91b1031232 100644--- a/frontend/src/views/Project/CertificatesPage/components/CertificatesTab/components/CertificateTemplateModal.tsx+++ b/frontend/src/views/Project/CertificatesPage/components/CertificatesTab/components/CertificateTemplateModal.tsx@@ -19,6 +19,7 @@ import {useCreateCertTemplate,useGetCertTemplate,useListWorkspaceCas,+ useListWorkspacePkiCollections,useUpdateCertTemplate} from "@app/hooks/api";import { caTypeToNameMap } from "@app/hooks/api/ca/constants";@@ -36,6 +37,7 @@ const validateTemplateRegexField = zconst schema = z.object({caId: z.string(),+ collectionId: z.string().optional(),name: z.string().min(1),commonName: validateTemplateRegexField,subjectAlternativeName: validateTemplateRegexField,@@ -63,6 +65,10 @@ export const CertificateTemplateModal = ({ popUp, handlePopUpToggle }: Props) =>status: CaStatus.ACTIVE});+ const { data: collectionsData } = useListWorkspacePkiCollections({+ workspaceId: currentWorkspace?.id || ""+ });+const { mutateAsync: createCertTemplate } = useCreateCertTemplate();const { mutateAsync: updateCertTemplate } = useUpdateCertTemplate();@@ -82,6 +88,7 @@ export const CertificateTemplateModal = ({ popUp, handlePopUpToggle }: Props) =>name: certTemplate.name,commonName: certTemplate.commonName,subjectAlternativeName: certTemplate.subjectAlternativeName,+ collectionId: certTemplate.pkiCollectionId ?? undefined,ttl: certTemplate.ttl});} else {@@ -96,6 +103,7 @@ export const CertificateTemplateModal = ({ popUp, handlePopUpToggle }: Props) =>const onFormSubmit = async ({caId,+ collectionId,name,commonName,subjectAlternativeName,@@ -110,6 +118,7 @@ export const CertificateTemplateModal = ({ popUp, handlePopUpToggle }: Props) =>await updateCertTemplate({id: certTemplate.id,projectId: currentWorkspace.id,+ pkiCollectionId: collectionId,caId,name,commonName,@@ -124,6 +133,7 @@ export const CertificateTemplateModal = ({ popUp, handlePopUpToggle }: Props) =>} else {await createCertTemplate({projectId: currentWorkspace.id,+ pkiCollectionId: collectionId,caId,name,commonName,@@ -200,6 +210,31 @@ export const CertificateTemplateModal = ({ popUp, handlePopUpToggle }: Props) =></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"+ >+ {(collectionsData?.collections || []).map(({ id, name }) => (+ <SelectItem value={id} key={`pki-collection-${id}`}>+ {name}+ </SelectItem>+ ))}+ </Select>+ </FormControl>+ )}+ /><Controllercontrol={control}defaultValue=""diff --git a/frontend/src/views/Project/CertificatesPage/components/CertificatesTab/components/CertificateTemplatesTable.tsx b/frontend/src/views/Project/CertificatesPage/components/CertificatesTab/components/CertificateTemplatesTable.tsxindex a8042337ec..297b2d8178 100644--- a/frontend/src/views/Project/CertificatesPage/components/CertificatesTab/components/CertificateTemplatesTable.tsx+++ b/frontend/src/views/Project/CertificatesPage/components/CertificatesTab/components/CertificateTemplatesTable.tsx@@ -76,7 +76,7 @@ export const CertificateTemplatesTable = ({ handlePopUpOpen }: Props) => {}icon={<FontAwesomeIcon icon={faGear} />}>- Manage+ Manage Policies</DropdownMenuItem><ProjectPermissionCanI={ProjectPermissionActions.Delete}