Skip to content

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

Improve PKI UI modals

Carlos Monastyrski1ec225d81a28
diff --git a/backend/src/db/migrations/20260113145337_add-ca-settings-to-certificate-templates-v2.ts b/backend/src/db/migrations/20260113145337_add-ca-settings-to-certificate-templates-v2.ts
index b91154f58b..90990a2dec 100644
--- a/backend/src/db/migrations/20260113145337_add-ca-settings-to-certificate-templates-v2.ts
+++ b/backend/src/db/migrations/20260113145337_add-ca-settings-to-certificate-templates-v2.ts
@@ -3,9 +3,9 @@ import { Knex } from "knex";
import { TableName } from "../schemas";
export async function up(knex: Knex): Promise<void> {
- const hasTemplateCaSettingsColumn = await knex.schema.hasColumn(TableName.PkiCertificateTemplateV2, "caSettings");
+ const hasTemplateCaSettingsColumn = await knex.schema.hasColumn(TableName.PkiCertificatePolicy, "caSettings");
if (!hasTemplateCaSettingsColumn) {
- await knex.schema.alterTable(TableName.PkiCertificateTemplateV2, (t) => {
+ await knex.schema.alterTable(TableName.PkiCertificatePolicy, (t) => {
t.jsonb("caSettings");
});
}
@@ -19,9 +19,9 @@ export async function up(knex: Knex): Promise<void> {
}
export async function down(knex: Knex): Promise<void> {
- const hasTemplateCaSettingsColumn = await knex.schema.hasColumn(TableName.PkiCertificateTemplateV2, "caSettings");
+ const hasTemplateCaSettingsColumn = await knex.schema.hasColumn(TableName.PkiCertificatePolicy, "caSettings");
if (hasTemplateCaSettingsColumn) {
- await knex.schema.alterTable(TableName.PkiCertificateTemplateV2, (t) => {
+ await knex.schema.alterTable(TableName.PkiCertificatePolicy, (t) => {
t.dropColumn("caSettings");
});
}
diff --git a/backend/src/db/schemas/pki-certificate-policies.ts b/backend/src/db/schemas/pki-certificate-policies.ts
index 52a69e20ee..ff378e2ebb 100644
--- a/backend/src/db/schemas/pki-certificate-policies.ts
+++ b/backend/src/db/schemas/pki-certificate-policies.ts
@@ -19,7 +19,8 @@ export const PkiCertificatePoliciesSchema = z.object({
algorithms: z.unknown().nullable().optional(),
validity: z.unknown().nullable().optional(),
createdAt: z.date(),
- updatedAt: z.date()
+ updatedAt: z.date(),
+ caSettings: z.unknown().nullable().optional()
});
export type TPkiCertificatePolicies = z.infer<typeof PkiCertificatePoliciesSchema>;
diff --git a/backend/src/services/certificate-policy/certificate-policy-service.ts b/backend/src/services/certificate-policy/certificate-policy-service.ts
index 7d89435798..60ca0ba3c4 100644
--- a/backend/src/services/certificate-policy/certificate-policy-service.ts
+++ b/backend/src/services/certificate-policy/certificate-policy-service.ts
@@ -602,6 +602,30 @@ export const certificatePolicyServiceFactory = ({
}
}
+ if (request.basicConstraints?.isCA) {
+ if (!template.caSettings) {
+ errors.push(
+ "CA certificate issuance is not allowed by this policy. The policy must have caSettings configured to issue CA certificates."
+ );
+ } else {
+ const { maxPathLength } = template.caSettings;
+
+ if (maxPathLength !== undefined && maxPathLength !== null && maxPathLength !== -1) {
+ if (request.basicConstraints.pathLength === undefined || request.basicConstraints.pathLength === null) {
+ errors.push(
+ `Path length is required when issuing CA certificates. Policy allows maximum path length of ${maxPathLength}.`
+ );
+ } else if (request.basicConstraints.pathLength > maxPathLength) {
+ errors.push(
+ `Requested path length (${request.basicConstraints.pathLength}) exceeds maximum allowed by policy (${maxPathLength}).`
+ );
+ } else if (request.basicConstraints.pathLength < 0 && request.basicConstraints.pathLength !== -1) {
+ errors.push("Path length must be -1 (unlimited), 0, or a positive integer.");
+ }
+ }
+ }
+ }
+
return {
isValid: errors.length === 0,
errors,
diff --git a/backend/src/services/certificate-policy/certificate-policy-types.ts b/backend/src/services/certificate-policy/certificate-policy-types.ts
index a107a984de..a36612d1bf 100644
--- a/backend/src/services/certificate-policy/certificate-policy-types.ts
+++ b/backend/src/services/certificate-policy/certificate-policy-types.ts
@@ -100,6 +100,10 @@ export interface TCertificateRequest {
notAfter?: Date;
signatureAlgorithm?: string;
keyAlgorithm?: string;
+ basicConstraints?: {
+ isCA: boolean;
+ pathLength?: number;
+ };
}
export interface TPolicyValidationResult {
diff --git a/backend/src/services/certificate-v3/certificate-v3-service.test.ts b/backend/src/services/certificate-v3/certificate-v3-service.test.ts
index b0009cfa5d..847b1f685f 100644
--- a/backend/src/services/certificate-v3/certificate-v3-service.test.ts
+++ b/backend/src/services/certificate-v3/certificate-v3-service.test.ts
@@ -229,7 +229,7 @@ describe("CertificateV3Service", () => {
enrollmentType: EnrollmentType.API,
issuerType: IssuerType.CA,
caId: "ca-123",
- certificatePolicyId: "template-123",
+ certificatePolicyId: "policy-123",
createdAt: new Date(),
updatedAt: new Date(),
slug: "test-profile",
@@ -267,13 +267,13 @@ describe("CertificateV3Service", () => {
enableDirectIssuance: true
};
- const mockTemplate = {
- id: "template-123",
- name: "Test Template",
+ const mockPolicy = {
+ id: "policy-123",
+ name: "Test Policy",
createdAt: new Date(),
updatedAt: new Date(),
projectId: "project-123",
- description: "Test template",
+ description: "Test policy",
signatureAlgorithm: { defaultAlgorithm: "RSA-SHA256" },
keyAlgorithm: { defaultKeyType: "RSA_2048" },
attributes: [
@@ -337,7 +337,7 @@ describe("CertificateV3Service", () => {
notBefore: new Date(),
notAfter: new Date(),
caId: "ca-123",
- certificatePolicyId: "template-123",
+ certificatePolicyId: "policy-123",
revokedAt: null,
revokedBy: null
};
@@ -349,7 +349,7 @@ describe("CertificateV3Service", () => {
warnings: []
});
vi.mocked(mockCertificateAuthorityDAL.findByIdWithAssociatedCa).mockResolvedValue(mockCA);
- vi.mocked(mockCertificatePolicyService.getPolicyById).mockResolvedValue(mockTemplate);
+ vi.mocked(mockCertificatePolicyService.getPolicyById).mockResolvedValue(mockPolicy);
vi.mocked(mockInternalCaService.issueCertFromCa).mockResolvedValue(mockCertificateResult as any);
vi.mocked(mockCertificateDAL.findOne).mockResolvedValue(mockCertRecord);
vi.mocked(mockCertificateDAL.findById).mockResolvedValue(mockCertRecord);
@@ -381,7 +381,7 @@ describe("CertificateV3Service", () => {
enrollmentType: EnrollmentType.API,
issuerType: IssuerType.CA,
caId: "ca-123",
- certificatePolicyId: "template-123",
+ certificatePolicyId: "policy-123",
createdAt: new Date(),
updatedAt: new Date(),
slug: "test-profile-camel",
@@ -421,13 +421,13 @@ describe("CertificateV3Service", () => {
enableDirectIssuance: true
};
- const mockTemplate = {
- id: "template-123",
- name: "Test Template for CamelCase",
+ const mockPolicy = {
+ id: "policy-123",
+ name: "Test Policy for CamelCase",
createdAt: new Date(),
updatedAt: new Date(),
projectId: "project-123",
- description: "Test template for camelCase validation",
+ description: "Test policy for camelCase validation",
signatureAlgorithm: { defaultAlgorithm: "RSA-SHA256" },
keyAlgorithm: { defaultKeyType: "RSA_2048" },
attributes: [
@@ -457,7 +457,7 @@ describe("CertificateV3Service", () => {
notBefore: new Date(),
notAfter: new Date(),
caId: "ca-123",
- certificatePolicyId: "template-123",
+ certificatePolicyId: "policy-123",
revokedAt: null,
altNames: null,
caCertId: null,
@@ -533,7 +533,7 @@ describe("CertificateV3Service", () => {
warnings: []
});
vi.mocked(mockCertificateAuthorityDAL.findByIdWithAssociatedCa).mockResolvedValue(mockCA);
- vi.mocked(mockCertificatePolicyService.getPolicyById).mockResolvedValue(mockTemplate);
+ vi.mocked(mockCertificatePolicyService.getPolicyById).mockResolvedValue(mockPolicy);
vi.mocked(mockInternalCaService.issueCertFromCa).mockResolvedValue(mockCertificateResultWithCa as any);
vi.mocked(mockCertificateDAL.findOne).mockResolvedValue(mockCertRecord);
vi.mocked(mockCertificateDAL.findById).mockResolvedValue({
@@ -570,9 +570,9 @@ describe("CertificateV3Service", () => {
...mockActor
});
- // Verify that the template validation service was called with mapped snake_case values
+ // Verify that the policy validation service was called with mapped snake_case values
expect(mockCertificatePolicyService.validateCertificateRequest).toHaveBeenCalledWith(
- "template-123",
+ "policy-123",
expect.objectContaining({
keyUsages: [
CertKeyUsageType.DIGITAL_SIGNATURE,
@@ -599,7 +599,7 @@ describe("CertificateV3Service", () => {
enrollmentType: EnrollmentType.EST, // Wrong enrollment type
issuerType: IssuerType.CA,
caId: "ca-123",
- certificatePolicyId: "template-123",
+ certificatePolicyId: "policy-123",
createdAt: new Date(),
updatedAt: new Date(),
slug: "test-profile-est",
@@ -653,7 +653,7 @@ describe("CertificateV3Service", () => {
enrollmentType: EnrollmentType.API,
issuerType: IssuerType.CA,
caId: "ca-123",
- certificatePolicyId: "template-123",
+ certificatePolicyId: "policy-123",
createdAt: new Date(),
updatedAt: new Date(),
slug: "test-profile-sign",
@@ -743,7 +743,7 @@ describe("CertificateV3Service", () => {
notBefore: new Date(),
notAfter: new Date(),
caId: "ca-123",
- certificatePolicyId: "template-123",
+ certificatePolicyId: "policy-123",
revokedAt: null,
altNames: null,
caCertId: null,
@@ -754,13 +754,13 @@ describe("CertificateV3Service", () => {
profileId: null
};
- const mockTemplate = {
- id: "template-123",
- name: "Test Signing Template",
+ const mockPolicy = {
+ id: "policy-123",
+ name: "Test Signing Policy",
createdAt: new Date(),
updatedAt: new Date(),
projectId: "project-123",
- description: "Test template for signing certificates",
+ description: "Test policy for signing certificates",
signatureAlgorithm: { defaultAlgorithm: "RSA-SHA256" },
keyAlgorithm: { defaultKeyType: "RSA_2048" },
attributes: [
@@ -780,7 +780,7 @@ describe("CertificateV3Service", () => {
vi.mocked(mockCertificateProfileDAL.findByIdWithConfigs).mockResolvedValue(mockProfile);
vi.mocked(mockCertificateAuthorityDAL.findByIdWithAssociatedCa).mockResolvedValue(mockCA);
- vi.mocked(mockCertificatePolicyService.getPolicyById).mockResolvedValue(mockTemplate);
+ vi.mocked(mockCertificatePolicyService.getPolicyById).mockResolvedValue(mockPolicy);
vi.mocked(mockCertificatePolicyService.validateCertificateRequest).mockResolvedValue({
isValid: true,
errors: [],
@@ -819,7 +819,7 @@ describe("CertificateV3Service", () => {
enrollmentType: EnrollmentType.EST, // Wrong enrollment type
issuerType: IssuerType.CA,
caId: "ca-123",
- certificatePolicyId: "template-123",
+ certificatePolicyId: "policy-123",
createdAt: new Date(),
updatedAt: new Date(),
slug: "test-profile-est-sign",
@@ -871,7 +871,7 @@ describe("CertificateV3Service", () => {
enrollmentType: EnrollmentType.EST, // Wrong enrollment type
issuerType: IssuerType.CA,
caId: "ca-123",
- certificatePolicyId: "template-123",
+ certificatePolicyId: "policy-123",
createdAt: new Date(),
updatedAt: new Date(),
slug: "test-profile-est-order",
@@ -906,7 +906,7 @@ describe("CertificateV3Service", () => {
slug: "test-profile",
projectId: "project-1",
caId: "ca-1",
- certificatePolicyId: "template-1",
+ certificatePolicyId: "policy-1",
enrollmentType: EnrollmentType.API,
issuerType: IssuerType.CA,
createdAt: new Date(),
@@ -959,13 +959,13 @@ describe("CertificateV3Service", () => {
}
};
- const rsaTemplate = {
- id: "template-1",
- name: "RSA Template",
+ const rsaPolicy = {
+ id: "policy-1",
+ name: "RSA Policy",
createdAt: new Date(),
updatedAt: new Date(),
projectId: "project-1",
- description: "RSA template for algorithm compatibility",
+ description: "RSA policy for algorithm compatibility",
signatureAlgorithm: {
allowedAlgorithms: ["SHA256-RSA", "SHA384-RSA"]
},
@@ -992,7 +992,7 @@ describe("CertificateV3Service", () => {
errors: [],
warnings: []
});
- vi.mocked(mockCertificatePolicyService.getPolicyById).mockResolvedValue(rsaTemplate);
+ vi.mocked(mockCertificatePolicyService.getPolicyById).mockResolvedValue(rsaPolicy);
vi.mocked(mockInternalCaService.issueCertFromCa).mockResolvedValue({
certificate: "cert",
certificateChain: "chain",
@@ -1118,13 +1118,13 @@ describe("CertificateV3Service", () => {
}
};
- const ecdsaTemplate = {
- id: "template-1",
- name: "ECDSA Template",
+ const ecdsaPolicy = {
+ id: "policy-1",
+ name: "ECDSA Policy",
createdAt: new Date(),
updatedAt: new Date(),
projectId: "project-1",
- description: "ECDSA template for algorithm compatibility",
+ description: "ECDSA policy for algorithm compatibility",
signatureAlgorithm: {
allowedAlgorithms: ["SHA256-ECDSA", "SHA384-ECDSA"]
},
@@ -1151,7 +1151,7 @@ describe("CertificateV3Service", () => {
errors: [],
warnings: []
});
- vi.mocked(mockCertificatePolicyService.getPolicyById).mockResolvedValue(ecdsaTemplate);
+ vi.mocked(mockCertificatePolicyService.getPolicyById).mockResolvedValue(ecdsaPolicy);
vi.mocked(mockInternalCaService.issueCertFromCa).mockResolvedValue({
certificate: "cert",
certificateChain: "chain",
@@ -1277,13 +1277,13 @@ describe("CertificateV3Service", () => {
}
};
- const rsaTemplate = {
- id: "template-1",
- name: "RSA 8192 Template",
+ const rsaPolicy = {
+ id: "policy-1",
+ name: "RSA 8192 Policy",
createdAt: new Date(),
updatedAt: new Date(),
projectId: "project-1",
- description: "RSA 8192 template for future key sizes",
+ description: "RSA 8192 policy for future key sizes",
signatureAlgorithm: {
allowedAlgorithms: ["SHA256-RSA"]
},
@@ -1310,7 +1310,7 @@ describe("CertificateV3Service", () => {
errors: [],
warnings: []
});
- vi.mocked(mockCertificatePolicyService.getPolicyById).mockResolvedValue(rsaTemplate);
+ vi.mocked(mockCertificatePolicyService.getPolicyById).mockResolvedValue(rsaPolicy);
vi.mocked(mockInternalCaService.issueCertFromCa).mockResolvedValue({
certificate: "cert",
certificateChain: "chain",
@@ -1436,13 +1436,13 @@ describe("CertificateV3Service", () => {
}
};
- const ecdsaTemplate = {
- id: "template-1",
- name: "ECDSA secp521r1 Template",
+ const ecdsaPolicy = {
+ id: "policy-1",
+ name: "ECDSA secp521r1 Policy",
createdAt: new Date(),
updatedAt: new Date(),
projectId: "project-1",
- description: "ECDSA secp521r1 template for future EC curves",
+ description: "ECDSA secp521r1 policy for future EC curves",
signatureAlgorithm: {
allowedAlgorithms: ["SHA384-ECDSA"]
},
@@ -1469,7 +1469,7 @@ describe("CertificateV3Service", () => {
errors: [],
warnings: []
});
- vi.mocked(mockCertificatePolicyService.getPolicyById).mockResolvedValue(ecdsaTemplate);
+ vi.mocked(mockCertificatePolicyService.getPolicyById).mockResolvedValue(ecdsaPolicy);
vi.mocked(mockInternalCaService.issueCertFromCa).mockResolvedValue({
certificate: "cert",
certificateChain: "chain",
@@ -1585,7 +1585,7 @@ describe("CertificateV3Service", () => {
projectId: "project-123",
createdAt: new Date(),
updatedAt: new Date(),
- certificatePolicyId: "template-123",
+ certificatePolicyId: "policy-123",
revocationReason: null,
caCertId: null,
renewedFromCertificateId: null,
@@ -1600,7 +1600,7 @@ describe("CertificateV3Service", () => {
enrollmentType: EnrollmentType.API,
issuerType: IssuerType.CA,
caId: "ca-123",
- certificatePolicyId: "template-123",
+ certificatePolicyId: "policy-123",
apiConfig: {
id: "api-config-123",
autoRenew: true,
@@ -1620,7 +1620,7 @@ describe("CertificateV3Service", () => {
updatedAt: new Date(),
enableDirectIssuance: true,
name: "Test CA",
- requireTemplateForIssuance: false,
+ requirePolicyForIssuance: false,
externalCa: undefined,
parentCaId: null,
type: "ROOT",
@@ -1659,10 +1659,10 @@ describe("CertificateV3Service", () => {
}
};
- const mockTemplate = {
- id: "template-123",
+ const mockPolicy = {
+ id: "policy-123",
projectId: "project-123",
- name: "Test Template",
+ name: "Test Policy",
createdAt: new Date(),
updatedAt: new Date(),
algorithms: {
@@ -1688,7 +1688,7 @@ describe("CertificateV3Service", () => {
vi.mocked(mockCertificateSecretDAL.findOne).mockResolvedValue({ id: "secret-123", certId: "cert-123" } as any);
vi.mocked(mockCertificateProfileDAL.findByIdWithConfigs).mockResolvedValue(mockProfile);
vi.mocked(mockCertificateAuthorityDAL.findByIdWithAssociatedCa).mockResolvedValue(mockCA);
- vi.mocked(mockCertificatePolicyService.getPolicyById).mockResolvedValue(mockTemplate);
+ vi.mocked(mockCertificatePolicyService.getPolicyById).mockResolvedValue(mockPolicy);
vi.mocked(mockCertificatePolicyService.validateCertificateRequest).mockResolvedValue({
isValid: true,
errors: [],
@@ -1742,11 +1742,11 @@ describe("CertificateV3Service", () => {
);
});
- it("should validate certificate against current template during renewal", async () => {
+ it("should validate certificate against current policy during renewal", async () => {
vi.mocked(mockCertificateDAL.findById).mockResolvedValue(mockOriginalCert);
vi.mocked(mockCertificateProfileDAL.findByIdWithConfigs).mockResolvedValue(mockProfile);
vi.mocked(mockCertificateAuthorityDAL.findByIdWithAssociatedCa).mockResolvedValue(mockCA);
- vi.mocked(mockCertificatePolicyService.getPolicyById).mockResolvedValue(mockTemplate);
+ vi.mocked(mockCertificatePolicyService.getPolicyById).mockResolvedValue(mockPolicy);
vi.mocked(mockCertificatePolicyService.validateCertificateRequest).mockResolvedValue({
isValid: false,
errors: ["Subject alternative name not allowed"],
@@ -1777,7 +1777,7 @@ describe("CertificateV3Service", () => {
})
).rejects.toThrow("Certificate renewal failed. Errors: Subject alternative name not allowed");
- // Should store template validation error
+ // Should store policy validation error
expect(mockCertificateDAL.updateById).toHaveBeenCalledWith("cert-123", {
renewalError: "Policy validation failed: Subject alternative name not allowed"
});
@@ -2007,7 +2007,7 @@ describe("CertificateV3Service", () => {
vi.mocked(mockCertificateProfileDAL.findByIdWithConfigs).mockResolvedValue(mockProfile);
vi.mocked(mockCertificateAuthorityDAL.findByIdWithAssociatedCa).mockResolvedValue(mockCA);
vi.mocked(mockCertificateSecretDAL.findOne).mockResolvedValue({ id: "secret-123", certId: "cert-123" } as any);
- vi.mocked(mockCertificatePolicyService.getPolicyById).mockResolvedValue(mockTemplate);
+ vi.mocked(mockCertificatePolicyService.getPolicyById).mockResolvedValue(mockPolicy);
vi.mocked(mockCertificatePolicyService.validateCertificateRequest).mockResolvedValue({
isValid: true,
errors: [],
diff --git a/backend/src/services/certificate-v3/certificate-v3-service.ts b/backend/src/services/certificate-v3/certificate-v3-service.ts
index 23762312c2..625993e0dd 100644
--- a/backend/src/services/certificate-v3/certificate-v3-service.ts
+++ b/backend/src/services/certificate-v3/certificate-v3-service.ts
@@ -984,8 +984,7 @@ export const certificateV3ServiceFactory = ({
keyAlgorithm: effectiveKeyAlgorithm,
signatureAlgorithm: effectiveSignatureAlgorithm,
status: CertificateRequestStatus.ISSUED,
- certificateId: selfSignedResult.certificateData.id,
- caSettings: certificateRequest.basicConstraints
+ certificateId: selfSignedResult.certificateData.id
});
return { ...selfSignedResult, certificateRequestId: certRequestResult.id };
@@ -1052,6 +1051,13 @@ export const certificateV3ServiceFactory = ({
validateCaSupport(ca, "direct certificate issuance");
validateAlgorithmCompatibility(ca, policy);
+ const shouldIssueAsCA = certificateRequest.basicConstraints?.isCA === true;
+ if (shouldIssueAsCA && !policy.caSettings) {
+ throw new BadRequestError({
+ message: "CA certificate issuance is not allowed by this policy. The policy must have caSettings configured."
+ });
+ }
+
const {
certificate,
certificateChain,
@@ -1066,6 +1072,8 @@ export const certificateV3ServiceFactory = ({
friendlyName: certificateSubject.common_name || "Certificate",
commonName: certificateSubject.common_name || "",
altNames: subjectAlternativeNames,
+ caSettings: shouldIssueAsCA ? policy.caSettings : undefined,
+ pathLength: certificateRequest.basicConstraints?.pathLength,
ttl: certificateRequest.validity.ttl,
keyUsages: convertKeyUsageArrayToLegacy(certificateRequest.keyUsages) || [],
extendedKeyUsages: convertExtendedKeyUsageArrayToLegacy(certificateRequest.extendedKeyUsages) || [],
@@ -1078,13 +1086,6 @@ export const certificateV3ServiceFactory = ({
actorAuthMethod,
actorOrgId,
isFromProfile: true,
- caSettings: template.caSettings,
- pathLength: certificateRequest.basicConstraints?.pathLength,
- organization: certificateSubject.organization,
- country: certificateSubject.country,
- state: certificateSubject.state,
- locality: certificateSubject.locality,
- ou: certificateSubject.organizational_unit,
tx
});
@@ -1244,12 +1245,21 @@ export const certificateV3ServiceFactory = ({
const effectiveSignatureAlgorithm = extractedSignatureAlgorithm;
const effectiveKeyAlgorithm = extractedKeyAlgorithm;
+ const shouldIssueAsCA = basicConstraints?.isCA === true;
+ if (shouldIssueAsCA && !policy.caSettings) {
+ throw new BadRequestError({
+ message: "CA certificate issuance is not allowed by this policy. The policy must have caSettings configured."
+ });
+ }
+
const { certificate, certificateChain, issuingCaCertificate, serialNumber, cert, certificateRequestId } =
await certificateDAL.transaction(async (tx) => {
const certResult = await internalCaService.signCertFromCa({
isInternal: true,
caId: ca.id,
csr,
+ caSettings: shouldIssueAsCA ? policy.caSettings : undefined,
+ pathLength: basicConstraints?.pathLength,
ttl: validity.ttl,
altNames: undefined,
notBefore: normalizeDateForApi(notBefore),
@@ -1257,8 +1267,6 @@ export const certificateV3ServiceFactory = ({
signatureAlgorithm: effectiveSignatureAlgorithm,
keyAlgorithm: effectiveKeyAlgorithm,
isFromProfile: true,
- caSettings: template.caSettings,
- pathLength: basicConstraints?.pathLength,
tx
});
@@ -1430,8 +1438,7 @@ export const certificateV3ServiceFactory = ({
altNames: certificateOrder.altNames?.map((san) => san.value).join(",") || "",
notBefore: certificateOrder.notBefore,
notAfter: certificateOrder.notAfter,
- status: CertificateRequestStatus.PENDING,
- caSettings: certificateOrder.basicConstraints
+ status: CertificateRequestStatus.PENDING
});
await certificateIssuanceQueue.queueCertificateIssuance({
@@ -1685,7 +1692,6 @@ export const certificateV3ServiceFactory = ({
actorAuthMethod,
actorOrgId,
internal: true,
- caSettings: template?.caSettings,
tx
});
diff --git a/frontend/src/pages/cert-manager/CertificatesPage/components/CertificateIssuanceModal.tsx b/frontend/src/pages/cert-manager/CertificatesPage/components/CertificateIssuanceModal.tsx
index db3d93874b..e6e9546f53 100644
--- a/frontend/src/pages/cert-manager/CertificatesPage/components/CertificateIssuanceModal.tsx
+++ b/frontend/src/pages/cert-manager/CertificatesPage/components/CertificateIssuanceModal.tsx
@@ -47,21 +47,21 @@ const createSchema = (shouldShowSubjectSection: boolean) => {
profileId: z.string().min(1, "Profile is required"),
subjectAttributes: shouldShowSubjectSection
? z
- .array(
- z.object({
- type: z.nativeEnum(CertSubjectAttributeType),
- 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),
- 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({
@@ -174,6 +174,7 @@ export const CertificateIssuanceModal = ({ popUp, handlePopUpToggle, profileId }
});
const actualSelectedProfileId = watch("profileId");
+ const watchedIsCA = watch("basicConstraints.isCA") || false;
const actualSelectedProfile = useMemo(
() => profilesData?.certificateProfiles?.find((p) => p.id === actualSelectedProfileId),
[profilesData?.certificateProfiles, actualSelectedProfileId]
@@ -225,15 +226,15 @@ export const CertificateIssuanceModal = ({ popUp, handlePopUpToggle, profileId }
: [{ 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: "",
@@ -569,88 +570,92 @@ export const CertificateIssuanceModal = ({ popUp, handlePopUpToggle, profileId }
<Checkbox
id="isCA"
isChecked={value || false}
- onCheckedChange={onChange}
+ onCheckedChange={(checked) => {
+ onChange(checked);
+ if (!checked) {
+ setValue("basicConstraints.pathLength", undefined);
+ }
+ }}
/>
<div className="space-y-1">
<FormLabel
id="isCA"
className="cursor-pointer text-sm font-medium text-mineshaft-100"
- label="Request as Certificate Authority"
+ label="Issue as Certificate Authority"
/>
<p className="text-xs text-bunker-300">
- This certificate will be created as a certificate authority.
+ This certificate will be issued with CA:TRUE
</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={
+ <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
+ ? `Required. Policy maximum: ${constraints.maxPathLength}`
+ : "Sets the pathLen for this CA certificate. Controls how many levels of sub-CAs can exist below."
+ }
+ >
+ <Input
+ {...field}
+ type="number"
+ placeholder={
constraints.maxPathLength !== undefined &&
- constraints.maxPathLength !== null &&
- constraints.maxPathLength !== -1
- ? `Required. Template maximum: ${constraints.maxPathLength}`
- : "Controls how many CA levels can exist below this certificate."
+ constraints.maxPathLength !== null &&
+ constraints.maxPathLength !== -1
+ ? "Enter path length (required)"
+ : "Leave empty for no constraint"
}
- >
- <Input
- {...field}
- type="number"
- placeholder={
- constraints.maxPathLength !== undefined &&
- 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>
- )}
- />
- )}
+ className="w-full"
+ value={field.value ?? ""}
+ isDisabled={!watchedIsCA}
+ onChange={(e) => {
+ const val = e.target.value;
+ field.onChange(val === "" ? undefined : Number(val));
+ }}
+ />
+ </FormControl>
+ )}
+ />
</div>
</AccordionContent>
</AccordionItem>
diff --git a/frontend/src/pages/cert-manager/CertificatesPage/components/SubjectAttributesField.tsx b/frontend/src/pages/cert-manager/CertificatesPage/components/SubjectAttributesField.tsx
index 4aaae72bea..ac7d01ff19 100644
--- a/frontend/src/pages/cert-manager/CertificatesPage/components/SubjectAttributesField.tsx
+++ b/frontend/src/pages/cert-manager/CertificatesPage/components/SubjectAttributesField.tsx
@@ -3,7 +3,7 @@ import { faPlus, faTrash } from "@fortawesome/free-solid-svg-icons";
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
import { Button, FormControl, IconButton, Input, Select, SelectItem } from "@app/components/v2";
-import { CertSubjectAttributeType } from "@app/pages/cert-manager/PoliciesPage/components/CertificateTemplatesV2Tab/shared/certificate-constants";
+import { CertSubjectAttributeType } from "@app/pages/cert-manager/PoliciesPage/components/CertificatePoliciesTab/shared/certificate-constants";
export type SubjectAttribute = {
type: CertSubjectAttributeType;
diff --git a/frontend/src/pages/cert-manager/PoliciesPage/components/CertificatePoliciesTab/CreatePolicyModal.tsx b/frontend/src/pages/cert-manager/PoliciesPage/components/CertificatePoliciesTab/CreatePolicyModal.tsx
index f639ee9ce6..493aaaeee0 100644
--- a/frontend/src/pages/cert-manager/PoliciesPage/components/CertificatePoliciesTab/CreatePolicyModal.tsx
+++ b/frontend/src/pages/cert-manager/PoliciesPage/components/CertificatePoliciesTab/CreatePolicyModal.tsx
@@ -82,10 +82,10 @@ const SAN_TYPE_LABELS: Record<(typeof SAN_TYPE_OPTIONS)[number], string> = {
};
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",
@@ -188,32 +188,32 @@ export const CreatePolicyModal = ({ isOpen, onClose, policy, mode = "create" }:
const validity = policyData.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 = {
@@ -298,6 +298,7 @@ export const CreatePolicyModal = ({ isOpen, onClose, policy, mode = "create" }:
optionalUsages: []
};
const watchedPreset = watch("preset") || POLICY_PRESET_IDS.CUSTOM;
+ const watchedIsCA = watch("basicConstraints.isCA") || false;
const handlePresetChange = async (presetId: PolicyPresetId) => {
setValue("preset", presetId);
@@ -465,8 +466,8 @@ export const CreatePolicyModal = ({ isOpen, onClose, policy, mode = "create" }:
const caSettings = data.basicConstraints?.isCA
? {
- maxPathLength: data.basicConstraints.maxPathLength ?? undefined
- }
+ maxPathLength: data.basicConstraints.maxPathLength ?? undefined
+ }
: null;
return {
@@ -773,10 +774,11 @@ export const CreatePolicyModal = ({ isOpen, onClose, policy, mode = "create" }:
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,10 +891,11 @@ export const CreatePolicyModal = ({ isOpen, onClose, policy, mode = "create" }:
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
/>
@@ -1077,7 +1080,7 @@ export const CreatePolicyModal = ({ isOpen, onClose, policy, mode = "create" }:
</AccordionItem>
<AccordionItem value="basicConstraints" className="mt-4">
- <AccordionTrigger>CA Settings</AccordionTrigger>
+ <AccordionTrigger>Basic Constraints</AccordionTrigger>
<AccordionContent>
<div className="space-y-4">
<Controller
@@ -1089,14 +1092,20 @@ export const CreatePolicyModal = ({ isOpen, onClose, policy, mode = "create" }:
<Checkbox
id="isCA"
isChecked={value || false}
- onCheckedChange={onChange}
+ onCheckedChange={(checked) => {
+ onChange(checked);
+ if (!checked) {
+ setValue("basicConstraints.maxPathLength", undefined);
+ }
+ }}
/>
<div className="space-y-1">
<span className="text-sm font-medium text-mineshaft-100">
- Allow Certificate Authority Issuance
+ Allow issuance of CA certificates
</span>
<p className="text-xs text-bunker-300">
- Enable this to allow issuing intermediate CA certificates.
+ When enabled, certificates issued under this policy may be Certificate
+ Authorities (CA:TRUE).
</p>
</div>
</div>
@@ -1104,60 +1113,59 @@ export const CreatePolicyModal = ({ isOpen, onClose, policy, mode = "create" }:
)}
/>
- {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 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>
- )}
- />
- )}
+ <Controller
+ control={control}
+ name="basicConstraints.maxPathLength"
+ render={({ field, fieldState: { error } }) => (
+ <FormControl
+ label={
+ <div className="flex items-center gap-1">
+ <span className="mb-1">Maximum allowed 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="Defines the pathLen constraint applied to issued CA certificates."
+ >
+ <Input
+ {...field}
+ type="number"
+ placeholder="Leave empty to omit the constraint"
+ className="w-full"
+ value={field.value ?? ""}
+ isDisabled={!watchedIsCA}
+ onChange={(e) => {
+ const val = e.target.value;
+ field.onChange(val === "" ? undefined : Number(val));
+ }}
+ />
+ </FormControl>
+ )}
+ />
</div>
</AccordionContent>
</AccordionItem>