From 86348eb434799d9b81b8ca74bc1c62b75b1dc2cf Mon Sep 17 00:00:00 2001 From: = Date: Fri, 30 May 2025 20:39:41 +0530 Subject: [PATCH] feat: completed reptile reviews --- backend/src/server/routes/v2/pki-templates-router.ts | 2 +- .../internal/internal-certificate-authority-fns.ts | 2 +- .../services/pki-templates/pki-templates-service.ts | 10 ++++++++++ docs/documentation/platform/pki/pki-issuer.mdx | 2 +- .../components/PkiTemplatePermissionConditions.tsx | 2 +- 5 files changed, 14 insertions(+), 4 deletions(-) diff --git a/backend/src/server/routes/v2/pki-templates-router.ts b/backend/src/server/routes/v2/pki-templates-router.ts index a085aecdb..b6b969706 100644 --- a/backend/src/server/routes/v2/pki-templates-router.ts +++ b/backend/src/server/routes/v2/pki-templates-router.ts @@ -281,7 +281,7 @@ export const registerPkiTemplatesRouter = async (server: FastifyZodProvider) => body: z.object({ projectId: z.string(), ttl: z.string().refine((val) => ms(val) > 0, "TTL must be a positive number"), - csr: z.string().trim().min(1) + csr: z.string().trim().min(1).max(4096) }), response: { 200: z.object({ diff --git a/backend/src/services/certificate-authority/internal/internal-certificate-authority-fns.ts b/backend/src/services/certificate-authority/internal/internal-certificate-authority-fns.ts index 643a9e127..def2e2bed 100644 --- a/backend/src/services/certificate-authority/internal/internal-certificate-authority-fns.ts +++ b/backend/src/services/certificate-authority/internal/internal-certificate-authority-fns.ts @@ -490,7 +490,7 @@ export const InternalCertificateAuthorityFns = ({ notBefore: notBeforeDate, notAfter: notAfterDate, keyUsages: selectedKeyUsages, - extendedKeyUsages: extendedKeyUsages as CertExtendedKeyUsage[], + extendedKeyUsages: selectedExtendedKeyUsages, projectId: ca.projectId, certificateTemplateId: certificateTemplate.id }, diff --git a/backend/src/services/pki-templates/pki-templates-service.ts b/backend/src/services/pki-templates/pki-templates-service.ts index 96ffa0183..e72a2198a 100644 --- a/backend/src/services/pki-templates/pki-templates-service.ts +++ b/backend/src/services/pki-templates/pki-templates-service.ts @@ -120,6 +120,11 @@ export const pkiTemplatesServiceFactory = ({ subject(ProjectPermissionSub.CertificateTemplates, { name }) ); + const existingTemplate = await pkiTemplatesDAL.findOne({ name, projectId: ca.projectId }); + if (existingTemplate) { + throw new BadRequestError({ message: `Template with name ${name} already exists.` }); + } + const newTemplate = await pkiTemplatesDAL.create({ caId, name, @@ -182,6 +187,11 @@ export const pkiTemplatesServiceFactory = ({ ProjectPermissionPkiTemplateActions.Edit, subject(ProjectPermissionSub.CertificateTemplates, { name }) ); + + const existingTemplate = await pkiTemplatesDAL.findOne({ name, projectId }); + if (existingTemplate && existingTemplate.id !== certTemplate.id) { + throw new BadRequestError({ message: `Template with name ${name} already exists.` }); + } } const updatedTemplate = await pkiTemplatesDAL.updateById(certTemplate.id, { diff --git a/docs/documentation/platform/pki/pki-issuer.mdx b/docs/documentation/platform/pki/pki-issuer.mdx index 9f6d6595b..42d40114b 100644 --- a/docs/documentation/platform/pki/pki-issuer.mdx +++ b/docs/documentation/platform/pki/pki-issuer.mdx @@ -21,7 +21,7 @@ A typical workflow for using the Infisical PKI Issuer to issue certificates for 3. Installing `cert-manager` into your Kubernetes cluster. 4. Installing the Infisical PKI Issuer controller into your Kubernetes cluster. 5. Creating an `Issuer` or `ClusterIssuer` resource in your Kubernetes cluster to represent the Infisical PKI issuer you wish to use. -6. Create an the approver policy to accept certificate request. +6. Create the approver policy to accept certificate request. 7. Creating a `Certificate` resource in your Kubernetes cluster to represent a certificate you wish to issue. As part of this step, you specify the Kubernetes `Secret` to create and store the issued certificate and private key. 8. Consuming the issued certificate across your Kubernetes resources from the specified Kubernetes `Secret`. diff --git a/frontend/src/pages/project/RoleDetailsBySlugPage/components/PkiTemplatePermissionConditions.tsx b/frontend/src/pages/project/RoleDetailsBySlugPage/components/PkiTemplatePermissionConditions.tsx index b581b7bea..2ca4e2d14 100644 --- a/frontend/src/pages/project/RoleDetailsBySlugPage/components/PkiTemplatePermissionConditions.tsx +++ b/frontend/src/pages/project/RoleDetailsBySlugPage/components/PkiTemplatePermissionConditions.tsx @@ -132,7 +132,7 @@ export const PkiTemplatePermissionConditions = ({ position = 0, isDisabled }: Pr
items.remove(index)}