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
fix(pki): fix dashboard filters and auto-renew display for app-level certificates (#6572)
Saif Ur Rahman8fdf822a3953
diff --git a/backend/src/server/routes/index.ts b/backend/src/server/routes/index.tsindex 334f164193..80bbfdf20a 100644--- a/backend/src/server/routes/index.ts+++ b/backend/src/server/routes/index.ts@@ -2773,6 +2773,8 @@ export const registerRoutes = async (certificateRequestDAL,resourceMetadataDAL,pkiAlertV2Queue,+ pkiApplicationProfileDAL,+ apiEnrollmentConfigDAL,gatewayV2Service,gatewayPoolService});@@ -2791,7 +2793,9 @@ export const registerRoutes = async (projectDAL,certificatePolicyService,certificateIssuanceQueue,- resourceMetadataDAL+ resourceMetadataDAL,+ pkiApplicationProfileDAL,+ apiEnrollmentConfigDAL});const approvalPolicyStepsDAL = approvalPolicyStepsDALFactory(db);@@ -2847,6 +2851,7 @@ export const registerRoutes = async (resourceMetadataDAL,pkiAlertV2Queue,pkiApplicationProfileDAL,+ apiEnrollmentConfigDAL,licenseService});diff --git a/backend/src/services/certificate-authority/certificate-issuance-queue.ts b/backend/src/services/certificate-authority/certificate-issuance-queue.tsindex eba0803ba4..2f529b9afd 100644--- a/backend/src/services/certificate-authority/certificate-issuance-queue.ts+++ b/backend/src/services/certificate-authority/certificate-issuance-queue.ts@@ -23,12 +23,18 @@ import { TAppConnectionServiceFactory } from "../app-connection/app-connection-simport { TCertificateBodyDALFactory } from "../certificate/certificate-body-dal";import { TCertificateSecretDALFactory } from "../certificate/certificate-secret-dal";import { CertKeyAlgorithm } from "../certificate-common/certificate-constants";+import {+ calculateFinalRenewBeforeDays,+ resolveEffectiveApiConfig+} from "../certificate-common/certificate-issuance-utils";import { DigiCertExternalMetadataSchema } from "../certificate-common/external-metadata-schemas";import { TCertificateRequestDALFactory } from "../certificate-request/certificate-request-dal";import { TCertificateRequestServiceFactory } from "../certificate-request/certificate-request-service";import { CertificateRequestStatus } from "../certificate-request/certificate-request-types";+import { TApiEnrollmentConfigDALFactory } from "../enrollment-config/api-enrollment-config-dal";import { TPkiAlertV2QueueServiceFactory } from "../pki-alert-v2/pki-alert-v2-queue";import { PkiAlertEventType } from "../pki-alert-v2/pki-alert-v2-types";+import { TPkiApplicationProfileDALFactory } from "../pki-application/pki-application-profile-dal";import { TPkiSubscriberDALFactory } from "../pki-subscriber/pki-subscriber-dal";import { TPkiSyncDALFactory } from "../pki-sync/pki-sync-dal";import { TPkiSyncQueueFactory } from "../pki-sync/pki-sync-queue";@@ -131,6 +137,8 @@ type TCertificateIssuanceQueueFactoryDep = {certificateRequestDAL?: Pick<TCertificateRequestDALFactory, "updateById" | "findById">;resourceMetadataDAL: Pick<TResourceMetadataDALFactory, "find" | "insertMany">;pkiAlertV2Queue?: Pick<TPkiAlertV2QueueServiceFactory, "queueCertificateEvent">;+ pkiApplicationProfileDAL?: Pick<TPkiApplicationProfileDALFactory, "findOneByApplicationAndProfile">;+ apiEnrollmentConfigDAL?: Pick<TApiEnrollmentConfigDALFactory, "findById">;gatewayV2Service: Pick<TGatewayV2ServiceFactory, "getPlatformConnectionDetailsByGatewayId">;gatewayPoolService: Pick<TGatewayPoolServiceFactory, "resolveEffectiveGatewayId">;};@@ -156,6 +164,8 @@ export const certificateIssuanceQueueFactory = ({certificateRequestDAL,resourceMetadataDAL,pkiAlertV2Queue,+ pkiApplicationProfileDAL,+ apiEnrollmentConfigDAL,gatewayV2Service,gatewayPoolService}: TCertificateIssuanceQueueFactoryDep) => {@@ -796,6 +806,40 @@ export const certificateIssuanceQueueFactory = ({);}+ try {+ if (scopedApplicationId && profileId && certificateProfileDAL && certificateRequestDAL) {+ const req = await certificateRequestDAL.findById(certificateRequestId!);+ if (req?.certificateId) {+ const profile = await certificateProfileDAL.findByIdWithConfigs(profileId);+ if (profile) {+ const effectiveApiConfig = await resolveEffectiveApiConfig({+ applicationId: scopedApplicationId,+ profileId,+ profileApiConfig: profile.apiConfig,+ pkiApplicationProfileDAL,+ apiEnrollmentConfigDAL+ });+ const cert = await certificateDAL.findById(req.certificateId);+ if (cert && !cert.renewBeforeDays) {+ const finalRenewBeforeDays = calculateFinalRenewBeforeDays(+ { apiConfig: effectiveApiConfig },+ ttl,+ new Date(cert.notAfter)+ );+ if (finalRenewBeforeDays !== undefined) {+ await certificateDAL.updateById(req.certificateId, { renewBeforeDays: finalRenewBeforeDays });+ }+ }+ }+ }+ }+ } catch (renewErr) {+ logger.warn(+ renewErr,+ `Failed to set renewBeforeDays on async-issued certificate [certificateRequestId=${certificateRequestId}]`+ );+ }+try {await pkiAlertV2Queue?.queueCertificateEvent({certificateId,diff --git a/backend/src/services/certificate-common/certificate-issuance-utils.ts b/backend/src/services/certificate-common/certificate-issuance-utils.tsindex d2d2995504..57a190467f 100644--- a/backend/src/services/certificate-common/certificate-issuance-utils.ts+++ b/backend/src/services/certificate-common/certificate-issuance-utils.ts@@ -100,6 +100,46 @@ export const calculateFinalRenewBeforeDays = (return isValidRenewalTiming(renewBeforeDays, certificateExpiryDate) ? renewBeforeDays : undefined;};+/**+ * Resolves the effective API enrollment config for auto-renew.+ * When an applicationId is present, the application-profile junction's config takes+ * precedence over the profile-level config.+ */+export const resolveEffectiveApiConfig = async ({+ applicationId,+ profileId,+ profileApiConfig,+ pkiApplicationProfileDAL,+ apiEnrollmentConfigDAL+}: {+ applicationId?: string;+ profileId: string;+ profileApiConfig?: { autoRenew?: boolean; renewBeforeDays?: number };+ pkiApplicationProfileDAL?: {+ findOneByApplicationAndProfile: (+ appId: string,+ profId: string+ ) => Promise<{ apiConfigId?: string | null } | undefined>;+ };+ apiEnrollmentConfigDAL?: {+ findById: (id: string) => Promise<{ autoRenew?: boolean | null; renewBeforeDays?: number | null } | undefined>;+ };+}): Promise<{ autoRenew?: boolean; renewBeforeDays?: number } | undefined> => {+ if (applicationId && pkiApplicationProfileDAL && apiEnrollmentConfigDAL) {+ const junction = await pkiApplicationProfileDAL.findOneByApplicationAndProfile(applicationId, profileId);+ if (junction?.apiConfigId) {+ const appApiConfig = await apiEnrollmentConfigDAL.findById(junction.apiConfigId);+ if (appApiConfig) {+ return {+ autoRenew: Boolean(appApiConfig.autoRenew),+ renewBeforeDays: appApiConfig.renewBeforeDays ?? undefined+ };+ }+ }+ }+ return profileApiConfig;+};+/*** Validates that the CA supports the requested operation (only internal CAs support direct operations)*/diff --git a/backend/src/services/certificate-v3/certificate-approval-fns.ts b/backend/src/services/certificate-v3/certificate-approval-fns.tsindex 7c69818dc1..efde8aa0a8 100644--- a/backend/src/services/certificate-v3/certificate-approval-fns.ts+++ b/backend/src/services/certificate-v3/certificate-approval-fns.ts@@ -23,7 +23,9 @@ import { TInternalCertificateAuthorityServiceFactory } from "@app/services/certiimport { 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";+import { TApiEnrollmentConfigDALFactory } from "@app/services/enrollment-config/api-enrollment-config-dal";import { TKmsServiceFactory } from "@app/services/kms/kms-service";+import { TPkiApplicationProfileDALFactory } from "@app/services/pki-application/pki-application-profile-dal";import { TProjectDALFactory } from "@app/services/project/project-dal";import { getProjectKmsCertificateKeyId } from "@app/services/project/project-fns";import { TResourceMetadataDALFactory } from "@app/services/resource-metadata/resource-metadata-dal";@@ -35,6 +37,7 @@ import {extractCertificateFromBuffer,generateSelfSignedCertificate,getEffectiveAlgorithms,+ resolveEffectiveApiConfig,validateAlgorithmCompatibility,validateCaSupport} from "../certificate-common/certificate-issuance-utils";@@ -66,6 +69,8 @@ export type TIssueCertificateFromApprovedRequestDeps = {certificatePolicyService: Pick<TCertificatePolicyServiceFactory, "validateCertificateRequest" | "getPolicyById">;certificateIssuanceQueue: Pick<TCertificateIssuanceQueueFactory, "queueCertificateIssuance">;resourceMetadataDAL: Pick<TResourceMetadataDALFactory, "find" | "insertMany">;+ pkiApplicationProfileDAL: Pick<TPkiApplicationProfileDALFactory, "findOneByApplicationAndProfile">;+ apiEnrollmentConfigDAL: Pick<TApiEnrollmentConfigDALFactory, "findById">;};export type TCertificateApprovalService = {@@ -89,7 +94,9 @@ export const certificateApprovalServiceFactory = (projectDAL,certificatePolicyService,certificateIssuanceQueue,- resourceMetadataDAL+ resourceMetadataDAL,+ pkiApplicationProfileDAL,+ apiEnrollmentConfigDAL} = deps;const $validateProfileAndPermissions = async ({@@ -380,7 +387,18 @@ export const certificateApprovalServiceFactory = (throw new NotFoundError({ message: "Certificate was signed but could not be found in database" });}- const finalRenewBeforeDays = calculateFinalRenewBeforeDays(profile, ttl, new Date(signedCertRecord.notAfter));+ const effectiveApiConfig = await resolveEffectiveApiConfig({+ applicationId: certRequest.applicationId ?? undefined,+ profileId,+ profileApiConfig: profile.apiConfig,+ pkiApplicationProfileDAL,+ apiEnrollmentConfigDAL+ });+ const finalRenewBeforeDays = calculateFinalRenewBeforeDays(+ { apiConfig: effectiveApiConfig },+ ttl,+ new Date(signedCertRecord.notAfter)+ );const updateData: { profileId: string; renewBeforeDays?: number; applicationId?: string } = { profileId };if (finalRenewBeforeDays !== undefined) {@@ -566,8 +584,15 @@ export const certificateApprovalServiceFactory = (tx});+ const effectiveApiConfig = await resolveEffectiveApiConfig({+ applicationId: applicationId ?? undefined,+ profileId: profile.id,+ profileApiConfig: profile.apiConfig,+ pkiApplicationProfileDAL,+ apiEnrollmentConfigDAL+ });const finalRenewBeforeDays = calculateFinalRenewBeforeDays(- profile,+ { apiConfig: effectiveApiConfig },certificateRequestInput.validity.ttl,processResult.selfSignedResult.notAfter);@@ -694,8 +719,15 @@ export const certificateApprovalServiceFactory = (throw new NotFoundError({ message: "Certificate was issued but could not be found in database" });}+ const effectiveApiConfig = await resolveEffectiveApiConfig({+ applicationId: applicationId ?? undefined,+ profileId: profile.id,+ profileApiConfig: profile.apiConfig,+ pkiApplicationProfileDAL,+ apiEnrollmentConfigDAL+ });const finalRenewBeforeDays = calculateFinalRenewBeforeDays(- profile,+ { apiConfig: effectiveApiConfig },certificateRequestInput.validity.ttl,new Date(certificateRecord.notAfter));diff --git a/backend/src/services/certificate-v3/certificate-v3-service.test.ts b/backend/src/services/certificate-v3/certificate-v3-service.test.tsindex 86f3a1a486..7d4aebf715 100644--- a/backend/src/services/certificate-v3/certificate-v3-service.test.ts+++ b/backend/src/services/certificate-v3/certificate-v3-service.test.ts@@ -275,8 +275,12 @@ describe("CertificateV3Service", () => {find: vi.fn().mockResolvedValue([])},pkiApplicationProfileDAL: {- findAllByProfileId: vi.fn().mockResolvedValue([])+ findAllByProfileId: vi.fn().mockResolvedValue([]),+ findOneByApplicationAndProfile: vi.fn().mockResolvedValue(undefined)} as never,+ apiEnrollmentConfigDAL: {+ findById: vi.fn().mockResolvedValue(undefined)+ },licenseService: {getPlan: vi.fn().mockResolvedValue({ pkiPqc: true })}diff --git a/backend/src/services/certificate-v3/certificate-v3-service.ts b/backend/src/services/certificate-v3/certificate-v3-service.tsindex 876d83b259..db6fcbea08 100644--- a/backend/src/services/certificate-v3/certificate-v3-service.ts+++ b/backend/src/services/certificate-v3/certificate-v3-service.ts@@ -56,6 +56,7 @@ import { TInternalCertificateAuthorityServiceFactory } from "@app/services/certiimport { 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";+import { TApiEnrollmentConfigDALFactory } from "@app/services/enrollment-config/api-enrollment-config-dal";import { TIdentityDALFactory } from "@app/services/identity/identity-dal";import { TKmsServiceFactory } from "@app/services/kms/kms-service";import { TPkiAlertV2QueueServiceFactory } from "@app/services/pki-alert-v2/pki-alert-v2-queue";@@ -84,6 +85,7 @@ import {generateSelfSignedCertificate,getEffectiveAlgorithms,isValidRenewalTiming,+ resolveEffectiveApiConfig,validateAlgorithmCompatibility,validateCaSupport} from "../certificate-common/certificate-issuance-utils";@@ -166,7 +168,11 @@ type TCertificateV3ServiceFactoryDep = {approvalPolicyService: Pick<TApprovalPolicyServiceFactory, "createRequestFromPolicy">;resourceMetadataDAL: Pick<TResourceMetadataDALFactory, "insertMany" | "delete" | "find">;pkiAlertV2Queue?: Pick<TPkiAlertV2QueueServiceFactory, "queueCertificateEvent">;- pkiApplicationProfileDAL: Pick<TPkiApplicationProfileDALFactory, "findAllByProfileId">;+ pkiApplicationProfileDAL: Pick<+ TPkiApplicationProfileDALFactory,+ "findAllByProfileId" | "findOneByApplicationAndProfile"+ >;+ apiEnrollmentConfigDAL: Pick<TApiEnrollmentConfigDALFactory, "findById">;licenseService: Pick<TLicenseServiceFactory, "getPlan">;};@@ -687,6 +693,7 @@ export const certificateV3ServiceFactory = ({resourceMetadataDAL,pkiAlertV2Queue,pkiApplicationProfileDAL,+ apiEnrollmentConfigDAL,licenseService}: TCertificateV3ServiceFactoryDep) => {const $resolveApplicationIdForProfile = async (@@ -1164,8 +1171,15 @@ export const certificateV3ServiceFactory = ({});}+ const effectiveApiConfig = await resolveEffectiveApiConfig({+ applicationId,+ profileId: profile.id,+ profileApiConfig: profile.apiConfig,+ pkiApplicationProfileDAL,+ apiEnrollmentConfigDAL+ });const finalRenewBeforeDays = calculateFinalRenewBeforeDays(- profile,+ { apiConfig: effectiveApiConfig },resolvedTtl,processResult.selfSignedResult.notAfter);@@ -1335,8 +1349,15 @@ export const certificateV3ServiceFactory = ({flowDefaultTtl: ""});+ const effectiveApiConfig = await resolveEffectiveApiConfig({+ applicationId,+ profileId: profile.id,+ profileApiConfig: profile.apiConfig,+ pkiApplicationProfileDAL,+ apiEnrollmentConfigDAL+ });const finalRenewBeforeDays = calculateFinalRenewBeforeDays(- profile,+ { apiConfig: effectiveApiConfig },effectiveTtl,new Date(certificateRecord.notAfter));@@ -1768,8 +1789,15 @@ export const certificateV3ServiceFactory = ({throw new NotFoundError({ message: "Certificate was signed but could not be found in database" });}+ const effectiveApiConfig = await resolveEffectiveApiConfig({+ applicationId,+ profileId: profile.id,+ profileApiConfig: profile.apiConfig,+ pkiApplicationProfileDAL,+ apiEnrollmentConfigDAL+ });const finalRenewBeforeDays = calculateFinalRenewBeforeDays(- profile,+ { apiConfig: effectiveApiConfig },effectiveTtl,new Date(signedCertRecord.notAfter));@@ -2448,7 +2476,18 @@ export const certificateV3ServiceFactory = ({const notBefore = new Date();const notAfter = new Date(Date.now() + parseTtlToMs(ttl));- const finalRenewBeforeDays = profile ? calculateFinalRenewBeforeDays(profile, ttl, notAfter) : undefined;+ const effectiveApiConfig = profile+ ? await resolveEffectiveApiConfig({+ applicationId: originalCert.applicationId ?? undefined,+ profileId: profile.id,+ profileApiConfig: profile.apiConfig,+ pkiApplicationProfileDAL,+ apiEnrollmentConfigDAL+ })+ : undefined;+ const finalRenewBeforeDays = profile+ ? calculateFinalRenewBeforeDays({ apiConfig: effectiveApiConfig }, ttl, notAfter)+ : undefined;let certificate: string;let certificateChain: string;diff --git a/backend/src/services/certificate/certificate-dal.ts b/backend/src/services/certificate/certificate-dal.tsindex 24679343c9..64088878b1 100644--- a/backend/src/services/certificate/certificate-dal.ts+++ b/backend/src/services/certificate/certificate-dal.ts@@ -807,7 +807,28 @@ export const certificateDALFactory = (db: TDbClient) => {`${TableName.PkiCertificateProfile}.id`).where(`${TableName.CertificateAuthority}.projectId`, projectId)- .select(db.raw(`COALESCE("${TableName.PkiCertificateProfile}"."enrollmentType", 'API') as label`))+ .select(+ db.raw(+ `COALESCE(+ (SELECT ??.?? FROM ?? WHERE ??.?? = ??.?? ORDER BY ??.?? ASC LIMIT 1),+ ??.??,+ 'api'+ ) as label`,+ [+ TableName.CertificateRequests,+ "enrollmentType",+ TableName.CertificateRequests,+ TableName.CertificateRequests,+ "certificateId",+ TableName.Certificate,+ "id",+ TableName.CertificateRequests,+ "createdAt",+ TableName.PkiCertificateProfile,+ "enrollmentType"+ ]+ )+ ).count("* as count").groupBy("label");diff --git a/frontend/src/pages/cert-manager/DashboardPage/components/DistributionCharts.tsx b/frontend/src/pages/cert-manager/DashboardPage/components/DistributionCharts.tsxindex 8c22dfa1d6..ad53adebc0 100644--- a/frontend/src/pages/cert-manager/DashboardPage/components/DistributionCharts.tsx+++ b/frontend/src/pages/cert-manager/DashboardPage/components/DistributionCharts.tsx@@ -197,7 +197,7 @@ export const DistributionCharts = ({ stats, onNavigate }: Props) => {onSegmentClick={(entry) => {if (chart.chartKey === "enrollmentMethod") {onNavigate({ filterEnrollmentType: entry.label });- } else if (chart.chartKey === "algorithm") {+ } else if (chart.chartKey === "algorithm" && entry.label !== "Unknown") {onNavigate({ filterKeyAlgorithm: entry.label });} else if (chart.chartKey === "ca" && entry.id) {onNavigate({ filterCaId: entry.id });