Skip to content

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

Merge remote-tracking branch 'origin/main' into PKI-303

Carlos Monastyrskia2523679f89b
diff --cc backend/src/server/routes/v1/certificate-profiles-router.ts
index 2ea171ccbc,540739503c..011c2ddc74
--- a/backend/src/server/routes/v1/certificate-profiles-router.ts
+++ b/backend/src/server/routes/v1/certificate-profiles-router.ts
@@@ -16,7 -16,7 +16,8 @@@ import
CertKeyAlgorithm,
CertKeyUsageType,
CertSignatureAlgorithm,
- CertSubjectAlternativeNameType
++ CertSubjectAlternativeNameType,
+ domainComponentSchema
} from "@app/services/certificate-common/certificate-constants";
import { ExternalConfigUnionSchema } from "@app/services/certificate-profile/certificate-profile-external-config-schemas";
import { EnrollmentType, IssuerType } from "@app/services/certificate-profile/certificate-profile-types";
@@@ -50,7 -41,7 +51,8 @@@ const CertificateProfileDefaultsRespons
country: z.string().optional(),
state: z.string().optional(),
locality: z.string().optional(),
- subjectAltNames: SubjectAltNameDefaultsSchema
++ subjectAltNames: SubjectAltNameDefaultsSchema,
+ domainComponents: z.array(z.string()).optional()
})
.nullish();
@@@ -134,7 -125,7 +136,8 @@@ export const registerCertificateProfile
country: z.string().optional(),
state: z.string().optional(),
locality: z.string().optional(),
- subjectAltNames: SubjectAltNameDefaultsSchema
++ subjectAltNames: SubjectAltNameDefaultsSchema,
+ domainComponents: z.array(domainComponentSchema).optional()
})
.nullish()
})
@@@ -618,7 -609,7 +621,8 @@@
country: z.string().optional(),
state: z.string().optional(),
locality: z.string().optional(),
- subjectAltNames: SubjectAltNameDefaultsSchema
++ subjectAltNames: SubjectAltNameDefaultsSchema,
+ domainComponents: z.array(domainComponentSchema).optional()
})
.nullish()
})
diff --cc backend/src/services/certificate-policy/certificate-policy-service.ts
index ce08a13d66,4af9f74df7..bd6519a868
--- a/backend/src/services/certificate-policy/certificate-policy-service.ts
+++ b/backend/src/services/certificate-policy/certificate-policy-service.ts
@@@ -387,9 -390,63 +390,57 @@@ export const certificatePolicyServiceFa
errors.push(`${attrType} is not allowed by template policy (not defined in template)`);
}
}
- } else if (requestAttributes.size > 0) {
- // No subject policies defined but request has subject attributes - deny all
- for (const [attrType] of requestAttributes) {
- errors.push(`${attrType} is not allowed by template policy (no subject policies defined)`);
- }
}
+ // No subject policy defined means no subject constraint (allow all)
+ const domainComponentPolicy = subjectPolicies?.find(
+ (attrPolicy) => attrPolicy.type === CertSubjectAttributeType.DOMAIN_COMPONENT
+ );
+ const requestDomainComponents = request.domainComponents ?? [];
+ const dcFieldName = CertSubjectAttributeType.DOMAIN_COMPONENT;
+ if (domainComponentPolicy) {
+ if (!options?.skipRequired && domainComponentPolicy.required && domainComponentPolicy.required.length > 0) {
+ for (const requiredValue of domainComponentPolicy.required) {
+ const hasMatch = requestDomainComponents.some(
+ (dc) => validateValueAgainstConstraints(dc, [requiredValue], dcFieldName).isValid
+ );
+ if (!hasMatch) {
+ errors.push(`Required ${dcFieldName} matching pattern '${requiredValue}' not found in request`);
+ }
+ }
+ }
+
+ if (domainComponentPolicy.denied && domainComponentPolicy.denied.length > 0) {
+ for (const dc of requestDomainComponents) {
+ if (validateValueAgainstConstraints(dc, domainComponentPolicy.denied, dcFieldName).isValid) {
+ errors.push(`${dcFieldName} value '${dc}' is denied by template policy`);
+ }
+ }
+ }
+
+ if (domainComponentPolicy.allowed && domainComponentPolicy.allowed.length > 0 && requestDomainComponents.length) {
+ for (const dc of requestDomainComponents) {
+ const satisfiesRequired =
+ domainComponentPolicy.required && domainComponentPolicy.required.length > 0
+ ? domainComponentPolicy.required.some(
+ (requiredValue) => validateValueAgainstConstraints(dc, [requiredValue], dcFieldName).isValid
+ )
+ : false;
+
+ if (!satisfiesRequired) {
+ const validation = validateValueAgainstConstraints(dc, domainComponentPolicy.allowed, dcFieldName);
+ if (!validation.isValid && validation.error) {
+ errors.push(validation.error);
+ }
+ }
+ }
+ }
- } else if (requestDomainComponents.length > 0) {
- errors.push(
- subjectPolicies && subjectPolicies.length > 0
- ? `${dcFieldName} is not allowed by template policy (not defined in template)`
- : `${dcFieldName} is not allowed by template policy (no subject policies defined)`
- );
++ } else if (subjectPolicies && subjectPolicies.length > 0 && requestDomainComponents.length > 0) {
++ // A subject policy is defined but has no domain_component rule, so DCs aren't permitted.
++ // When no subject policy is defined at all, every subject attribute is allowed (see above).
++ errors.push(`${dcFieldName} is not allowed by template policy (not defined in template)`);
+ }
+
// Validate Subject Alternative Names
const sansPolicies = template.sans;
if (sansPolicies && sansPolicies.length > 0) {
diff --cc backend/src/services/certificate-profile/certificate-profile-types.ts
index 4f3402db73,90366d65e2..e1febfb034
--- a/backend/src/services/certificate-profile/certificate-profile-types.ts
+++ b/backend/src/services/certificate-profile/certificate-profile-types.ts
@@@ -37,7 -36,7 +37,8 @@@ export type TCertificateProfileDefault
country?: string;
state?: string;
locality?: string;
+ subjectAltNames?: { type: CertSubjectAlternativeNameType; value: string }[];
+ domainComponents?: string[];
};
export type TCertificateProfile = Omit<
diff --cc frontend/src/hooks/api/certificateProfiles/types.ts
index a196c51ed9,f434794bdc..d52345a182
--- a/frontend/src/hooks/api/certificateProfiles/types.ts
+++ b/frontend/src/hooks/api/certificateProfiles/types.ts
@@@ -28,7 -28,7 +28,8 @@@ export type TCertificateProfileDefault
country?: string;
state?: string;
locality?: string;
+ subjectAltNames?: { type: string; value: string }[];
+ domainComponents?: string[];
};
export type TCertificateProfile = {
diff --cc frontend/src/pages/cert-manager/CertificatesPage/components/useCertificatePolicy.ts
index 0f3d25ecc0,cbf3a35097..2348a55855
--- a/frontend/src/pages/cert-manager/CertificatesPage/components/useCertificatePolicy.ts
+++ b/frontend/src/pages/cert-manager/CertificatesPage/components/useCertificatePolicy.ts
@@@ -251,78 -230,75 +251,88 @@@ export const useCertificatePolicy =
});
newConstraints.allowedSubjectAttributeTypes =
subjectTypes.length > 0 ? subjectTypes : [CertSubjectAttributeType.COMMON_NAME];
+ } else {
+ // No subject policy allows every subject attribute type (allow all)
+ newConstraints.allowedSubjectAttributeTypes = [
+ CertSubjectAttributeType.COMMON_NAME,
+ CertSubjectAttributeType.ORGANIZATION,
+ CertSubjectAttributeType.ORGANIZATIONAL_UNIT,
+ CertSubjectAttributeType.COUNTRY,
+ CertSubjectAttributeType.STATE,
- CertSubjectAttributeType.LOCALITY
++ CertSubjectAttributeType.LOCALITY,
++ CertSubjectAttributeType.DOMAIN_COMPONENT
+ ];
+ }
- // Pre-populate subject attributes from profile defaults
- const defaultSubjectAttrs: Array<{ type: CertSubjectAttributeType; value: string }> = [];
- if (defaults?.commonName) {
- defaultSubjectAttrs.push({
- type: CertSubjectAttributeType.COMMON_NAME,
- value: defaults.commonName
- });
- }
- if (defaults?.organization) {
- defaultSubjectAttrs.push({
- type: CertSubjectAttributeType.ORGANIZATION,
- value: defaults.organization
- });
- }
- if (defaults?.organizationalUnit) {
- defaultSubjectAttrs.push({
- type: CertSubjectAttributeType.ORGANIZATIONAL_UNIT,
- value: defaults.organizationalUnit
- });
- }
- if (defaults?.country) {
- defaultSubjectAttrs.push({
- type: CertSubjectAttributeType.COUNTRY,
- value: defaults.country
- });
- }
- if (defaults?.state) {
- defaultSubjectAttrs.push({
- type: CertSubjectAttributeType.STATE,
- value: defaults.state
- });
- }
- if (defaults?.locality) {
+ // Pre-populate subject attributes from profile defaults
+ const defaultSubjectAttrs: Array<{ type: CertSubjectAttributeType; value: string }> = [];
+ if (defaults?.commonName) {
+ defaultSubjectAttrs.push({
+ type: CertSubjectAttributeType.COMMON_NAME,
+ value: defaults.commonName
+ });
+ }
+ if (defaults?.organization) {
+ defaultSubjectAttrs.push({
+ type: CertSubjectAttributeType.ORGANIZATION,
+ value: defaults.organization
+ });
+ }
+ if (defaults?.organizationalUnit) {
+ defaultSubjectAttrs.push({
+ type: CertSubjectAttributeType.ORGANIZATIONAL_UNIT,
+ value: defaults.organizationalUnit
+ });
+ }
+ if (defaults?.country) {
+ defaultSubjectAttrs.push({
+ type: CertSubjectAttributeType.COUNTRY,
+ value: defaults.country
+ });
+ }
+ if (defaults?.state) {
+ defaultSubjectAttrs.push({
+ type: CertSubjectAttributeType.STATE,
+ value: defaults.state
+ });
+ }
+ if (defaults?.locality) {
+ defaultSubjectAttrs.push({
+ type: CertSubjectAttributeType.LOCALITY,
+ value: defaults.locality
+ });
+ }
++ // Domain components are multi-valued: prefill one row per default value.
++ if (defaults?.domainComponents) {
++ defaults.domainComponents.forEach((dc: string) => {
+ defaultSubjectAttrs.push({
- type: CertSubjectAttributeType.LOCALITY,
- value: defaults.locality
++ type: CertSubjectAttributeType.DOMAIN_COMPONENT,
++ value: dc
+ });
- }
- if (defaults?.domainComponents) {
- defaults.domainComponents.forEach((dc: string) => {
- defaultSubjectAttrs.push({
- type: CertSubjectAttributeType.DOMAIN_COMPONENT,
- value: dc
- });
- });
- }
++ });
++ }
- const currentSubjectAttrs = watch("subjectAttributes");
- if (!currentSubjectAttrs || currentSubjectAttrs.length === 0) {
- if (defaultSubjectAttrs.length > 0) {
- // Filter to only allowed attribute types
- const filteredDefaults = defaultSubjectAttrs.filter((attr) =>
- newConstraints.allowedSubjectAttributeTypes.includes(attr.type)
- );
- const subjectValue =
- filteredDefaults.length > 0
- ? filteredDefaults
- : [{ type: newConstraints.allowedSubjectAttributeTypes[0], value: "" }];
- setValue("subjectAttributes", subjectValue);
- } else {
- const defaultType = newConstraints.allowedSubjectAttributeTypes[0];
- setValue("subjectAttributes", [{ type: defaultType, value: "" }]);
- }
+ // Switching profiles resets SAN entries so a previous profile's values don't carry over.
+ if (profileChanged) {
+ setValue("subjectAltNames", []);
+ }
+
+ const currentSubjectAttrs = watch("subjectAttributes");
+ if (profileChanged || !currentSubjectAttrs || currentSubjectAttrs.length === 0) {
+ if (defaultSubjectAttrs.length > 0) {
+ // Filter to only allowed attribute types
+ const filteredDefaults = defaultSubjectAttrs.filter((attr) =>
+ newConstraints.allowedSubjectAttributeTypes.includes(attr.type)
+ );
+ const subjectValue =
+ filteredDefaults.length > 0
+ ? filteredDefaults
+ : [{ type: newConstraints.allowedSubjectAttributeTypes[0], value: "" }];
+ setValue("subjectAttributes", subjectValue);
+ } else {
+ const defaultType = newConstraints.allowedSubjectAttributeTypes[0];
+ setValue("subjectAttributes", [{ type: defaultType, value: "" }]);
}
- } else {
- newConstraints.shouldShowSubjectSection = false;
- newConstraints.allowedSubjectAttributeTypes = [];
- setValue("subjectAttributes", undefined);
}
// Set isCA if template requires it
diff --cc frontend/src/pages/cert-manager/PoliciesPage/components/CertificateProfilesTab/CreateProfileModal.tsx
index 8f3c82546b,9a2962e27c..ebe432a018
--- a/frontend/src/pages/cert-manager/PoliciesPage/components/CertificateProfilesTab/CreateProfileModal.tsx
+++ b/frontend/src/pages/cert-manager/PoliciesPage/components/CertificateProfilesTab/CreateProfileModal.tsx
@@@ -390,13 -384,11 +400,16 @@@ const convertFormToDefaults =
break;
}
});
+ if (domainComponents.length > 0) {
+ result.domainComponents = domainComponents;
+ }
}
+ if (formDefaults.subjectAltNames && formDefaults.subjectAltNames.length > 0) {
+ const sans = formDefaults.subjectAltNames.filter((san) => san.value?.trim());
+ if (sans.length > 0) result.subjectAltNames = sans;
+ }
+
if (formDefaults.basicConstraints) {
result.basicConstraints = {
isCA: formDefaults.basicConstraints.isCA,