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
Merge remote-tracking branch 'origin/main' into PKI-390
Carlos Monastyrski703dfb7dc9bb
diff --cc backend/src/db/schemas/certificates.tsindex 4473f0f04c,e6ba55baae..68fe46719d--- a/backend/src/db/schemas/certificates.ts+++ b/backend/src/db/schemas/certificates.ts@@@ -55,7 -55,8 +55,9 @@@ export const CertificatesSchema = z.objhsmPublicKeySpki: zodBuffer.nullable().optional(),subjectDomainComponents: z.string().nullable().optional(),orderId: z.string().uuid().default("00000000-0000-0000-0000-000000000000"),- customExtensions: z.unknown().nullable().optional()++ customExtensions: z.unknown().nullable().optional(),+ quotaKey: z.string().nullable().optional(),+ hasWildcard: z.boolean().nullable().optional()});export type TCertificates = z.infer<typeof CertificatesSchema>;diff --cc backend/src/ee/services/pki-acme/pki-acme-service.tsindex 705d57bb55,cb42a763e7..385118ebcd--- a/backend/src/ee/services/pki-acme/pki-acme-service.ts+++ b/backend/src/ee/services/pki-acme/pki-acme-service.ts@@@ -1098,8 -1095,16 +1108,17 @@@ export const pkiAcmeServiceFactory = (if (!validationResult.isValid) {throw new AcmeBadCSRError({ message: `Invalid CSR: ${validationResult.errors.join(", ")}` });}+ assertAcmeCaSupportsCustomExtensions(caType, validationResult.resolvedCustomExtensions?.length ?? 0);+ await validateCertificateRequestLicense({+ request: updatedCertificateRequest,+ altNames: (updatedCertificateRequest.subjectAlternativeNames ?? []).map((san) => san.value).join(","),+ projectId: profile.projectId,+ projectDAL,+ licenseService,+ quotaDeps: { projectDAL, licenseService, usageCounterDAL, keyStore }+ });+const certRequest = await certificateRequestService.createCertificateRequest({actor: ActorType.ACME_ACCOUNT,actorId: accountId,diff --cc backend/src/ee/services/pki-scep/pki-scep-service.tsindex 741fc68bba,3891108eac..4f2d283cc7--- a/backend/src/ee/services/pki-scep/pki-scep-service.ts+++ b/backend/src/ee/services/pki-scep/pki-scep-service.ts@@@ -920,8 -925,16 +927,17 @@@ export const pkiScepServiceFactory = (message: `Certificate request validation failed: ${validationResult.errors.join(", ")}`});}+ assertCaSupportsCustomExtensions(caType, validationResult.resolvedCustomExtensions?.length ?? 0);+ await validateCertificateRequestLicense({+ request: { ...certRequest, keyAlgorithm, signatureAlgorithm },+ altNames: (certRequest.subjectAlternativeNames ?? []).map((san) => san.value).join(","),+ projectId: profile.projectId,+ projectDAL,+ licenseService,+ quotaDeps: { projectDAL, licenseService, usageCounterDAL, keyStore }+ });+const newCertRequest = await certificateRequestService.createCertificateRequest({actor: ActorType.SCEP_ACCOUNT,actorId: profile.id,diff --cc backend/src/server/routes/v1/certificate-router.tsindex e22247c986,0257744d01..3297e0a3aa--- a/backend/src/server/routes/v1/certificate-router.ts+++ b/backend/src/server/routes/v1/certificate-router.ts@@@ -2,10 -2,8 +2,9 @@@import RE2 from "re2";import { z } from "zod";- import { CertificatesSchema } from "@app/db/schemas";import { EventType } from "@app/ee/services/audit-log/audit-log-types";import { ApiDocsTags, CERTIFICATES } from "@app/lib/api-docs";+import { BadRequestError } from "@app/lib/errors";import { ms } from "@app/lib/ms";import { isUuidV4 } from "@app/lib/validator";import { readLimit, writeLimit } from "@app/server/config/rateLimiter";diff --cc backend/src/services/certificate-authority/internal/internal-certificate-authority-service.tsindex 08eddbfcb9,bc011277af..4d1832f67e--- a/backend/src/services/certificate-authority/internal/internal-certificate-authority-service.ts+++ b/backend/src/services/certificate-authority/internal/internal-certificate-authority-service.ts@@@ -32,10 -32,9 +32,10 @@@ import { alphaNumericNanoId } from "@apimport { ActorAuthMethod, ActorType } from "@app/services/auth/auth-type";import { TCertificateBodyDALFactory } from "@app/services/certificate/certificate-body-dal";import { TCertificateDALFactory } from "@app/services/certificate/certificate-dal";+import { CERT_SUBJECT_ALTERNATIVE_NAMES } from "@app/services/certificate-common/certificate-constants";import type { THsmConnectorServiceFactory } from "@app/services/hsm-connector/hsm-connector-service";import { TKmsServiceFactory } from "@app/services/kms/kms-service";- import { ActiveCerts } from "@app/services/license-client";+ import { ActiveCerts, WildcardCerts } from "@app/services/license-client";import { TUsageMeteringServiceFactory } from "@app/services/license-client/usage";import { TPkiCollectionDALFactory } from "@app/services/pki-collection/pki-collection-dal";import { TPkiCollectionItemDALFactory } from "@app/services/pki-collection/pki-collection-item-dal";diff --cc backend/src/services/certificate-v3/certificate-approval-fns.tsindex 92535db362,35adb4f25e..5142321650--- a/backend/src/services/certificate-v3/certificate-approval-fns.ts+++ b/backend/src/services/certificate-v3/certificate-approval-fns.ts@@@ -537,8 -534,24 +553,25 @@@ export const certificateApprovalServiceif (effectiveBasicConstraints) {mappedReconstructedRequest.basicConstraints = effectiveBasicConstraints;}+ mappedReconstructedRequest.customExtensions = toRequestCustomExtensions(certRequest.customExtensions);+ // Same re-check the non-CSR branch does: this path returns before that one runs, and an approval+ // can land days after the count it was compared against at submit.+ const {+ quotaOrgId: csrQuotaOrgId,+ isNewQuotaKey: isNewCsrQuotaKey,+ isWildcard: isCsrWildcard+ } = await assertCertificateQuotaForProject({+ projectId: profile.projectId,+ commonName: mappedReconstructedRequest.commonName,+ // A CSR-derived request carries its SANs in subjectAlternativeNames, not altNames.+ altNames: (mappedReconstructedRequest.subjectAlternativeNames ?? [])+ .map((san: { value: string }) => san.value)+ .join(","),+ deps: { projectDAL, licenseService, usageCounterDAL, keyStore },+ isApprovedRequest: true+ });+const revalidationResult = await certificatePolicyService.validateCertificateRequest(profile.certificatePolicyId,mappedReconstructedRequest@@@ -747,19 -770,19 +792,20 @@@ttl: effectiveTtl,signatureAlgorithm: certRequest.signatureAlgorithm || "",keyAlgorithm: certRequest.keyAlgorithm || "",- commonName: certRequest.commonName || "",- altNames: altNames?.map((san) => ({ type: san.type, value: san.value })) || [],- keyUsages: certRequest.keyUsages || [],- extendedKeyUsages: certRequest.extendedKeyUsages || [],+ commonName: mappedReconstructedRequest.commonName || "",+ altNames:+ mappedReconstructedRequest.subjectAlternativeNames?.map((san) => ({ type: san.type, value: san.value })) || [],+ keyUsages: convertKeyUsageArrayToLegacy(mappedReconstructedRequest.keyUsages) || [],+ extendedKeyUsages: convertExtendedKeyUsageArrayToLegacy(mappedReconstructedRequest.extendedKeyUsages) || [],certificateRequestId,csr: certRequest.csr || undefined,- organization: certRequest.organization || undefined,- organizationalUnit: certRequest.organizationalUnit || undefined,- country: certRequest.country || undefined,- state: certRequest.state || undefined,- locality: certRequest.locality || undefined,+ organization: mappedReconstructedRequest.organization || undefined,+ organizationalUnit: mappedReconstructedRequest.organizationalUnit || undefined,+ country: mappedReconstructedRequest.country || undefined,+ state: mappedReconstructedRequest.state || undefined,+ locality: mappedReconstructedRequest.locality || undefined,basicConstraints: certRequest.basicConstraints as { isCA: boolean; pathLength?: number | null } | null,+ customExtensions: revalidationResult.resolvedCustomExtensions,...(certRequest.applicationId && { applicationId: certRequest.applicationId })});@@@ -1134,27 -1151,39 +1180,41 @@@});}- const issuerType = targetProfile?.issuerType || (targetProfile?.caId ? IssuerType.CA : IssuerType.SELF_SIGNED);+ // Re-checked here as well as at submit: an approval can land days later, so the count compared+ // against at submit says nothing about current usage. Not pushed into certificateDAL.create,+ // which would also gate discovery and renewal writes.+ const { quotaOrgId, isNewQuotaKey, isWildcard } = await assertCertificateQuotaForProject({+ projectId: targetProfile.projectId,+ commonName: certificateRequestInput.commonName,+ altNames: (altNames ?? []).map((san) => san.value).join(","),+ deps: { projectDAL, licenseService, usageCounterDAL, keyStore },+ isApprovedRequest: true+ });- if (issuerType === IssuerType.SELF_SIGNED) {- return await $processSelfSignedRequest(- certificateRequestInput,- certificateRequestId,- targetProfile,- certPolicy,- certRequest.applicationId,- validationResult.resolvedCustomExtensions- );- }+ const issuerType = targetProfile?.issuerType || (targetProfile?.caId ? IssuerType.CA : IssuerType.SELF_SIGNED);- return await $processCASignedRequest(- certificateRequestInput,- certificateRequestId,- targetProfile,- certPolicy,- certRequest.applicationId,- validationResult.resolvedCustomExtensions- );+ const issuanceResult =+ issuerType === IssuerType.SELF_SIGNED+ ? await $processSelfSignedRequest(+ certificateRequestInput,+ certificateRequestId,+ targetProfile,+ certPolicy,- certRequest.applicationId++ certRequest.applicationId,++ validationResult.resolvedCustomExtensions+ )+ : await $processCASignedRequest(+ certificateRequestInput,+ certificateRequestId,+ targetProfile,+ certPolicy,- certRequest.applicationId++ certRequest.applicationId,++ validationResult.resolvedCustomExtensions+ );++ if (isNewQuotaKey) await recordNewCertificateQuotaKey(quotaOrgId, { keyStore }, isWildcard);++ return issuanceResult;} catch (error) {await certificateRequestDAL.updateById(certificateRequestId, {status: CertificateRequestStatus.FAILED,diff --cc backend/src/services/certificate-v3/certificate-v3-service.tsindex 4c0a2babc4,e4094c67ba..1e547c64fa--- a/backend/src/services/certificate-v3/certificate-v3-service.ts+++ b/backend/src/services/certificate-v3/certificate-v3-service.ts@@@ -37,12 -38,10 +38,13 @@@ import { validateAwsPcaCaIssuanceInputimport { TCertificateAuthorityDALFactory } from "@app/services/certificate-authority/certificate-authority-dal";import { CaType } from "@app/services/certificate-authority/certificate-authority-enums";import { assertCaInProfileProject } from "@app/services/certificate-authority/certificate-authority-fns";-import { caUsesExternalIssuanceQueue } from "@app/services/certificate-authority/certificate-authority-maps";+import {+ assertCaSupportsCustomExtensions,+ caUsesExternalIssuanceQueue+} from "@app/services/certificate-authority/certificate-authority-maps";import { validateGoDaddyIssuanceInputs } from "@app/services/certificate-authority/godaddy/godaddy-certificate-authority-validators";import { TInternalCertificateAuthorityServiceFactory } from "@app/services/certificate-authority/internal/internal-certificate-authority-service";+ import { recordNewCertificateQuotaKey } from "@app/services/certificate-common/certificate-quota-fns";import { TCertificatePolicyServiceFactory } from "@app/services/certificate-policy/certificate-policy-service";import { TCertificateProfileDALFactory } from "@app/services/certificate-profile/certificate-profile-dal";import { EnrollmentType, IssuerType } from "@app/services/certificate-profile/certificate-profile-types";@@@ -1777,10 -1771,20 +1801,21 @@@ export const certificateV3ServiceFactormappedCertificateRequest.signatureAlgorithm = extractedSignatureAlgorithm;}+ // Not recorded here: the issuance queue creates the certificate later, once the external CA+ // responds, so the cached count picks it up on its next refresh.+ await validateCertificateRequestLicense({+ request: mappedCertificateRequest,+ altNames: (mappedCertificateRequest.subjectAlternativeNames ?? []).map((san) => san.value).join(","),+ projectId: profile.projectId,+ projectDAL,+ licenseService,+ quotaDeps: $quotaDeps+ });+const validationResult = await certificatePolicyService.validateCertificateRequest(profile.certificatePolicyId,- mappedCertificateRequest+ mappedCertificateRequest,+ { profileCustomExtensions: profile.defaults?.customExtensions });if (!validationResult.isValid) {diff --cc backend/src/services/certificate/certificate-fns.tsindex cb211811c0,99bcdb0608..b1a47d41d6--- a/backend/src/services/certificate/certificate-fns.ts+++ b/backend/src/services/certificate/certificate-fns.ts@@@ -403,9 -397,9 +403,11 @@@ export const extractCertificateFieldsisCA: parsed.basicConstraints?.isCA ?? null,pathLength: parsed.basicConstraints?.pathLength ?? null,- // Callers spread these last so the issued usages win over the requested ones. Absent when the- // certificate carries no such extension, leaving the requested values in place.+ customExtensions: issuedCustomExtensions.length ? JSON.stringify(issuedCustomExtensions) : null,+++ // Callers spread these last so the issued values win over the requested ones. Absent when the+ // certificate does not carry them, leaving the requested values in place.+ ...(parsed.subject?.commonName && { commonName: parsed.subject.commonName }),...(parsed.keyUsages && { keyUsages: parsed.keyUsages }),...(parsed.extendedKeyUsages && { extendedKeyUsages: parsed.extendedKeyUsages })};diff --cc docs/documentation/platform/pki/ca/adcs.mdxindex 7819d83062,2ee5066b11..a425e109af--- a/docs/documentation/platform/pki/ca/adcs.mdx+++ b/docs/documentation/platform/pki/ca/adcs.mdx@@@ -189,26 -189,16 +189,26 @@@ You can use AD CS in a few ways: as anThe CA rejected the request with `CERTSRV_E_UNSUPPORTED_CERT_TYPE`. The template is either not published on the CA or the name is wrong. Confirm the template is published (`certutil -CATemplates`) and that the name matches exactly.</Accordion><Accordion title="Enroll permission denied">- The connection account does not have Enroll permission on the requested template. Grant Enroll to the account on the template's security settings.+ The connection account doesn't have Enroll permission on the requested template. Grant Enroll to the account on the template's security settings.</Accordion><Accordion title="The certificate authority name could not be discovered">- Automatic discovery reads the CA name from the host's registry over SMB (TCP 445), which requires the Remote Registry service to be running and reachable from the Gateway. If SMB is not open to the Gateway, leave discovery aside and set the certificate authority name explicitly on the external CA. Run `certutil -getreg CA\CommonName` on the AD CS server to find it.+ Automatic discovery reads the CA name from the host's registry over SMB (TCP 445), which requires the Remote Registry service to be running and reachable from the Gateway. If SMB isn't open to the Gateway, leave discovery aside and set the certificate authority name explicitly on the external CA. Run `certutil -getreg CA\CommonName` on the AD CS server to find it.</Accordion><Accordion title="Could not reach certificate authority through the gateway">- When you create or update the CA, Infisical validates the certificate authority name against the CA over the Gateway. This error means the name does not match a CA on the host, or the Gateway cannot reach the AD CS server. Confirm the name with `certutil -getreg CA\CommonName` on the AD CS server and that the Gateway can connect to the host over DCOM (MS-WCCE).+ When you create or update the CA, Infisical validates the certificate authority name against the CA over the Gateway. This error means the name doesn't match a CA on the host, or the Gateway can't reach the AD CS server. Confirm the name with `certutil -getreg CA\CommonName` on the AD CS server and that the Gateway can connect to the host over DCOM (MS-WCCE).</Accordion>+ <Accordion title="The certificate was issued without a custom extension">+ AD CS copies a custom extension out of a request only when its OID is listed in the CA's `EnableRequestExtensionList`, which lists none by default. Add the OID and restart the service:++ ```powershell+ certutil -setreg policy\EnableRequestExtensionList +1.3.6.1.4.1.311.25.2+ net stop certsvc && net start certsvc+ ```++ Leaving an OID off that list is also how you stop requests from introducing it.+ </Accordion><Accordion title="Signer rejected: missing Code Signing extended key usage">- The template used for a code signing signer does not produce a code-signing certificate. Point the signer at a template that carries the Code Signing extended key usage.+ The template used for a code signing signer doesn't produce a code-signing certificate. Point the signer at a template that carries the Code Signing extended key usage.</Accordion><Accordion title="Gateway connectivity issues">Verify the Gateway can reach the AD CS host over DCOM (MS-WCCE) and that the domain account credentials are correct.diff --cc frontend/src/pages/cert-manager/PoliciesPage/components/CertificatePoliciesTab/CreatePolicyModal.tsxindex c7f6c3c18d,33159aee95..7f85d27fb8--- a/frontend/src/pages/cert-manager/PoliciesPage/components/CertificatePoliciesTab/CreatePolicyModal.tsx+++ b/frontend/src/pages/cert-manager/PoliciesPage/components/CertificatePoliciesTab/CreatePolicyModal.tsx@@@ -37,15 -36,8 +37,15 @@@ importStepper,StepperList,StepperStep,- Switch,+ Table,+ TableBody,+ TableCell,+ TableHead,+ TableHeader,+ TableHeadLabel,+ TableRow,- TextArea+ TextArea,+ Toggle} from "@app/components/v3";import { useProject, useSubscription } from "@app/context";import {