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
Greptile comments fixes
Carlos Monastyrski1db9524ba917
diff --git a/backend/src/services/alert/providers/cert-manager-application-alert-dal.test.ts b/backend/src/services/alert/providers/cert-manager-application-alert-dal.test.tsindex 90c1721026..8ed3abee1b 100644--- a/backend/src/services/alert/providers/cert-manager-application-alert-dal.test.ts+++ b/backend/src/services/alert/providers/cert-manager-application-alert-dal.test.ts@@ -21,6 +21,7 @@ const buildDAL = (firstQueryRows: unknown[] = []) => {}});}) as unknown as Knex;+ Object.assign(reader, { raw: builder.raw.bind(builder) });const db = Object.assign(reader, { replicaNode: () => reader }) as unknown as TDbClient;return { dal: certManagerApplicationAlertDALFactory(db), queries };@@ -66,12 +67,12 @@ describe("cert manager certificate alert DAL", () => {});expect(queries).toHaveLength(2);- const [neverNotified, leastRecentlyNotified] = queries;- expect(neverNotified.sql).toContain('count(distinct "tgt"."channelId")');- expect(neverNotified.sql).toContain('"tgt"."targetId" = "certificates".id::text');- expect(neverNotified.sql).toContain('not exists (select "notifiedTgt"."id"');- expect(neverNotified.sql).toMatch(/order by "certificates"\."notAfter" asc limit \?$/);- expect(neverNotified.bindings).toEqual(+ const [notFullyNotified, leastRecentlyNotified] = queries;+ expect(notFullyNotified.sql).toContain('count(distinct "tgt"."channelId")');+ expect(notFullyNotified.sql).toContain('"tgt"."targetId" = "certificates".id::text');+ expect(notFullyNotified.sql).toContain('count(distinct "everTgt"."channelId")');+ expect(notFullyNotified.sql).toMatch(/order by "certificates"\."notAfter" asc limit \?$/);+ expect(notFullyNotified.bindings).toEqual(expect.arrayContaining(["alert-1", since, "success", "channel-1", "channel-2", 2, 1000]));expect(leastRecentlyNotified.sql).toContain('max("lastHist"."triggeredAt") as "lastDeliveredAt"');@@ -79,7 +80,7 @@ describe("cert manager certificate alert DAL", () => {expect(leastRecentlyNotified.sql).toContain('order by "lastDelivered"."lastDeliveredAt" asc, "certificates"."notAfter" asc limit ?');- expect(leastRecentlyNotified.sql).not.toContain("not exists");+ expect(leastRecentlyNotified.sql).toContain('having count(distinct "lastTgt"."channelId") >= ?');});test("findExpiringCertificates stops after the never-notified query when it fills the cap", async () => {@@ -109,17 +110,15 @@ describe("cert manager certificate alert DAL", () => {});const [{ sql, bindings }] = queries;- expect(sql).toContain('inner join "certificates" on "pki_signers"."certificateId" = "certificates"."id"');+ expect(sql).toContain('group by "pki_signers"."certificateId"');+ expect(sql).toContain('array_agg("pki_signers".name order by "pki_signers".name) as "signerNames"');+ expect(sql).toContain('as "signers" on "signers"."certificateId" = "certificates"."id"');expect(sql).toContain('"pki_signers"."projectId" = ?');expect(sql).toContain('"pki_signers"."status" = ?');- expect(sql).toContain('"pki_signers"."name" as "signerName"');expect(sql).toContain('not "certificates"."status" = ?');- expect(sql).toContain('count(distinct "tgt"."channelId")');- expect(sql).toContain("not exists");+ expect(sql).toContain('count(distinct "everTgt"."channelId")');expect(bindings).toEqual(expect.arrayContaining([PROJECT_ID, "active", "alert-1"]));- expect(queries[1].sql).toContain(- 'inner join "certificates" on "pki_signers"."certificateId" = "certificates"."id"'- );+ expect(queries[1].sql).toContain('as "signers" on "signers"."certificateId" = "certificates"."id"');expect(queries[1].sql).toContain('"lastDelivered"."lastDeliveredAt" asc');});diff --git a/backend/src/services/alert/providers/cert-manager-application-alert-dal.ts b/backend/src/services/alert/providers/cert-manager-application-alert-dal.tsindex a567eac49f..057d5702be 100644--- a/backend/src/services/alert/providers/cert-manager-application-alert-dal.ts+++ b/backend/src/services/alert/providers/cert-manager-application-alert-dal.ts@@ -23,8 +23,8 @@ export type TApplicationAlertCertificate = {revocationReason: number | null;applicationId: string | null;applicationName: string | null;- signerId?: string | null;- signerName?: string | null;+ signerIds?: string[];+ signerNames?: string[];};type TExpiryWindow = {@@ -112,24 +112,27 @@ const selectExpiring = async (.limit(MAX_EXPIRING_CERTIFICATES_PER_RUN)) as TApplicationAlertCertificate[];}- const neverNotified = (await dueQuery()- .whereNotExists(- reader(`${TableName.AlertHistory} as notifiedHist`)- .join(`${TableName.AlertHistoryTarget} as notifiedTgt`, "notifiedHist.id", "notifiedTgt.alertHistoryId")- .where("notifiedHist.alertId", alreadyAlerted.alertId)- .where("notifiedTgt.status", AlertRunStatus.SUCCESS)- .whereRaw(`"notifiedTgt"."targetId" = "${TableName.Certificate}".id::text`)- .select("notifiedTgt.id")- )+ const channelCount = alreadyAlerted.channelIds.length;+ const everDeliveredChannelCount = reader(`${TableName.AlertHistory} as everHist`)+ .join(`${TableName.AlertHistoryTarget} as everTgt`, "everHist.id", "everTgt.alertHistoryId")+ .where("everHist.alertId", alreadyAlerted.alertId)+ .where("everTgt.status", AlertRunStatus.SUCCESS)+ .whereIn("everTgt.channelId", alreadyAlerted.channelIds)+ .whereRaw(`"everTgt"."targetId" = "${TableName.Certificate}".id::text`)+ .countDistinct("everTgt.channelId");+ const notFullyNotified = (await dueQuery()+ .whereRaw("(?) < ?", [everDeliveredChannelCount, channelCount]).orderBy(`${TableName.Certificate}.notAfter`, "asc").limit(MAX_EXPIRING_CERTIFICATES_PER_RUN)) as TApplicationAlertCertificate[];- if (neverNotified.length >= MAX_EXPIRING_CERTIFICATES_PER_RUN) return neverNotified;+ if (notFullyNotified.length >= MAX_EXPIRING_CERTIFICATES_PER_RUN) return notFullyNotified;const lastDelivered = reader(`${TableName.AlertHistory} as lastHist`).join(`${TableName.AlertHistoryTarget} as lastTgt`, "lastHist.id", "lastTgt.alertHistoryId").where("lastHist.alertId", alreadyAlerted.alertId).where("lastTgt.status", AlertRunStatus.SUCCESS)+ .whereIn("lastTgt.channelId", alreadyAlerted.channelIds).groupBy("lastTgt.targetId")+ .havingRaw(`count(distinct "lastTgt"."channelId") >= ?`, [channelCount]).select("lastTgt.targetId").max("lastHist.triggeredAt as lastDeliveredAt");const leastRecentlyNotified = (await dueQuery()@@ -138,9 +141,9 @@ const selectExpiring = async (]).orderBy("lastDelivered.lastDeliveredAt", "asc").orderBy(`${TableName.Certificate}.notAfter`, "asc")- .limit(MAX_EXPIRING_CERTIFICATES_PER_RUN - neverNotified.length)) as TApplicationAlertCertificate[];+ .limit(MAX_EXPIRING_CERTIFICATES_PER_RUN - notFullyNotified.length)) as TApplicationAlertCertificate[];- return [...neverNotified, ...leastRecentlyNotified];+ return [...notFullyNotified, ...leastRecentlyNotified];};export const certManagerApplicationAlertDALFactory = (db: TDbClient) => {@@ -177,22 +180,28 @@ export const certManagerApplicationAlertDALFactory = (db: TDbClient) => {): Promise<TApplicationAlertCertificate[]> => {try {const reader = tx || db.replicaNode();+ const activeSigners = reader(TableName.PkiSigners)+ .where(`${TableName.PkiSigners}.projectId`, scope.projectId)+ .where(`${TableName.PkiSigners}.status`, SignerStatus.Active)+ .whereNotNull(`${TableName.PkiSigners}.certificateId`)+ .groupBy(`${TableName.PkiSigners}.certificateId`)+ .select(`${TableName.PkiSigners}.certificateId`)+ .select(+ reader.raw(`array_agg("${TableName.PkiSigners}".id order by "${TableName.PkiSigners}".name) as "signerIds"`),+ reader.raw(+ `array_agg("${TableName.PkiSigners}".name order by "${TableName.PkiSigners}".name) as "signerNames"`+ )+ );const buildQuery = () =>- reader(TableName.PkiSigners)- .join(TableName.Certificate, `${TableName.PkiSigners}.certificateId`, `${TableName.Certificate}.id`)+ reader(TableName.Certificate)+ .join(activeSigners.clone().as("signers"), "signers.certificateId", `${TableName.Certificate}.id`).leftJoin(`${TableName.PkiCertificateProfile} as profile`, `${TableName.Certificate}.profileId`, "profile.id").leftJoin(TableName.PkiApplication,`${TableName.Certificate}.applicationId`,`${TableName.PkiApplication}.id`)- .where(`${TableName.PkiSigners}.projectId`, scope.projectId)- .where(`${TableName.PkiSigners}.status`, SignerStatus.Active)- .select([- ...CERTIFICATE_TARGET_COLUMNS,- `${TableName.PkiSigners}.id as signerId`,- `${TableName.PkiSigners}.name as signerName`- ]);+ .select([...CERTIFICATE_TARGET_COLUMNS, "signers.signerIds", "signers.signerNames"]);return await selectExpiring(reader, buildQuery, scope);} catch (error) {throw new DatabaseError({ error, name: "FindExpiringSignerCertificates" });diff --git a/backend/src/services/alert/providers/cert-manager-application-alert-provider.test.ts b/backend/src/services/alert/providers/cert-manager-application-alert-provider.test.tsindex 80ecf9a7cd..35d8e798bf 100644--- a/backend/src/services/alert/providers/cert-manager-application-alert-provider.test.ts+++ b/backend/src/services/alert/providers/cert-manager-application-alert-provider.test.ts@@ -779,8 +779,8 @@ describe("cert manager application alert provider", () => {altNames: null,applicationId: null,applicationName: null,- signerId: "signer-1",- signerName: "release-signer"+ signerIds: ["signer-1"],+ signerNames: ["release-signer"]});const signerAlert = alertContext({resourceId: null,@@ -892,8 +892,24 @@ describe("cert manager application alert provider", () => {expect(payload.summary).toBe("1 signer certificate expiring within 30 days");expect(payload.items[0].summary).toMatch(/^Certificate 'release signing' of signer 'release-signer' expires on /);expect(payload.items[0].fields?.[0]).toEqual({ label: "Signer", value: "release-signer" });- expect(payload.items[0].resource).toMatchObject({ signerId: "signer-1", signerName: "release-signer" });+ expect(payload.items[0].resource).toMatchObject({ signerIds: ["signer-1"], signerNames: ["release-signer"] });expect(provider.dedupWindowHours?.({ alertBefore: "30d" })).toBe(44);});++ test("a certificate shared by several signers is one item naming every signer", async () => {+ const { provider } = buildProvider();+ const sharedCertificate = {+ ...signerCertificate,+ signerIds: ["signer-1", "signer-2"],+ signerNames: ["build-signer", "release-signer"]+ };+ const payload = provider.buildPayload(signerAlert, [sharedCertificate], await provider.buildViewUrl(signerAlert));++ expect(payload.items).toHaveLength(1);+ expect(payload.items[0].summary).toMatch(+ /^Certificate 'release signing' of signers 'build-signer', 'release-signer' expires on /+ );+ expect(payload.items[0].fields?.[0]).toEqual({ label: "Signers", value: "build-signer, release-signer" });+ });});});diff --git a/backend/src/services/alert/providers/cert-manager-application-alert-provider.ts b/backend/src/services/alert/providers/cert-manager-application-alert-provider.tsindex 862ee992c2..e6e50828e1 100644--- a/backend/src/services/alert/providers/cert-manager-application-alert-provider.ts+++ b/backend/src/services/alert/providers/cert-manager-application-alert-provider.ts@@ -183,9 +183,12 @@ const buildSummary = (return `${targets.length} certificates ${EVENT_VERBS[eventType]}${inApplication(applicationName)}`;};+const formatSigners = (signerNames: string[] = []) =>+ `${signerNames.length === 1 ? "signer" : "signers"} ${signerNames.map((name) => `'${name}'`).join(", ")}`;+const buildItemSummary = (eventType: TCertManagerAlertEvent, certificate: TApplicationAlertCertificate): string => {if (eventType === CodeSigningAlertEvent.SignerCertificateExpiry) {- return `Certificate '${certificateDisplayName(certificate)}' of signer '${certificate.signerName}' expires on ${formatUtcDate(certificate.notAfter)}`;+ return `Certificate '${certificateDisplayName(certificate)}' of ${formatSigners(certificate.signerNames)} expires on ${formatUtcDate(certificate.notAfter)}`;}if (eventType === CertificateAlertEvent.Expiry) {return `Certificate '${certificateDisplayName(certificate)}'${inApplication(certificate.applicationName)} expires on ${formatUtcDate(certificate.notAfter)}`;@@ -330,7 +333,14 @@ export const certManagerApplicationAlertProviderFactory = ({summary: buildItemSummary(eventType, certificate),severity: eventSeverity(eventType, [certificate]),fields: [- ...(isSignerAlert && certificate.signerName ? [{ label: "Signer", value: certificate.signerName }] : []),+ ...(isSignerAlert && certificate.signerNames?.length+ ? [+ {+ label: certificate.signerNames.length === 1 ? "Signer" : "Signers",+ value: certificate.signerNames.join(", ")+ }+ ]+ : []),{ label: "Serial Number", value: certificate.serialNumber },...(altNames.length ? [{ label: "SANs", value: altNames.join(", ") }] : []),...(certificate.profileName ? [{ label: "Profile", value: certificate.profileName }] : []),@@ -354,7 +364,7 @@ export const certManagerApplicationAlertProviderFactory = ({profileName: certificate.profileName,applicationId: certificate.applicationId,applicationName: certificate.applicationName,- ...(isSignerAlert ? { signerId: certificate.signerId, signerName: certificate.signerName } : {})+ ...(isSignerAlert ? { signerIds: certificate.signerIds, signerNames: certificate.signerNames } : {})}};})diff --git a/docs/documentation/platform/pki/settings/alerts.mdx b/docs/documentation/platform/pki/settings/alerts.mdxindex e6fa661e63..aca4cd7178 100644--- a/docs/documentation/platform/pki/settings/alerts.mdx+++ b/docs/documentation/platform/pki/settings/alerts.mdx@@ -80,7 +80,7 @@ Only each signer's current certificate counts. When you reissue a signer's certi| `data.items[].fields` | Includes an entry labelled `Application` when the certificate belongs to an application || `data.items[].resource.applicationId` | `null` for a certificate outside an application |- A **Signer Certificate Expiration** alert sends `cert-manager.signer-certificate.expiry` as its `subject` (`type` is `com.infisical.cert-manager.signer-certificate.expiry`), opens **Code Signing** from `data.metadata.viewUrl`, and adds a `Signer` field plus `signerId` and `signerName` to each item.+ A **Signer Certificate Expiration** alert sends `cert-manager.signer-certificate.expiry` as its `subject` (`type` is `com.infisical.cert-manager.signer-certificate.expiry`), opens **Code Signing** from `data.metadata.viewUrl`, and adds a `Signer` field (`Signers` when several signers share the certificate) plus `signerIds` and `signerNames` to each item.</Accordion></AccordionGroup>diff --git a/frontend/src/pages/cert-manager/ApplicationDetailsByIDPage/components/ApplicationAlerts/FiltersStep.tsx b/frontend/src/pages/cert-manager/ApplicationDetailsByIDPage/components/ApplicationAlerts/FiltersStep.tsxindex 856dbb8eb9..f0e189575f 100644--- a/frontend/src/pages/cert-manager/ApplicationDetailsByIDPage/components/ApplicationAlerts/FiltersStep.tsx+++ b/frontend/src/pages/cert-manager/ApplicationDetailsByIDPage/components/ApplicationAlerts/FiltersStep.tsx@@ -104,7 +104,13 @@ export const FiltersStep = ({ form, projectId }: Props) => {title: "Certificates couldn't be loaded",description: "Select Retry to try again."};+ } else if (hasUnfinishedFilter) {+ previewEmptyState = {+ title: "Finish the filter",+ description: "Select at least one value in each filter, or remove it."+ };}+ const showPreviewRows = !isPreviewError && !hasUnfinishedFilter;return (<div className="flex flex-col">@@ -223,12 +229,12 @@ export const FiltersStep = ({ form, projectId }: Props) => {<div className="mt-3"><PkiSyncMatchedCertificatesTable- rows={preview?.certificates ?? []}- isLoading={!preview && !isPreviewError}+ rows={showPreviewRows ? (preview?.certificates ?? []) : []}+ isLoading={showPreviewRows && !preview}emptyTitle={previewEmptyState.title}emptyDescription={previewEmptyState.description}/>- {matchedCount > MATCHED_PAGE_SIZE && (+ {showPreviewRows && matchedCount > MATCHED_PAGE_SIZE && (<PaginationclassName="mt-2"count={matchedCount}