Skip to content

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

misc: rename certificate template to certificate policy: frontend, docs and BDD testclear

Carlos Monastyrskibdab91ed8aa9
diff --cc backend/src/server/routes/index.ts
index 3f10b2a631,70b69e5f4c..693307836c
--- a/backend/src/server/routes/index.ts
+++ b/backend/src/server/routes/index.ts
@@@ -2318,8 -2322,7 +2322,8 @@@ export const registerRoutes = async
const certificateEstV3Service = certificateEstV3ServiceFactory({
internalCertificateAuthorityService,
- certificateTemplateV2Service,
- certificateTemplateV2DAL,
+ certificatePolicyService,
++ certificatePolicyDAL,
certificateAuthorityDAL,
certificateAuthorityCertDAL,
projectDAL,
diff --cc backend/src/server/routes/v1/certificate-policy-router.ts
index 8f3a21ed4c,d51c8e1407..417e531ac2
--- a/backend/src/server/routes/v1/certificate-policy-router.ts
+++ b/backend/src/server/routes/v1/certificate-policy-router.ts
@@@ -115,42 -115,30 +115,42 @@@ const policyAlgorithmsSchema = z.object
keyAlgorithm: z.array(z.string()).min(1, "At least one key algorithm must be provided").optional()
});
- const templateV2CaSettingsSchema = z
++const policyCaSettingsSchema = z
+ .object({
+ maxPathLength: z
+ .number()
+ .int("Path length must be an integer")
+ .min(-1, "Path length must be -1 (unlimited) or a non-negative integer")
+ .optional()
+ })
+ .nullable();
+
- const createCertificateTemplateV2Schema = z.object({
+ const createCertificatePolicySchema = z.object({
projectId: z.string().min(1),
name: z.string().min(1).max(255, "Name must be between 1 and 255 characters"),
description: z.string().max(1000).optional(),
- subject: z.array(templateV2SubjectSchema).optional(),
- sans: z.array(templateV2SanSchema).optional(),
- keyUsages: templateV2KeyUsagesSchema.optional(),
- extendedKeyUsages: templateV2ExtendedKeyUsagesSchema.optional(),
- algorithms: templateV2AlgorithmsSchema.optional(),
- validity: templateV2ValiditySchema.optional(),
- caSettings: templateV2CaSettingsSchema.optional()
+ subject: z.array(policySubjectSchema).optional(),
+ sans: z.array(policySanSchema).optional(),
+ keyUsages: policyKeyUsagesSchema.optional(),
+ extendedKeyUsages: policyExtendedKeyUsagesSchema.optional(),
+ algorithms: policyAlgorithmsSchema.optional(),
- validity: policyValiditySchema.optional()
++ validity: policyValiditySchema.optional(),
++ caSettings: policyCaSettingsSchema.optional()
});
- const updateCertificateTemplateV2Schema = z.object({
+ const updateCertificatePolicySchema = z.object({
name: z.string().min(1).max(255, "Name must be between 1 and 255 characters").optional(),
description: z.string().max(1000).optional(),
- subject: z.array(templateV2SubjectSchema).optional(),
- sans: z.array(templateV2SanSchema).optional(),
- keyUsages: templateV2KeyUsagesSchema.optional(),
- extendedKeyUsages: templateV2ExtendedKeyUsagesSchema.optional(),
- algorithms: templateV2AlgorithmsSchema.optional(),
- validity: templateV2ValiditySchema.optional(),
- caSettings: templateV2CaSettingsSchema.optional()
+ subject: z.array(policySubjectSchema).optional(),
+ sans: z.array(policySanSchema).optional(),
+ keyUsages: policyKeyUsagesSchema.optional(),
+ extendedKeyUsages: policyExtendedKeyUsagesSchema.optional(),
+ algorithms: policyAlgorithmsSchema.optional(),
- validity: policyValiditySchema.optional()
++ validity: policyValiditySchema.optional(),
++ caSettings: policyCaSettingsSchema.optional()
});
- export const registerCertificateTemplateRouter = async (server: FastifyZodProvider) => {
+ export const registerCertificatePolicyRouter = async (server: FastifyZodProvider) => {
server.route({
method: "POST",
url: "/",
diff --cc backend/src/services/certificate-est-v3/certificate-est-v3-service.test.ts
index d725a05182,ead72936b6..55e6fe81ce
--- a/backend/src/services/certificate-est-v3/certificate-est-v3-service.test.ts
+++ b/backend/src/services/certificate-est-v3/certificate-est-v3-service.test.ts
@@@ -171,15 -171,6 +171,15 @@@ describe("CertificateEstV3Service Secur
validateCertificateRequest: vi.fn()
};
- const mockCertificateTemplateV2DAL = {
++ const mockCertificatePolicyDAL = {
+ findById: vi.fn().mockResolvedValue({
- id: "template-v2-123",
++ id: "policy-123",
+ caSettings: null,
+ subject: [],
+ sans: []
+ })
+ };
+
const mockCertificateAuthorityDAL = {
findById: vi.fn(),
findByIdWithAssociatedCa: vi.fn()
@@@ -241,8 -236,7 +245,8 @@@
service = certificateEstV3ServiceFactory({
internalCertificateAuthorityService: mockInternalCertificateAuthorityService,
- certificateTemplateV2Service: mockCertificateTemplateV2Service,
- certificateTemplateV2DAL: mockCertificateTemplateV2DAL,
+ certificatePolicyService: mockCertificatePolicyService,
++ certificatePolicyDAL: mockCertificatePolicyDAL,
certificateAuthorityDAL: mockCertificateAuthorityDAL,
certificateAuthorityCertDAL: mockCertificateAuthorityCertDAL,
projectDAL: mockProjectDAL,
diff --cc backend/src/services/certificate-est-v3/certificate-est-v3-service.ts
index 95bc4ad317,714d3c8494..8a2317acb0
--- a/backend/src/services/certificate-est-v3/certificate-est-v3-service.ts
+++ b/backend/src/services/certificate-est-v3/certificate-est-v3-service.ts
@@@ -20,11 -19,10 +19,12 @@@ import { getProjectKmsCertificateKeyId
import { convertRawCertsToPkcs7 } from "../../ee/services/certificate-est/certificate-est-fns";
import { TLicenseServiceFactory } from "../../ee/services/license/license-service";
++import { TCertificatePolicyDALFactory } from "../certificate-policy/certificate-policy-dal";
type TCertificateEstV3ServiceFactoryDep = {
internalCertificateAuthorityService: Pick<TInternalCertificateAuthorityServiceFactory, "signCertFromCa">;
- certificateTemplateV2Service: Pick<TCertificateTemplateV2ServiceFactory, "validateCertificateRequest">;
- certificateTemplateV2DAL: Pick<TCertificateTemplateV2DALFactory, "findById">;
+ certificatePolicyService: Pick<TCertificatePolicyServiceFactory, "validateCertificateRequest">;
++ certificatePolicyDAL: Pick<TCertificatePolicyDALFactory, "findById">;
certificateAuthorityDAL: Pick<TCertificateAuthorityDALFactory, "findById" | "findByIdWithAssociatedCa">;
certificateAuthorityCertDAL: Pick<TCertificateAuthorityCertDALFactory, "find" | "findById">;
projectDAL: Pick<TProjectDALFactory, "findOne" | "updateById" | "transaction">;
@@@ -38,8 -36,7 +38,8 @@@ export type TCertificateEstV3ServiceFac
export const certificateEstV3ServiceFactory = ({
internalCertificateAuthorityService,
- certificateTemplateV2Service,
- certificateTemplateV2DAL,
+ certificatePolicyService,
++ certificatePolicyDAL,
certificateAuthorityCertDAL,
certificateAuthorityDAL,
projectDAL,
@@@ -146,16 -143,11 +146,16 @@@
});
}
- // Fetch the template to get caSettings for CA certificate support
- const template = await certificateTemplateV2DAL.findById(profile.certificateTemplateId);
++ // Fetch the policy to get caSettings for CA certificate support
++ const policy = await certificatePolicyDAL.findById(profile.certificatePolicyId);
+
const { certificate } = await internalCertificateAuthorityService.signCertFromCa({
isInternal: true,
caId: profile.caId,
csr,
- isFromProfile: true
+ isFromProfile: true,
- // Pass CA settings from template (null for leaf certificates, object for CA certificates)
- caSettings: template?.caSettings
++ // Pass CA settings from policy (null for leaf certificates, object for CA certificates)
++ caSettings: policy?.caSettings
});
return convertRawCertsToPkcs7([certificate.rawData]);
@@@ -277,16 -269,11 +277,16 @@@
});
}
- // Fetch the template to get caSettings for CA certificate support
- const template = await certificateTemplateV2DAL.findById(profile.certificateTemplateId);
++ // Fetch the policy to get caSettings for CA certificate support
++ const policy = await certificatePolicyDAL.findById(profile.certificatePolicyId);
+
const { certificate } = await internalCertificateAuthorityService.signCertFromCa({
isInternal: true,
caId: profile.caId,
csr,
- isFromProfile: true
+ isFromProfile: true,
- // Pass CA settings from template (null for leaf certificates, object for CA certificates)
- caSettings: template?.caSettings
++ // Pass CA settings from policy (null for leaf certificates, object for CA certificates)
++ caSettings: policy?.caSettings
});
return convertRawCertsToPkcs7([certificate.rawData]);
diff --cc backend/src/services/certificate-policy/certificate-policy-dal.ts
index 9e7fef563b,e5d7e25392..e7a6fbaf82
--- a/backend/src/services/certificate-policy/certificate-policy-dal.ts
+++ b/backend/src/services/certificate-policy/certificate-policy-dal.ts
@@@ -22,13 -17,13 +17,13 @@@ interface CountResult
count: string;
}
- export const certificateTemplateV2DALFactory = (db: TDbClient) => {
- const certificateTemplateV2Orm = ormify(db, TableName.PkiCertificateTemplateV2);
+ export const certificatePolicyDALFactory = (db: TDbClient) => {
+ const certificatePolicyOrm = ormify(db, TableName.PkiCertificatePolicy);
- const serializeJsonFields = (data: TCertificateTemplateV2Insert | TCertificateTemplateV2Update) => {
+ const serializeJsonFields = (data: TCertificatePolicyInsert | TCertificatePolicyUpdate) => {
const serialized = { ...data } as Record<string, unknown>;
- const jsonFields = ["subject", "sans", "keyUsages", "extendedKeyUsages", "algorithms", "validity"];
+ const jsonFields = ["subject", "sans", "keyUsages", "extendedKeyUsages", "algorithms", "validity", "caSettings"];
jsonFields.forEach((field) => {
const value = serialized[field];
@@@ -40,8 -35,8 +35,8 @@@
return serialized;
};
- const parseJsonFields = (raw: Record<string, unknown>): TCertificateTemplateV2 => {
+ const parseJsonFields = (raw: Record<string, unknown>): TCertificatePolicy => {
- const jsonFields = ["subject", "sans", "keyUsages", "extendedKeyUsages", "algorithms", "validity"];
+ const jsonFields = ["subject", "sans", "keyUsages", "extendedKeyUsages", "algorithms", "validity", "caSettings"];
const parsed = { ...raw } as Record<string, unknown>;
jsonFields.forEach((field) => {
diff --cc backend/src/services/certificate-policy/certificate-policy-schemas.ts
index 1b8fe918bb,1c8af8f6b1..9d93092899
--- a/backend/src/services/certificate-policy/certificate-policy-schemas.ts
+++ b/backend/src/services/certificate-policy/certificate-policy-schemas.ts
@@@ -105,33 -105,22 +105,33 @@@ const policyAlgorithmsSchema = z.object
.optional()
});
- export const templateV2CaSettingsSchema = z
++export const policyCaSettingsSchema = z
+ .object({
+ maxPathLength: z
+ .number()
+ .int("Path length must be an integer")
+ .min(-1, "Path length must be -1 (unlimited) or a non-negative integer")
+ .optional()
+ })
+ .nullable();
+
- export const certificateTemplateV2ResponseSchema = z.object({
+ export const certificatePolicyResponseSchema = z.object({
id: z.string().uuid(),
projectId: z.string().uuid("Project ID must be valid"),
name: z
.string()
.trim()
- .min(1, "Template name is required")
- .max(255, "Template name must be less than 255 characters")
- .regex(new RE2("^[a-zA-Z0-9-_]+$"), "Template name must contain only letters, numbers, hyphens, and underscores"),
+ .min(1, "Policy name is required")
+ .max(255, "Policy name must be less than 255 characters")
+ .regex(new RE2("^[a-zA-Z0-9-_]+$"), "Policy name must contain only letters, numbers, hyphens, and underscores"),
description: z.string().trim().max(1000, "Description must be less than 1000 characters").nullable().optional(),
- subject: z.array(templateV2SubjectSchema).optional(),
- sans: z.array(templateV2SanSchema).optional(),
- keyUsages: templateV2KeyUsagesSchema.optional(),
- extendedKeyUsages: templateV2ExtendedKeyUsagesSchema.optional(),
- algorithms: templateV2AlgorithmsSchema.optional(),
- validity: templateV2ValiditySchema.optional(),
- caSettings: templateV2CaSettingsSchema.optional(),
+ subject: z.array(policySubjectSchema).optional(),
+ sans: z.array(policySanSchema).optional(),
+ keyUsages: policyKeyUsagesSchema.optional(),
+ extendedKeyUsages: policyExtendedKeyUsagesSchema.optional(),
+ algorithms: policyAlgorithmsSchema.optional(),
+ validity: policyValiditySchema.optional(),
++ caSettings: policyCaSettingsSchema.optional(),
createdAt: z.date(),
updatedAt: z.date()
});
diff --cc backend/src/services/certificate-policy/certificate-policy-types.ts
index a20508f673,70995bdbdf..a107a984de
--- a/backend/src/services/certificate-policy/certificate-policy-types.ts
+++ b/backend/src/services/certificate-policy/certificate-policy-types.ts
@@@ -52,31 -45,21 +49,31 @@@ export type TCertificatePolicy = TPkiCe
extendedKeyUsages?: TTemplateV2Policy["extendedKeyUsages"];
algorithms?: TTemplateV2Policy["algorithms"];
validity?: TTemplateV2Policy["validity"];
+ caSettings?: TCaSettings | null;
};
- export type TCertificateTemplateV2Insert = TPkiCertificateTemplatesV2Insert & {
+ export type TCertificatePolicyInsert = TPkiCertificatePoliciesInsert & {
subject?: TTemplateV2Policy["subject"];
sans?: TTemplateV2Policy["sans"];
keyUsages?: TTemplateV2Policy["keyUsages"];
extendedKeyUsages?: TTemplateV2Policy["extendedKeyUsages"];
algorithms?: TTemplateV2Policy["algorithms"];
validity?: TTemplateV2Policy["validity"];
+ caSettings?: TCaSettings | null;
};
- export type TCertificateTemplateV2Update = Partial<
+ export type TCertificatePolicyUpdate = Partial<
Pick<
- TCertificateTemplateV2,
+ TCertificatePolicy,
- "name" | "description" | "subject" | "sans" | "keyUsages" | "extendedKeyUsages" | "algorithms" | "validity"
+ | "name"
+ | "description"
+ | "subject"
+ | "sans"
+ | "keyUsages"
+ | "extendedKeyUsages"
+ | "algorithms"
+ | "validity"
+ | "caSettings"
>
>;
diff --cc frontend/src/hooks/api/certificatePolicies/types.ts
index 0000000000,676827bc9e..20646bae3b
mode 000000,100644..100644
--- a/frontend/src/hooks/api/certificatePolicies/types.ts
+++ b/frontend/src/hooks/api/certificatePolicies/types.ts
@@@ -1,0 -1,86 +1,94 @@@
+ export type TCertificatePolicyRule = {
+ subject?: Array<{
- type: "common_name" | "organization" | "country";
++ type: "common_name" | "organization" | "country" | "state" | "locality" | "organizational_unit";
+ allowed?: string[];
+ required?: string[];
+ denied?: string[];
+ }>;
+ sans?: Array<{
+ type: "dns_name" | "ip_address" | "email" | "uri";
+ allowed?: string[];
+ required?: string[];
+ denied?: string[];
+ }>;
+ keyUsages?: {
+ allowed?: string[];
+ required?: string[];
+ denied?: string[];
+ };
+ extendedKeyUsages?: {
+ allowed?: string[];
+ required?: string[];
+ denied?: string[];
+ };
+ algorithms?: {
+ signature?: Array<
+ "SHA256-RSA" | "SHA384-RSA" | "SHA512-RSA" | "SHA256-ECDSA" | "SHA384-ECDSA" | "SHA512-ECDSA"
+ >;
+ keyAlgorithm?: Array<"RSA-2048" | "RSA-3072" | "RSA-4096" | "ECDSA-P256" | "ECDSA-P384">;
+ };
+ validity?: {
+ max?: string;
+ };
++ caSettings?: TCaSettings;
+ };
+
++export type TCaSettings = {
++ maxPathLength?: number;
++} | null;
++
+ export type TCertificatePolicy = {
+ id: string;
+ projectId: string;
+ name: string;
+ description?: string;
+ subject?: TCertificatePolicyRule["subject"];
+ sans?: TCertificatePolicyRule["sans"];
+ keyUsages?: TCertificatePolicyRule["keyUsages"];
+ extendedKeyUsages?: TCertificatePolicyRule["extendedKeyUsages"];
+ algorithms?: TCertificatePolicyRule["algorithms"];
+ validity?: TCertificatePolicyRule["validity"];
+ createdAt: string;
+ updatedAt: string;
++ caSettings?: TCaSettings | null;
+ };
+
+ export type TCreateCertificatePolicyDTO = {
+ projectId: string;
+ name: string;
+ description?: string;
+ subject?: TCertificatePolicyRule["subject"];
+ sans?: TCertificatePolicyRule["sans"];
+ keyUsages?: TCertificatePolicyRule["keyUsages"];
+ extendedKeyUsages?: TCertificatePolicyRule["extendedKeyUsages"];
+ algorithms?: TCertificatePolicyRule["algorithms"];
+ validity?: TCertificatePolicyRule["validity"];
++ caSettings?: TCaSettings;
+ };
+
+ export type TUpdateCertificatePolicyDTO = {
+ policyId: string;
+ name?: string;
+ description?: string;
+ subject?: TCertificatePolicyRule["subject"];
+ sans?: TCertificatePolicyRule["sans"];
+ keyUsages?: TCertificatePolicyRule["keyUsages"];
+ extendedKeyUsages?: TCertificatePolicyRule["extendedKeyUsages"];
+ algorithms?: TCertificatePolicyRule["algorithms"];
+ validity?: TCertificatePolicyRule["validity"];
++ caSettings?: TCaSettings;
+ };
+
+ export type TDeleteCertificatePolicyDTO = {
+ policyId: string;
+ };
+
+ export type TListCertificatePoliciesDTO = {
+ projectId: string;
+ limit?: number;
+ offset?: number;
+ };
+
+ export type TGetCertificatePolicyByIdDTO = {
+ policyId: string;
+ };
diff --cc frontend/src/pages/cert-manager/CertificatesPage/components/CertificateIssuanceModal.tsx
index fc99b57f52,bf8f48a06d..db3d93874b
--- a/frontend/src/pages/cert-manager/CertificatesPage/components/CertificateIssuanceModal.tsx
+++ b/frontend/src/pages/cert-manager/CertificatesPage/components/CertificateIssuanceModal.tsx
@@@ -24,15 -20,12 +24,15 @@@ import
} from "@app/components/v2";
import { useProject } from "@app/context";
import { useGetCert } from "@app/hooks/api";
++import { useGetCertificatePolicyById } from "@app/hooks/api/certificatePolicies";
import { EnrollmentType, useListCertificateProfiles } from "@app/hooks/api/certificateProfiles";
import { CertExtendedKeyUsage, CertKeyUsage } from "@app/hooks/api/certificates/enums";
import { useUnifiedCertificateIssuance } from "@app/hooks/api/certificates/mutations";
- import { useGetCertificateTemplateV2ById } from "@app/hooks/api/certificateTemplates/queries";
-import { useGetCertificatePolicyById } from "@app/hooks/api/certificatePolicies";
import { UsePopUpState } from "@app/hooks/usePopUp";
-import { CertSubjectAlternativeNameType } from "@app/pages/cert-manager/PoliciesPage/components/CertificatePoliciesTab/shared/certificate-constants";
+import {
+ CertSubjectAlternativeNameType,
+ CertSubjectAttributeType
- } from "@app/pages/cert-manager/PoliciesPage/components/CertificateTemplatesV2Tab/shared/certificate-constants";
++} from "@app/pages/cert-manager/PoliciesPage/components/CertificatePoliciesTab/shared/certificate-constants";
import { AlgorithmSelectors } from "./AlgorithmSelectors";
import { CertificateContent } from "./CertificateContent";
@@@ -47,21 -39,21 +47,21 @@@ const createSchema = (shouldShowSubject
profileId: z.string().min(1, "Profile is required"),
subjectAttributes: shouldShowSubjectSection
? z
-- .array(
-- z.object({
- type: z.nativeEnum(CertSubjectAttributeType),
- type: z.enum(["common_name"]),
-- value: z.string().min(1, "Value is required")
-- })
-- )
-- .min(1, "At least one subject attribute is required")
++ .array(
++ z.object({
++ type: z.nativeEnum(CertSubjectAttributeType),
++ value: z.string().min(1, "Value is required")
++ })
++ )
++ .min(1, "At least one subject attribute is required")
: z
-- .array(
-- z.object({
- type: z.nativeEnum(CertSubjectAttributeType),
- type: z.enum(["common_name"]),
-- value: z.string().min(1, "Value is required")
-- })
-- )
-- .optional(),
++ .array(
++ z.object({
++ type: z.nativeEnum(CertSubjectAttributeType),
++ value: z.string().min(1, "Value is required")
++ })
++ )
++ .optional(),
subjectAltNames: z
.array(
z.object({
@@@ -220,20 -202,18 +220,20 @@@ export const CertificateIssuanceModal
reset({
profileId: "",
subjectAttributes:
- subjectAttrs.length > 0 ? subjectAttrs : [{ type: "common_name" as const, value: "" }],
+ subjectAttrs.length > 0
+ ? subjectAttrs
+ : [{ type: CertSubjectAttributeType.COMMON_NAME, value: "" }],
subjectAltNames: cert.subjectAltNames
? cert.subjectAltNames.split(",").map((name) => {
-- const trimmed = name.trim();
-- if (trimmed.includes("@"))
-- return { type: CertSubjectAlternativeNameType.EMAIL, value: trimmed };
-- if (trimmed.match(/^\d+\.\d+\.\d+\.\d+$/))
-- return { type: CertSubjectAlternativeNameType.IP_ADDRESS, value: trimmed };
-- if (trimmed.startsWith("http"))
-- return { type: CertSubjectAlternativeNameType.URI, value: trimmed };
-- return { type: CertSubjectAlternativeNameType.DNS_NAME, value: trimmed };
-- })
++ const trimmed = name.trim();
++ if (trimmed.includes("@"))
++ return { type: CertSubjectAlternativeNameType.EMAIL, value: trimmed };
++ if (trimmed.match(/^\d+\.\d+\.\d+\.\d+$/))
++ return { type: CertSubjectAlternativeNameType.IP_ADDRESS, value: trimmed };
++ if (trimmed.startsWith("http"))
++ return { type: CertSubjectAlternativeNameType.URI, value: trimmed };
++ return { type: CertSubjectAlternativeNameType.DNS_NAME, value: trimmed };
++ })
: [],
ttl: "",
signatureAlgorithm: "",
@@@ -556,105 -512,6 +556,105 @@@
options={filteredExtendedKeyUsages}
requiredUsages={constraints.requiredExtendedKeyUsages}
/>
+ {constraints.templateAllowsCA && (
+ <AccordionItem value="basic-constraints">
+ <AccordionTrigger>Basic Constraints</AccordionTrigger>
+ <AccordionContent>
+ <div className="space-y-4 pl-2">
+ <Controller
+ control={control}
+ name="basicConstraints.isCA"
+ render={({ field: { value, onChange } }) => (
+ <div className="flex items-center gap-3">
+ <Checkbox
+ id="isCA"
+ isChecked={value || false}
+ onCheckedChange={onChange}
+ />
+ <div className="space-y-1">
+ <FormLabel
+ id="isCA"
+ className="cursor-pointer text-sm font-medium text-mineshaft-100"
+ label="Request as Certificate Authority"
+ />
+ <p className="text-xs text-bunker-300">
+ This certificate will be created as a certificate authority.
+ </p>
+ </div>
+ </div>
+ )}
+ />
+
+ {watch("basicConstraints.isCA") && (
+ <Controller
+ control={control}
+ name="basicConstraints.pathLength"
+ render={({ field, fieldState: { error } }) => (
+ <FormControl
+ label={
+ <div className="flex items-center gap-1">
+ <span className="mb-1">Path Length</span>
+ <Tooltip
+ content={
+ <div className="max-w-xs">
+ <p className="font-medium">Values:</p>
+ <ul className="mt-1 list-disc pl-4 text-xs">
+ <li>
+ <strong>-1</strong> = Unlimited depth
+ </li>
+ <li>
+ <strong>0</strong> = Can only sign end-entity certs
+ </li>
+ <li>
+ <strong>1+</strong> = CA levels allowed beneath
+ </li>
+ </ul>
+ </div>
+ }
+ >
+ <FontAwesomeIcon
+ icon={faQuestionCircle}
+ size="sm"
+ className="ml-1 text-mineshaft-400"
+ />
+ </Tooltip>
+ </div>
+ }
+ isError={Boolean(error)}
+ errorText={error?.message}
+ helperText={
+ constraints.maxPathLength !== undefined &&
- constraints.maxPathLength !== null &&
- constraints.maxPathLength !== -1
++ constraints.maxPathLength !== null &&
++ constraints.maxPathLength !== -1
+ ? `Required. Template maximum: ${constraints.maxPathLength}`
+ : "Controls how many CA levels can exist below this certificate."
+ }
+ >
+ <Input
+ {...field}
+ type="number"
+ placeholder={
+ constraints.maxPathLength !== undefined &&
- constraints.maxPathLength !== null &&
- constraints.maxPathLength !== -1
++ constraints.maxPathLength !== null &&
++ constraints.maxPathLength !== -1
+ ? "Enter path length (required)"
+ : "Leave empty for no constraint"
+ }
+ className="w-full"
+ value={field.value ?? ""}
+ onChange={(e) => {
+ const val = e.target.value;
+ field.onChange(val === "" ? undefined : Number(val));
+ }}
+ />
+ </FormControl>
+ )}
+ />
+ )}
+ </div>
+ </AccordionContent>
+ </AccordionItem>
+ )}
</Accordion>
</>
)}
diff --cc frontend/src/pages/cert-manager/CertificatesPage/components/useCertificateTemplate.ts
index 61967af3be,4e0ddb6eb9..685031e970
--- a/frontend/src/pages/cert-manager/CertificatesPage/components/useCertificateTemplate.ts
+++ b/frontend/src/pages/cert-manager/CertificatesPage/components/useCertificateTemplate.ts
@@@ -7,10 -7,9 +7,10 @@@ import
} from "@app/hooks/api/certificates/constants";
import {
CertSubjectAlternativeNameType,
+ CertSubjectAttributeType,
- mapTemplateKeyAlgorithmToApi,
- mapTemplateSignatureAlgorithmToApi
- } from "@app/pages/cert-manager/PoliciesPage/components/CertificateTemplatesV2Tab/shared/certificate-constants";
+ mapPolicyKeyAlgorithmToApi,
+ mapPolicySignatureAlgorithmToApi
+ } from "@app/pages/cert-manager/PoliciesPage/components/CertificatePoliciesTab/shared/certificate-constants";
const convertTemplateTtlToCertificateTtl = (templateTtl: string): string => {
const match = templateTtl.match(/^(\d+)([dmyh])$/);
diff --cc frontend/src/pages/cert-manager/PoliciesPage/components/CertificatePoliciesTab/CreatePolicyModal.tsx
index 1fbf75cf63,f6dfe0288d..f639ee9ce6
--- a/frontend/src/pages/cert-manager/PoliciesPage/components/CertificatePoliciesTab/CreatePolicyModal.tsx
+++ b/frontend/src/pages/cert-manager/PoliciesPage/components/CertificatePoliciesTab/CreatePolicyModal.tsx
@@@ -84,10 -76,10 +82,10 @@@ const SAN_TYPE_LABELS: Record<(typeof S
};
const SUBJECT_ATTRIBUTE_LABELS: Record<(typeof SUBJECT_ATTRIBUTE_INCLUDE_OPTIONS)[number], string> =
-- {
-- optional: "Allow",
-- prohibit: "Deny"
-- };
++{
++ optional: "Allow",
++ prohibit: "Deny"
++};
const SAN_INCLUDE_LABELS: Record<(typeof SAN_INCLUDE_OPTIONS)[number], string> = {
mandatory: "Require",
@@@ -184,39 -176,38 +182,38 @@@ export const CreatePolicyModal = ({ isO
};
const extendedKeyUsages = {
- requiredUsages: (templateData.extendedKeyUsages?.required ||
- []) as CertExtendedKeyUsageType[],
- optionalUsages: (templateData.extendedKeyUsages?.allowed || []) as CertExtendedKeyUsageType[]
+ requiredUsages: (policyData.extendedKeyUsages?.required || []) as CertExtendedKeyUsageType[],
+ optionalUsages: (policyData.extendedKeyUsages?.allowed || []) as CertExtendedKeyUsageType[]
};
- const validity = templateData.validity?.max
+ const validity = policyData.validity?.max
? (() => {
- const maxValue = templateData.validity.max;
- const maxValue = policyData.validity.max;
-- if (maxValue.length < 2) return undefined;
--
-- const lastChar = maxValue.slice(-1);
-- const numberPart = maxValue.slice(0, -1);
-- const value = parseInt(numberPart, 10);
--
-- if (Number.isNaN(value) || value <= 0 || numberPart !== value.toString()) {
-- return undefined;
-- }
--
-- let unit: CertDurationUnit = CertDurationUnit.DAYS;
-- if (lastChar === "d") {
-- unit = CertDurationUnit.DAYS;
-- } else if (lastChar === "m") {
-- unit = CertDurationUnit.MONTHS;
-- } else if (lastChar === "y") {
-- unit = CertDurationUnit.YEARS;
-- } else {
-- return undefined;
-- }
--
-- return {
-- maxDuration: { value, unit }
-- };
-- })()
++ const maxValue = policyData.validity.max;
++ if (maxValue.length < 2) return undefined;
++
++ const lastChar = maxValue.slice(-1);
++ const numberPart = maxValue.slice(0, -1);
++ const value = parseInt(numberPart, 10);
++
++ if (Number.isNaN(value) || value <= 0 || numberPart !== value.toString()) {
++ return undefined;
++ }
++
++ let unit: CertDurationUnit = CertDurationUnit.DAYS;
++ if (lastChar === "d") {
++ unit = CertDurationUnit.DAYS;
++ } else if (lastChar === "m") {
++ unit = CertDurationUnit.MONTHS;
++ } else if (lastChar === "y") {
++ unit = CertDurationUnit.YEARS;
++ } else {
++ return undefined;
++ }
++
++ return {
++ maxDuration: { value, unit }
++ };
++ })()
: { maxDuration: { value: 365, unit: CertDurationUnit.DAYS } };
const signatureAlgorithm = {
@@@ -229,35 -220,25 +226,35 @@@
defaultKeyType: ""
};
+ const basicConstraints = {
- isCA: templateData.caSettings !== undefined && templateData.caSettings !== null,
- maxPathLength: templateData.caSettings?.maxPathLength ?? undefined
++ isCA: policyData.caSettings !== undefined && policyData.caSettings !== null,
++ maxPathLength: policyData.caSettings?.maxPathLength ?? undefined
+ };
+
return {
- preset: TEMPLATE_PRESET_IDS.CUSTOM,
- name: templateData.name || "",
- description: templateData.description || "",
- basicConstraints,
+ preset: POLICY_PRESET_IDS.CUSTOM,
+ name: policyData.name || "",
+ description: policyData.description || "",
attributes,
subjectAlternativeNames,
keyUsages,
extendedKeyUsages,
validity,
signatureAlgorithm,
-- keyAlgorithm
++ keyAlgorithm,
++ basicConstraints
};
};
- const getDefaultValues = (): FormData & { preset: TemplatePresetId } => {
+ const getDefaultValues = (): FormData & { preset: PolicyPresetId } => {
return {
- preset: TEMPLATE_PRESET_IDS.CUSTOM,
+ preset: POLICY_PRESET_IDS.CUSTOM,
name: "",
description: "",
+ basicConstraints: {
+ isCA: false,
+ maxPathLength: undefined
+ },
attributes: [],
keyUsages: { requiredUsages: [], optionalUsages: [] },
extendedKeyUsages: { requiredUsages: [], optionalUsages: [] },
@@@ -466,12 -447,6 +463,12 @@@
validity.max = `${data.validity.maxDuration.value}${unit}`;
}
+ const caSettings = data.basicConstraints?.isCA
+ ? {
- maxPathLength: data.basicConstraints.maxPathLength ?? undefined
- }
++ maxPathLength: data.basicConstraints.maxPathLength ?? undefined
++ }
+ : null;
+
return {
name: data.name,
description: data.description,
@@@ -772,15 -745,15 +769,14 @@@
};
setValue("attributes", newAttributes);
- if (watchedPreset !== TEMPLATE_PRESET_IDS.CUSTOM) {
- setValue("preset", TEMPLATE_PRESET_IDS.CUSTOM);
+ if (watchedPreset !== POLICY_PRESET_IDS.CUSTOM) {
+ setValue("preset", POLICY_PRESET_IDS.CUSTOM);
}
}}
-- className={`flex-1 ${
-- attr.value && attr.value.length > 0 && attr.value[0] === ""
++ className={`flex-1 ${attr.value && attr.value.length > 0 && attr.value[0] === ""
? "border-red-500 focus:border-red-500"
: ""
-- }`}
++ }`}
required
/>
@@@ -889,15 -862,15 +885,14 @@@
};
setValue("subjectAlternativeNames", newSans);
- if (watchedPreset !== TEMPLATE_PRESET_IDS.CUSTOM) {
- setValue("preset", TEMPLATE_PRESET_IDS.CUSTOM);
+ if (watchedPreset !== POLICY_PRESET_IDS.CUSTOM) {
+ setValue("preset", POLICY_PRESET_IDS.CUSTOM);
}
}}
-- className={`flex-1 ${
-- san.value && san.value.length > 0 && san.value[0] === ""
++ className={`flex-1 ${san.value && san.value.length > 0 && san.value[0] === ""
? "border-red-500 focus:border-red-500"
: ""
-- }`}
++ }`}
required
/>
@@@ -1080,92 -1053,6 +1075,92 @@@
</div>
</AccordionContent>
</AccordionItem>
+
+ <AccordionItem value="basicConstraints" className="mt-4">
+ <AccordionTrigger>CA Settings</AccordionTrigger>
+ <AccordionContent>
+ <div className="space-y-4">
+ <Controller
+ control={control}
+ name="basicConstraints.isCA"
+ render={({ field: { value, onChange }, fieldState: { error } }) => (
+ <FormControl isError={Boolean(error)} errorText={error?.message}>
+ <div className="flex items-center gap-3">
+ <Checkbox
+ id="isCA"
+ isChecked={value || false}
+ onCheckedChange={onChange}
+ />
+ <div className="space-y-1">
+ <span className="text-sm font-medium text-mineshaft-100">
+ Allow Certificate Authority Issuance
+ </span>
+ <p className="text-xs text-bunker-300">
+ Enable this to allow issuing intermediate CA certificates.
+ </p>
+ </div>
+ </div>
+ </FormControl>
+ )}
+ />
+
+ {watch("basicConstraints.isCA") && (
+ <Controller
+ control={control}
+ name="basicConstraints.maxPathLength"
+ render={({ field, fieldState: { error } }) => (
+ <FormControl
+ label={
+ <div className="flex items-center gap-1">
+ <span className="mb-1">Max Path Length</span>
+ <Tooltip
+ content={
+ <div className="max-w-xs">
+ <p className="font-medium">Values:</p>
+ <ul className="mt-1 list-disc pl-4 text-xs">
+ <li>
+ <strong>-1</strong> = Unlimited (no restriction)
+ </li>
+ <li>
+ <strong>0</strong> = Can only sign end-entity certificates
+ </li>
+ <li>
+ <strong>1+</strong> = Number of CA levels allowed beneath
+ </li>
+ </ul>
+ </div>
+ }
+ >
+ <FontAwesomeIcon
+ icon={faQuestionCircle}
+ size="sm"
+ className="ml-1 text-mineshaft-400"
+ />
+ </Tooltip>
+ </div>
+ }
+ isError={Boolean(error)}
+ errorText={error?.message}
- helperText="Controls how many levels of CA certificates can be created below certificates issued from this template."
++ helperText="Controls how many levels of CA certificates can be created below certificates issued from this policy."
+ >
+ <Input
+ {...field}
+ type="number"
+ placeholder="Leave empty for no constraint"
+ className="w-full"
+ value={field.value ?? ""}
+ onChange={(e) => {
+ const val = e.target.value;
+ field.onChange(val === "" ? undefined : Number(val));
+ }}
+ />
+ </FormControl>
+ )}
+ />
+ )}
+ </div>
+ </AccordionContent>
+ </AccordionItem>
</Accordion>
<div className="flex gap-3">
diff --cc frontend/src/pages/cert-manager/PoliciesPage/components/CertificatePoliciesTab/shared/schemas.ts
index f5df667645,f74c6082d4..25f3c1da5c
--- a/frontend/src/pages/cert-manager/PoliciesPage/components/CertificatePoliciesTab/shared/schemas.ts
+++ b/frontend/src/pages/cert-manager/PoliciesPage/components/CertificatePoliciesTab/shared/schemas.ts
@@@ -52,29 -52,20 +52,29 @@@ export const uiKeyAlgorithmSchema = z.o
.min(1, "At least one key type must be selected")
});
+export const uiBasicConstraintsSchema = z.object({
+ isCA: z.boolean().default(false),
+ maxPathLength: z
+ .number()
+ .min(-1, "Path length must be -1 (unlimited) or greater")
+ .nullable()
+ .optional()
+});
+
export const uiPresetSchema = z
.enum([
- TEMPLATE_PRESET_IDS.CUSTOM,
- TEMPLATE_PRESET_IDS.TLS_SERVER,
- TEMPLATE_PRESET_IDS.TLS_CLIENT,
- TEMPLATE_PRESET_IDS.CODE_SIGNING,
- TEMPLATE_PRESET_IDS.DEVICE,
- TEMPLATE_PRESET_IDS.USER,
- TEMPLATE_PRESET_IDS.EMAIL_PROTECTION,
- TEMPLATE_PRESET_IDS.DUAL_PURPOSE_SERVER
+ POLICY_PRESET_IDS.CUSTOM,
+ POLICY_PRESET_IDS.TLS_SERVER,
+ POLICY_PRESET_IDS.TLS_CLIENT,
+ POLICY_PRESET_IDS.CODE_SIGNING,
+ POLICY_PRESET_IDS.DEVICE,
+ POLICY_PRESET_IDS.USER,
+ POLICY_PRESET_IDS.EMAIL_PROTECTION,
+ POLICY_PRESET_IDS.DUAL_PURPOSE_SERVER
])
- .default(TEMPLATE_PRESET_IDS.CUSTOM);
+ .default(POLICY_PRESET_IDS.CUSTOM);
- export const templateSchema = z.object({
+ export const policySchema = z.object({
preset: uiPresetSchema,
name: z
.string()