Skip to content

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

feat: add support for signer-specific alerts

Sheen Capadngan2edd72888c99
diff --git a/backend/src/lib/api-docs/constants.ts b/backend/src/lib/api-docs/constants.ts
index b6f691916a..9dfbccde03 100644
--- a/backend/src/lib/api-docs/constants.ts
+++ b/backend/src/lib/api-docs/constants.ts
@@ -2467,7 +2467,7 @@ export const ALERTING = {
GET: {
alertId: "The ID of the alert to get.",
filters:
- "The resources named in the alert's condition, such as applications and certificate profiles, each as `{ id, name }`. `name` is null for a deleted resource."
+ "The resources named in the alert's condition, such as applications, certificate profiles, and signers, each as `{ id, name }`. `name` is null for a deleted resource."
},
UPDATE: {
alertId: "The ID of the alert to update.",
diff --git a/backend/src/services/alert/providers/cert-manager-alert-fns.ts b/backend/src/services/alert/providers/cert-manager-alert-fns.ts
index 206b5061ee..fc32c7abbd 100644
--- a/backend/src/services/alert/providers/cert-manager-alert-fns.ts
+++ b/backend/src/services/alert/providers/cert-manager-alert-fns.ts
@@ -40,6 +40,34 @@ export const ExpiryFieldsSchema = z.object({
dailyReminder: z.boolean().optional()
});
+const MAX_CERTIFICATE_ALERT_FILTER_IDS = 100;
+
+export const filterIdsSchema = (field: string, noun: string) =>
+ z
+ .array(z.string().uuid())
+ .min(1, `${field} must list at least one ${noun}. Omit it to cover every ${noun}.`)
+ .max(MAX_CERTIFICATE_ALERT_FILTER_IDS)
+ .superRefine((ids, ctx) => {
+ const seen = new Set<string>();
+ const duplicates = new Set<string>();
+ ids.forEach((id) => {
+ const key = id.toLowerCase();
+ if (seen.has(key)) duplicates.add(id);
+ seen.add(key);
+ });
+ if (duplicates.size) {
+ ctx.addIssue({
+ code: z.ZodIssueCode.custom,
+ message: `${field} lists the same ID more than once: ${[...duplicates].map((id) => `'${id}'`).join(", ")}`
+ });
+ }
+ })
+ .optional();
+
+export const formatIds = (ids: string[]) => ids.map((id) => `'${id}'`).join(", ");
+
+export const toIdSet = (ids: string[] = []) => new Set(ids.map((id) => id.toLowerCase()));
+
const DAILY_SCAN_DEDUP_MARGIN_HOURS = 4;
const dayMultipleDedupWindowHours = (days: number): number => days * 24 - DAILY_SCAN_DEDUP_MARGIN_HOURS;
diff --git a/backend/src/services/alert/providers/cert-manager-alert-provider.ts b/backend/src/services/alert/providers/cert-manager-alert-provider.ts
index 8db8009f93..132ac0a869 100644
--- a/backend/src/services/alert/providers/cert-manager-alert-provider.ts
+++ b/backend/src/services/alert/providers/cert-manager-alert-provider.ts
@@ -37,13 +37,14 @@ import {
CertificateAlertKind,
expiryDedupWindowHours,
ExpiryFieldsSchema,
+ filterIdsSchema,
+ formatIds,
getScopeWideAlertWebhookSource,
- resolveCertManagerProjectId
+ resolveCertManagerProjectId,
+ toIdSet
} from "./cert-manager-alert-fns";
import { TAlertCertificate, TCertManagerCertificateAlertDALFactory } from "./cert-manager-certificate-alert-dal";
-const MAX_CERTIFICATE_ALERT_FILTER_IDS = 100;
-
const ALERT_KIND_BY_EVENT: Record<CertificateManagerAlertEvent, CertificateAlertKind> = {
[CertificateManagerAlertEvent.Expiry]: CertificateAlertKind.Expiry,
[CertificateManagerAlertEvent.Issuance]: CertificateAlertKind.Issuance,
@@ -57,28 +58,6 @@ const EVENTS_SOURCED_FROM_APPLICATION_EVENTS: [CertificateManagerAlertEvent, Cer
[CertificateManagerAlertEvent.Revocation, CertificateApplicationAlertEvent.Revocation]
];
-const filterIdsSchema = (field: string, noun: string) =>
- z
- .array(z.string().uuid())
- .min(1, `${field} must list at least one ${noun}. Omit it to cover every ${noun}.`)
- .max(MAX_CERTIFICATE_ALERT_FILTER_IDS)
- .superRefine((ids, ctx) => {
- const seen = new Set<string>();
- const duplicates = new Set<string>();
- ids.forEach((id) => {
- const key = id.toLowerCase();
- if (seen.has(key)) duplicates.add(id);
- seen.add(key);
- });
- if (duplicates.size) {
- ctx.addIssue({
- code: z.ZodIssueCode.custom,
- message: `${field} lists the same ID more than once: ${[...duplicates].map((id) => `'${id}'`).join(", ")}`
- });
- }
- })
- .optional();
-
const CertificateFilterSchema = z.object({
applicationIds: filterIdsSchema("applicationIds", "application"),
profileIds: filterIdsSchema("profileIds", "profile"),
@@ -93,10 +72,6 @@ const ExpirationConditionSchema = ExpiryFieldsSchema.merge(CertificateFilterSche
const EventConditionSchema = CertificateFilterSchema.strict().nullish();
-const formatIds = (ids: string[]) => ids.map((id) => `'${id}'`).join(", ");
-
-const toIdSet = (ids: string[] = []) => new Set(ids.map((id) => id.toLowerCase()));
-
const parseFilters = (condition: unknown) => {
const filters = CertificateFilterSchema.safeParse(condition ?? {});
return filters.success ? filters.data : {};
diff --git a/backend/src/services/alert/providers/cert-manager-signer-alert-dal.test.ts b/backend/src/services/alert/providers/cert-manager-signer-alert-dal.test.ts
index 425ba6c319..dd7bab50cf 100644
--- a/backend/src/services/alert/providers/cert-manager-signer-alert-dal.test.ts
+++ b/backend/src/services/alert/providers/cert-manager-signer-alert-dal.test.ts
@@ -54,6 +54,17 @@ describe("cert manager signer alert DAL", () => {
expect(bindings).toEqual(expect.arrayContaining([PROJECT_ID, "active", "alert-1"]));
});
+ test("limits the scan, and the signers named for each certificate, to the filtered signers", async () => {
+ const signerId = "9a7c5e3b-1d2f-4a6b-8c0e-7f9d1b3a5c2e";
+ const { dal, queries } = buildDAL();
+
+ await dal.findExpiringSignerCertificates({ ...scope, signerIds: [signerId] });
+
+ const [{ sql, bindings }] = queries;
+ expect(sql).toContain('"pki_signers"."id" in (?) group by "pki_signers"."certificateId"');
+ expect(bindings).toContain(signerId);
+ });
+
test("fills the rest of the run with certificates delivered on every channel, least recently first", async () => {
const { dal, queries } = buildDAL();
diff --git a/backend/src/services/alert/providers/cert-manager-signer-alert-dal.ts b/backend/src/services/alert/providers/cert-manager-signer-alert-dal.ts
index 9fe2ed3c44..2132302006 100644
--- a/backend/src/services/alert/providers/cert-manager-signer-alert-dal.ts
+++ b/backend/src/services/alert/providers/cert-manager-signer-alert-dal.ts
@@ -22,13 +22,16 @@ export type TSignerAlertCertificate = {
};
export const certManagerSignerAlertDALFactory = (db: TDbClient) => {
- const $selectSignerCertificates = (reader: Knex, projectId: string) =>
+ const $selectSignerCertificates = (reader: Knex, projectId: string, signerIds?: string[]) =>
reader(TableName.Certificate)
.join(
reader(TableName.PkiSigners)
.where(`${TableName.PkiSigners}.projectId`, projectId)
.where(`${TableName.PkiSigners}.status`, SignerStatus.Active)
.whereNotNull(`${TableName.PkiSigners}.certificateId`)
+ .modify((query) => {
+ if (signerIds?.length) void query.whereIn(`${TableName.PkiSigners}.id`, signerIds);
+ })
.groupBy(`${TableName.PkiSigners}.certificateId`)
.select(`${TableName.PkiSigners}.certificateId`)
.select(
@@ -56,14 +59,14 @@ export const certManagerSignerAlertDALFactory = (db: TDbClient) => {
);
const findExpiringSignerCertificates = async (
- scope: { projectId: string } & TExpiringCertificatesScan,
+ scope: { projectId: string; signerIds?: string[] } & TExpiringCertificatesScan,
tx?: Knex
): Promise<TSignerAlertCertificate[]> => {
try {
const reader = tx || db.replicaNode();
return await scanExpiringCertificates<TSignerAlertCertificate>(
reader,
- () => $selectSignerCertificates(reader, scope.projectId),
+ () => $selectSignerCertificates(reader, scope.projectId, scope.signerIds),
scope
);
} catch (error) {
@@ -71,5 +74,29 @@ export const certManagerSignerAlertDALFactory = (db: TDbClient) => {
}
};
- return { findExpiringSignerCertificates };
+ const findProjectSignerIds = async (projectId: string, signerIds: string[], tx?: Knex) => {
+ try {
+ return (await (tx || db)(TableName.PkiSigners)
+ .where({ projectId })
+ .whereIn("id", signerIds)
+ .pluck("id")) as string[];
+ } catch (error) {
+ throw new DatabaseError({ error, name: "FindProjectSignerIds" });
+ }
+ };
+
+ const findSignerNamesByIds = async (projectId: string, signerIds: string[]) => {
+ if (signerIds.length === 0) return [];
+ try {
+ return (await db
+ .replicaNode()(TableName.PkiSigners)
+ .where({ projectId })
+ .whereIn("id", signerIds)
+ .select("id", "name")) as { id: string; name: string }[];
+ } catch (error) {
+ throw new DatabaseError({ error, name: "FindSignerNamesByIds" });
+ }
+ };
+
+ return { findExpiringSignerCertificates, findProjectSignerIds, findSignerNamesByIds };
};
diff --git a/backend/src/services/alert/providers/cert-manager-signer-alert-provider.test.ts b/backend/src/services/alert/providers/cert-manager-signer-alert-provider.test.ts
index 1623a61c5a..c8e74b4484 100644
--- a/backend/src/services/alert/providers/cert-manager-signer-alert-provider.test.ts
+++ b/backend/src/services/alert/providers/cert-manager-signer-alert-provider.test.ts
@@ -18,6 +18,8 @@ vi.mock("@app/lib/config/env", () => ({
const RESOURCE_TYPE = "cert-manager.signer";
const EXPIRY_EVENT = "cert-manager.signer.certificate.expiry";
const APPLICATION_ID = "7b0a6b54-3c1e-4f3a-9d5e-2f1b8c4d6e90";
+const SIGNER_ID = "2c9e4f1a-6b3d-4e8a-9f0c-1d5b7a3e6c24";
+const OTHER_SIGNER_ID = "8f1d3b6e-4a2c-4d9f-b7e0-3c5a9e1f2d68";
const NOT_AFTER = new Date(Date.now() + 10 * 24 * 60 * 60 * 1000);
@@ -58,6 +60,7 @@ const alertRules = [
const buildProvider = (opts?: {
certificates?: TSignerAlertCertificate[];
onFindExpiring?: (args: Record<string, unknown>) => void;
+ onFindSignerIds?: (ids: string[]) => void;
abilityRules?: { action: string; subject: string }[];
projectRoles?: string[];
pkiEnterpriseAlerting?: boolean;
@@ -67,7 +70,13 @@ const buildProvider = (opts?: {
findExpiringSignerCertificates: async (args: Record<string, unknown>) => {
opts?.onFindExpiring?.(args);
return opts?.certificates ?? [];
- }
+ },
+ findProjectSignerIds: async (_projectId: string, ids: string[]) => {
+ opts?.onFindSignerIds?.(ids);
+ return ids.filter((id) => id.toLowerCase() === SIGNER_ID);
+ },
+ findSignerNamesByIds: async (_projectId: string, ids: string[]) =>
+ ids.includes(SIGNER_ID) ? [{ id: SIGNER_ID, name: "release-signer" }] : []
},
permissionService: {
getProjectPermission: async () => ({
@@ -80,7 +89,7 @@ const buildProvider = (opts?: {
} as unknown as TCertManagerSignerAlertProviderDep);
describe("cert manager signer alert provider", () => {
- test("owns one scheduled event that takes only alertBefore and dailyReminder", () => {
+ test("owns one scheduled event that takes alertBefore, dailyReminder and signerIds", () => {
const provider = buildProvider();
expect(provider.resourceType).toBe(RESOURCE_TYPE);
expect(provider.events.map((event) => event.key)).toEqual([EXPIRY_EVENT]);
@@ -92,6 +101,12 @@ describe("cert manager signer alert provider", () => {
false
);
expect(event.conditionSchema.safeParse({ alertBefore: "400d" }).success).toBe(false);
+ expect(event.conditionSchema.safeParse({ alertBefore: "30d", signerIds: [SIGNER_ID] }).success).toBe(true);
+ expect(event.conditionSchema.safeParse({ alertBefore: "30d", signerIds: [] }).success).toBe(false);
+ expect(event.conditionSchema.safeParse({ alertBefore: "30d", signerIds: ["not-a-uuid"] }).success).toBe(false);
+ expect(
+ event.conditionSchema.safeParse({ alertBefore: "30d", signerIds: [SIGNER_ID, SIGNER_ID.toUpperCase()] }).success
+ ).toBe(false);
});
test("scans every active signer's certificate, and nothing for a bound alert or one with no channels", async () => {
@@ -115,6 +130,9 @@ describe("cert manager signer alert provider", () => {
await expect(provider.findScheduledTargets(input)).resolves.toEqual([signerCertificate()]);
expect(scanArgs).toMatchObject({ projectId: "proj-1", alertBeforeInterval: "14 days", asOf, alreadyAlerted });
+ expect(scanArgs?.signerIds).toBeUndefined();
+ await provider.findScheduledTargets({ ...input, condition: { alertBefore: "2w", signerIds: [SIGNER_ID] } });
+ expect(scanArgs).toMatchObject({ signerIds: [SIGNER_ID] });
await expect(provider.findScheduledTargets({ ...input, resourceId: APPLICATION_ID })).resolves.toEqual([]);
await expect(
provider.findScheduledTargets({ ...input, alreadyAlerted: { ...alreadyAlerted, channelIds: [] } })
@@ -147,18 +165,65 @@ describe("cert manager signer alert provider", () => {
const bound = { action: AlertPermissionAction.Create, orgId: "org-1", projectId: "proj-1", actor };
await expect(provider.assertPermission({ ...bound, resourceId: APPLICATION_ID })).rejects.toThrow(
- "can't be bound to a resource"
+ "aren't bound to a single signer"
);
await expect(provider.assertResourceInScope({ orgId: "org-1", resourceId: APPLICATION_ID })).rejects.toThrow(
- "can't be bound to a resource"
+ "aren't bound to a single signer"
);
await expect(provider.resolveProjectId?.({ orgId: "org-1", resourceId: APPLICATION_ID })).rejects.toThrow(
- "can't be bound to a resource"
+ "aren't bound to a single signer"
);
await expect(provider.resolveProjectId?.({ orgId: "org-1" })).resolves.toBe("proj-1");
await expect(provider.resolveProjectId?.({ orgId: "org-2" })).rejects.toThrow("Certificate Manager isn't set up");
});
+ test("assertConditionInScope rejects signers outside the project, checking only the IDs an update adds", async () => {
+ const lookups: string[][] = [];
+ const provider = buildProvider({ onFindSignerIds: (ids) => lookups.push(ids) });
+
+ await expect(
+ provider.assertConditionInScope?.({
+ projectId: "proj-1",
+ condition: { alertBefore: "30d", signerIds: [SIGNER_ID] }
+ })
+ ).resolves.toBeUndefined();
+ await expect(
+ provider.assertConditionInScope?.({
+ projectId: "proj-1",
+ condition: { alertBefore: "30d", signerIds: [OTHER_SIGNER_ID] }
+ })
+ ).rejects.toThrow(`Signer not found in Certificate Manager: '${OTHER_SIGNER_ID}'`);
+
+ lookups.length = 0;
+ await expect(
+ provider.assertConditionInScope?.({
+ projectId: "proj-1",
+ condition: { alertBefore: "30d", signerIds: [OTHER_SIGNER_ID, SIGNER_ID] },
+ previousCondition: { alertBefore: "30d", signerIds: [OTHER_SIGNER_ID] }
+ })
+ ).resolves.toBeUndefined();
+ expect(lookups).toEqual([[SIGNER_ID]]);
+ });
+
+ test("getFilters names each filtered signer, and a deleted one with a null name", async () => {
+ const filters = await buildProvider().getFilters?.({
+ orgId: "org-1",
+ projectId: "proj-1",
+ alerts: [
+ { id: "alert-1", condition: { alertBefore: "30d", signerIds: [SIGNER_ID, OTHER_SIGNER_ID] } },
+ { id: "alert-2", condition: { alertBefore: "30d" } }
+ ]
+ });
+
+ expect(filters?.get("alert-1")).toEqual({
+ signers: [
+ { id: SIGNER_ID, name: "release-signer" },
+ { id: OTHER_SIGNER_ID, name: null }
+ ]
+ });
+ expect(filters?.get("alert-2")).toEqual({ signers: [] });
+ });
+
test("buildPayload names the signer, links to Code Signing, and delivers under its own key", async () => {
const provider = buildProvider();
const viewUrl = await provider.buildViewUrl(signerAlert);
diff --git a/backend/src/services/alert/providers/cert-manager-signer-alert-provider.ts b/backend/src/services/alert/providers/cert-manager-signer-alert-provider.ts
index e192bd0e1a..6f6b026121 100644
--- a/backend/src/services/alert/providers/cert-manager-signer-alert-provider.ts
+++ b/backend/src/services/alert/providers/cert-manager-signer-alert-provider.ts
@@ -1,7 +1,9 @@
+import { z } from "zod";
+
import { TLicenseServiceFactory } from "@app/ee/services/license/license-service";
import { TPermissionServiceFactory } from "@app/ee/services/permission/permission-service-types";
import { getConfig } from "@app/lib/config/env";
-import { BadRequestError } from "@app/lib/errors";
+import { BadRequestError, NotFoundError } from "@app/lib/errors";
import { TCertManagerProjectResolverFactory } from "@app/services/cert-manager-instance/cert-manager-project-resolver";
import { CERT_MANAGER_SIGNER_RESOURCE_TYPE, SignerAlertEvent } from "@app/services/signer/signer-alert-events";
import { PkiAlertScope } from "@app/services/telemetry/telemetry-types";
@@ -13,6 +15,7 @@ import {
AlertTriggerType,
IScheduledAlertProvider,
TAlertContext,
+ TAlertFilters,
TAlertPermissionInput,
TAlertTelemetryInput,
TFindScheduledTargetsInput
@@ -25,18 +28,28 @@ import {
certificateDisplayName,
expiryDedupWindowHours,
ExpiryFieldsSchema,
+ filterIdsSchema,
+ formatIds,
getScopeWideAlertWebhookSource,
resolveCertManagerProjectId,
- splitAltNames
+ splitAltNames,
+ toIdSet
} from "./cert-manager-alert-fns";
import { TCertManagerSignerAlertDALFactory, TSignerAlertCertificate } from "./cert-manager-signer-alert-dal";
-const SignerExpirationConditionSchema = ExpiryFieldsSchema.strict();
+const SignerFilterSchema = z.object({ signerIds: filterIdsSchema("signerIds", "signer") });
+
+const SignerExpirationConditionSchema = ExpiryFieldsSchema.merge(SignerFilterSchema).strict();
+
+const parseFilters = (condition: unknown) => {
+ const filters = SignerFilterSchema.safeParse(condition ?? {});
+ return filters.success ? filters.data : {};
+};
const assertNoResource = (resourceId?: string | null) =>
assertNoAlertResource(
resourceId,
- "Signer certificate expiration alerts cover every signer in Certificate Manager and can't be bound to a resource. Remove resourceId."
+ "Signer certificate expiration alerts aren't bound to a single signer. Remove resourceId, and use signerIds to narrow the alert to specific signers."
);
const formatSigners = (signerNames: string[]) =>
@@ -57,10 +70,11 @@ export const certManagerSignerAlertProviderFactory = ({
}: TCertManagerSignerAlertProviderDep): IScheduledAlertProvider<TSignerAlertCertificate> => {
const findScheduledTargets = async (input: TFindScheduledTargetsInput): Promise<TSignerAlertCertificate[]> => {
if (!input.projectId || input.resourceId || !input.alreadyAlerted?.channelIds.length) return [];
- const { alertBefore } = SignerExpirationConditionSchema.parse(input.condition);
+ const { alertBefore, signerIds } = SignerExpirationConditionSchema.parse(input.condition);
return certManagerSignerAlertDAL.findExpiringSignerCertificates({
projectId: input.projectId,
+ signerIds,
alertBeforeInterval: `${durationToDays(alertBefore)} days`,
leadInterval: ALERT_SCAN_LEAD_INTERVAL,
asOf: input.asOf,
@@ -137,6 +151,52 @@ export const certManagerSignerAlertProviderFactory = ({
);
};
+ const assertConditionInScope = async (input: {
+ projectId?: string | null;
+ condition: unknown;
+ previousCondition?: unknown;
+ }): Promise<void> => {
+ if (!input.projectId) return;
+ const { signerIds = [] } = SignerFilterSchema.parse(input.condition ?? {});
+
+ const savedSignerIds = toIdSet(parseFilters(input.previousCondition).signerIds);
+ const addedSignerIds = signerIds.filter((id) => !savedSignerIds.has(id.toLowerCase()));
+ if (!addedSignerIds.length) return;
+
+ const foundSignerIds = toIdSet(
+ await certManagerSignerAlertDAL.findProjectSignerIds(input.projectId, addedSignerIds)
+ );
+ const missingSignerIds = addedSignerIds.filter((id) => !foundSignerIds.has(id.toLowerCase()));
+ if (missingSignerIds.length) {
+ throw new NotFoundError({
+ message: `${missingSignerIds.length === 1 ? "Signer" : "Signers"} not found in Certificate Manager: ${formatIds(missingSignerIds)}`
+ });
+ }
+ };
+
+ const getFilters = async ({
+ projectId,
+ alerts
+ }: {
+ projectId: string | null;
+ alerts: { id: string; condition: unknown }[];
+ }): Promise<Map<string, TAlertFilters>> => {
+ const filtersByAlert = alerts.map((alert) => ({ id: alert.id, ...parseFilters(alert.condition) }));
+ const signerIds = [...new Set(filtersByAlert.flatMap((filters) => filters.signerIds ?? []))];
+
+ const signers = projectId ? await certManagerSignerAlertDAL.findSignerNamesByIds(projectId, signerIds) : [];
+ const nameById = new Map(signers.map((signer) => [signer.id.toLowerCase(), signer.name]));
+
+ return new Map(
+ filtersByAlert.map((filters) => [
+ filters.id,
+ {
+ signers: (filters.signerIds ?? []).map((id) => ({ id, name: nameById.get(id.toLowerCase()) ?? null }))
+ }
+ ])
+ );
+ };
+
const getTelemetryEvent = ({ action, orgId, projectId }: TAlertTelemetryInput) => {
if (!projectId) return undefined;
return buildPkiAlertTelemetryEvent(
@@ -163,10 +223,12 @@ export const certManagerSignerAlertProviderFactory = ({
dedupWindowHours: expiryDedupWindowHours,
assertPermission,
assertResourceInScope: async ({ resourceId }) => assertNoResource(resourceId),
+ assertConditionInScope,
assertChannelTypesAllowed: (input) => assertCertManagerAlertChannelTypesAllowed(licenseService, input),
recipientPolicy: { atOrgScope: true, allowEmailAddresses: true },
includeLastRun: true,
getWebhookSource: getScopeWideAlertWebhookSource,
+ getFilters,
getTelemetryEvent,
resolveProjectId: async ({ orgId, resourceId }) => {
assertNoResource(resourceId);
diff --git a/docs/documentation/platform/pki/applications/alerting/overview.mdx b/docs/documentation/platform/pki/applications/alerting/overview.mdx
index b6dbb6bc30..ed5736870e 100644
--- a/docs/documentation/platform/pki/applications/alerting/overview.mdx
+++ b/docs/documentation/platform/pki/applications/alerting/overview.mdx
@@ -65,6 +65,10 @@ An expiration alert keeps notifying you about the same certificate until the cer
## Signer certificate expiration
-A **Signer Certificate Expiration** alert, in the **Code Signing** group, warns you before a [signer's](/documentation/platform/pki/code-signing/signers) current certificate expires. You can only create it as a Certificate Manager alert. It covers every active signer under **Code Signing** > **Signers** and skips the **Filters** step. Otherwise, it works like a certificate expiration alert.
+A **Signer Certificate Expiration** alert, in the **Code Signing** group, warns you before a [signer's](/documentation/platform/pki/code-signing/signers) current certificate expires. You can only create it as a Certificate Manager alert. Otherwise, it works like a certificate expiration alert.
+
+Without filters, the alert covers every active signer under **Code Signing** > **Signers**. To cover only some signers, add a **Signers** filter in the **Filters** step and select up to 100 signers. If several signers share a certificate, the notification names only the selected ones.
+
+If you delete a signer that the filter lists, the deleted signer stays in the filter and matches no certificates. When you edit the alert, the **Filters** step shows it as **Unknown signer**, so you can remove it.
When you reissue a signer's certificate, the alert follows the new certificate and stops alerting on the one it replaced. The alert doesn't cover disabled, failed, or pending signers.
diff --git a/docs/documentation/platform/pki/applications/alerting/webhook-alerts.mdx b/docs/documentation/platform/pki/applications/alerting/webhook-alerts.mdx
index 9d537b39d2..7b98d9b21f 100644
--- a/docs/documentation/platform/pki/applications/alerting/webhook-alerts.mdx
+++ b/docs/documentation/platform/pki/applications/alerting/webhook-alerts.mdx
@@ -92,7 +92,7 @@ To find out which kind of alert sent a request, read `data.alert.resourceType`:
- `cert-manager.application`: an application alert, with the application's ID in `data.alert.resourceId`
- `cert-manager`: a Certificate Manager alert
-- `cert-manager.signer`: a signer certificate expiration alert, whose items list the signers in `resource.signerIds` and `resource.signerNames`
+- `cert-manager.signer`: a signer certificate expiration alert, whose items list the signers in `resource.signerIds` and `resource.signerNames`. If the alert has a **Signers** filter, the items list only the selected signers.
<Note>
Alerts created before certificate alerts moved to applications keep sending the older `com.infisical.pki.certificate.*` event types with a `data.certificates` list. If one endpoint receives both, check the `type` field to tell them apart.
diff --git a/frontend/src/hooks/api/alerts/types.ts b/frontend/src/hooks/api/alerts/types.ts
index 69719d12f9..b13e6fd331 100644
--- a/frontend/src/hooks/api/alerts/types.ts
+++ b/frontend/src/hooks/api/alerts/types.ts
@@ -207,6 +207,7 @@ export type TAlert = {
applicationIds?: string[];
profileIds?: string[];
sources?: CertSource[];
+ signerIds?: string[];
} | null;
enabled: boolean;
orgId: string;
diff --git a/frontend/src/pages/cert-manager/components/CertificateAlerts/CertificateAlertsCard.tsx b/frontend/src/pages/cert-manager/components/CertificateAlerts/CertificateAlertsCard.tsx
index e941635593..6ebba25327 100644
--- a/frontend/src/pages/cert-manager/components/CertificateAlerts/CertificateAlertsCard.tsx
+++ b/frontend/src/pages/cert-manager/components/CertificateAlerts/CertificateAlertsCard.tsx
@@ -65,13 +65,13 @@ import {
CERTIFICATE_ALERT_EVENT_LABELS,
CERTIFICATE_FILTER_DEFINITIONS,
CertificateAlertScopeKind,
- CertificateFilterKind,
formatAlertBefore,
fromApiEventType,
getAlertResourceId,
+ getFilterKinds,
getFilterName,
getScopeEventTypes,
- isFilterableEventType,
+ isSignerEventType,
pluralize,
TCertificateAlertScope,
toConditionNames
@@ -97,17 +97,18 @@ const SCOPE_CARD_CONFIG: Record<
const AlertFiltersSummary = ({ alert }: { alert: TAlert }) => {
const conditionNames = toConditionNames(alert);
- const activeFilters = Object.values(CertificateFilterKind).flatMap((kind) => {
+ const eventType = alert.eventType as TCertificateAlertEventType;
+ const activeFilters = getFilterKinds(eventType).flatMap((kind) => {
const ids: string[] = alert.condition?.[kind] ?? [];
return ids.length ? [{ kind, ids }] : [];
});
- if (!isFilterableEventType(alert.eventType as TCertificateAlertEventType)) {
- return <span className="text-muted">All signers</span>;
- }
-
if (!activeFilters.length) {
- return <span className="text-muted">All certificates</span>;
+ return (
+ <span className="text-muted">
+ {isSignerEventType(eventType) ? "All signers" : "All certificates"}
+ </span>
+ );
}
return (
diff --git a/frontend/src/pages/cert-manager/components/CertificateAlerts/CertificateFilterSelects.tsx b/frontend/src/pages/cert-manager/components/CertificateAlerts/CertificateFilterSelects.tsx
index f573380b87..1729c43064 100644
--- a/frontend/src/pages/cert-manager/components/CertificateAlerts/CertificateFilterSelects.tsx
+++ b/frontend/src/pages/cert-manager/components/CertificateAlerts/CertificateFilterSelects.tsx
@@ -6,6 +6,7 @@ import { MAX_CERTIFICATE_ALERT_FILTER_IDS } from "@app/hooks/api/alerts";
import { useListCertificateProfiles } from "@app/hooks/api/certificateProfiles";
import { CertSource } from "@app/hooks/api/certificates/enums";
import { useListPkiApplications } from "@app/hooks/api/pkiApplications";
+import { useListSigners } from "@app/hooks/api/signers";
import { CertificateFilterKind, getFilterName } from "./types";
@@ -14,6 +15,7 @@ type TFilterOption = { id: string; name: string };
type Props = {
value: string[];
conditionNames: Record<string, string>;
+ projectId: string;
onChange: (selected: TFilterOption[]) => void;
};
@@ -105,6 +107,31 @@ export const ProfileFilterSelect = (props: Props) => {
);
};
+export const SignerFilterSelect = (props: Props) => {
+ const [search, setSearch] = useState("");
+ const [debouncedSearch] = useDebounce(search);
+ const { data, isPending } = useListSigners({
+ projectId: props.projectId,
+ limit: MAX_CERTIFICATE_ALERT_FILTER_IDS,
+ ...(debouncedSearch ? { search: debouncedSearch } : {})
+ });
+ const options = useMemo(
+ () => (data?.signers ?? []).map(({ id, name }) => ({ id, name })),
+ [data]
+ );
+
+ return (
+ <FilterCombobox
+ {...props}
+ kind={CertificateFilterKind.Signers}
+ options={options}
+ isLoading={isPending}
+ onSearchChange={setSearch}
+ placeholder="Select signers"
+ />
+ );
+};
+
const SOURCE_OPTIONS = Object.values(CertSource).map((source) => ({
id: source,
name: getFilterName(CertificateFilterKind.Sources, source, {})
diff --git a/frontend/src/pages/cert-manager/components/CertificateAlerts/DetailsStep.tsx b/frontend/src/pages/cert-manager/components/CertificateAlerts/DetailsStep.tsx
index e770874510..51370f8881 100644
--- a/frontend/src/pages/cert-manager/components/CertificateAlerts/DetailsStep.tsx
+++ b/frontend/src/pages/cert-manager/components/CertificateAlerts/DetailsStep.tsx
@@ -25,9 +25,9 @@ import {
CERTIFICATE_ALERT_EVENT_LABELS,
CertificateFilterKind,
getAlertEventDescription,
+ getFilterKinds,
getScopeEventGroups,
isExpiryEventType,
- isFilterableEventType,
TCertificateAlertForm,
TCertificateAlertScope
} from "./types";
@@ -48,11 +48,10 @@ export const DetailsStep = ({ form, scope, isEditing, usedEventTypes }: Props) =
onChange: (value: string) => void
) => {
onChange(next);
- if (!isFilterableEventType(next)) {
- Object.values(CertificateFilterKind).forEach((kind) =>
- form.setValue(kind, undefined, { shouldDirty: true })
- );
- }
+ const nextKinds = getFilterKinds(next);
+ Object.values(CertificateFilterKind)
+ .filter((kind) => !nextKinds.includes(kind))
+ .forEach((kind) => form.setValue(kind, undefined, { shouldDirty: true }));
};
return (
diff --git a/frontend/src/pages/cert-manager/components/CertificateAlerts/FiltersStep.tsx b/frontend/src/pages/cert-manager/components/CertificateAlerts/FiltersStep.tsx
index 3303d08ed1..d1f0e59776 100644
--- a/frontend/src/pages/cert-manager/components/CertificateAlerts/FiltersStep.tsx
+++ b/frontend/src/pages/cert-manager/components/CertificateAlerts/FiltersStep.tsx
@@ -25,37 +25,50 @@ import { CertStatus } from "@app/hooks/api/certificates/enums";
import {
ApplicationFilterSelect,
ProfileFilterSelect,
+ SignerFilterSelect,
SourceFilterSelect
} from "./CertificateFilterSelects";
import {
CERTIFICATE_FILTER_DEFINITIONS,
CertificateFilterKind,
- NO_FILTERS_DESCRIPTION,
+ getFilterKinds,
+ getNoFiltersDescription,
+ isSignerEventType,
TCertificateAlertForm
} from "./types";
const MATCHED_PAGE_SIZE = 20;
-const FILTER_KINDS = Object.values(CertificateFilterKind);
+const CERTIFICATE_FILTER_KINDS = [
+ CertificateFilterKind.Applications,
+ CertificateFilterKind.Profiles,
+ CertificateFilterKind.Sources
+] as const;
const FILTER_SELECTS = {
[CertificateFilterKind.Applications]: ApplicationFilterSelect,
[CertificateFilterKind.Profiles]: ProfileFilterSelect,
- [CertificateFilterKind.Sources]: SourceFilterSelect
+ [CertificateFilterKind.Sources]: SourceFilterSelect,
+ [CertificateFilterKind.Signers]: SignerFilterSelect
};
type Props = { form: UseFormReturn<TCertificateAlertForm>; projectId: string };
-export const FiltersStep = ({ form, projectId }: Props) => {
- const applicationIds = useWatch({
- control: form.control,
- name: CertificateFilterKind.Applications
- });
- const profileIds = useWatch({ control: form.control, name: CertificateFilterKind.Profiles });
- const sources = useWatch({ control: form.control, name: CertificateFilterKind.Sources });
- const conditionNames = useWatch({ control: form.control, name: "conditionNames" });
- const filters = { applicationIds, profileIds, sources };
+type TCertificateFilters = Pick<
+ TCertificateAlertForm,
+ | CertificateFilterKind.Applications
+ | CertificateFilterKind.Profiles
+ | CertificateFilterKind.Sources
+>;
+const MatchedCertificatesPreview = ({
+ filters,
+ projectId
+}: {
+ filters: TCertificateFilters;
+ projectId: string;
+}) => {
+ const { applicationIds, profileIds, sources } = filters;
const previewFilters = {
applicationIds: applicationIds?.length ? applicationIds : undefined,
profileIds: profileIds?.length ? profileIds : undefined,
@@ -83,19 +96,11 @@ export const FiltersStep = ({ form, projectId }: Props) => {
source: previewFilters.sources
});
- const setFilter = (kind: CertificateFilterKind, ids: string[] | undefined) =>
- form.setValue(kind, ids as TCertificateAlertForm[typeof kind], {
- shouldDirty: true,
- shouldValidate: true
- });
- const addFilter = (kind: CertificateFilterKind) => form.setValue(kind, [], { shouldDirty: true });
-
- const presentKinds = FILTER_KINDS.filter((kind) => filters[kind] !== undefined);
- const addableKinds = FILTER_KINDS.filter((kind) => filters[kind] === undefined);
-
const matchedCount = preview?.totalCount ?? 0;
- const isPreviewFiltered = FILTER_KINDS.some((kind) => previewFilters[kind] !== undefined);
- const hasUnfinishedFilter = FILTER_KINDS.some((kind) => filters[kind]?.length === 0);
+ const isPreviewFiltered = CERTIFICATE_FILTER_KINDS.some(
+ (kind) => previewFilters[kind] !== undefined
+ );
+ const hasUnfinishedFilter = CERTIFICATE_FILTER_KINDS.some((kind) => filters[kind]?.length === 0);
const certificatesLabel = `${matchedCount} active certificate${matchedCount === 1 ? "" : "s"}`;
let previewSummary = "Loading the certificates this alert covers.";
if (isPreviewError && !isPreviewing) {
@@ -128,12 +133,82 @@ export const FiltersStep = ({ form, projectId }: Props) => {
}
const showPreviewRows = !isPreviewError && !hasUnfinishedFilter;
+ return (
+ <>
+ <div className="mt-8 flex items-end justify-between gap-3">
+ <div>
+ <p className="text-sm font-medium text-foreground">Matched Certificates</p>
+ <p className="mt-0.5 text-xs text-muted">{previewSummary}</p>
+ </div>
+ {isPreviewError && (
+ <Button
+ type="button"
+ variant="outline"
+ size="xs"
+ isPending={isPreviewing}
+ isDisabled={isPreviewing}
+ onClick={() => retryPreview()}
+ >
+ Retry
+ </Button>
+ )}
+ </div>
+
+ <div className="mt-3">
+ <PkiSyncMatchedCertificatesTable
+ rows={showPreviewRows ? (preview?.certificates ?? []) : []}
+ isLoading={showPreviewRows && !preview}
+ emptyTitle={previewEmptyState.title}
+ emptyDescription={previewEmptyState.description}
+ />
+ {showPreviewRows && matchedCount > MATCHED_PAGE_SIZE && (
+ <Pagination
+ className="mt-2"
+ count={matchedCount}
+ page={page}
+ perPage={MATCHED_PAGE_SIZE}
+ onChangePage={setPage}
+ onChangePerPage={() => {}}
+ perPageList={[MATCHED_PAGE_SIZE]}
+ />
+ )}
+ </div>
+ </>
+ );
+};
+
+export const FiltersStep = ({ form, projectId }: Props) => {
+ const eventType = useWatch({ control: form.control, name: "eventType" });
+ const applicationIds = useWatch({
+ control: form.control,
+ name: CertificateFilterKind.Applications
+ });
+ const profileIds = useWatch({ control: form.control, name: CertificateFilterKind.Profiles });
+ const sources = useWatch({ control: form.control, name: CertificateFilterKind.Sources });
+ const signerIds = useWatch({ control: form.control, name: CertificateFilterKind.Signers });
+ const conditionNames = useWatch({ control: form.control, name: "conditionNames" });
+ const filters = { applicationIds, profileIds, sources, signerIds };
+ const isSignerEvent = isSignerEventType(eventType);
+
+ const setFilter = (kind: CertificateFilterKind, ids: string[] | undefined) =>
+ form.setValue(kind, ids as TCertificateAlertForm[typeof kind], {
+ shouldDirty: true,
+ shouldValidate: true
+ });
+ const addFilter = (kind: CertificateFilterKind) => form.setValue(kind, [], { shouldDirty: true });
+
+ const filterKinds = getFilterKinds(eventType);
+ const presentKinds = filterKinds.filter((kind) => filters[kind] !== undefined);
+ const addableKinds = filterKinds.filter((kind) => filters[kind] === undefined);
+
return (
<div className="flex flex-col">
<div>
<p className="text-sm font-medium text-foreground">Filters</p>
<p className="mt-0.5 text-xs text-muted">
- A certificate is covered only when it matches every filter below.
+ {isSignerEvent
+ ? "Only the certificates of the signers selected below are covered."
+ : "A certificate is covered only when it matches every filter below."}
</p>
</div>
@@ -158,6 +233,7 @@ export const FiltersStep = ({ form, projectId }: Props) => {
<Select
value={filters[kind] ?? []}
conditionNames={conditionNames}
+ projectId={projectId}
onChange={(selected) => {
if (kind !== CertificateFilterKind.Sources) {
form.setValue("conditionNames", {
@@ -194,7 +270,9 @@ export const FiltersStep = ({ form, projectId }: Props) => {
<EmptyMedia variant="icon">
<FilterIcon />
</EmptyMedia>
- <EmptyDescription>{NO_FILTERS_DESCRIPTION} Add a filter to narrow it.</EmptyDescription>
+ <EmptyDescription>
+ {getNoFiltersDescription(eventType)} Add a filter to narrow it.
+ </EmptyDescription>
</Empty>
)}
@@ -223,44 +301,7 @@ export const FiltersStep = ({ form, projectId }: Props) => {
</div>
)}
- <div className="mt-8 flex items-end justify-between gap-3">
- <div>
- <p className="text-sm font-medium text-foreground">Matched Certificates</p>
- <p className="mt-0.5 text-xs text-muted">{previewSummary}</p>
- </div>
- {isPreviewError && (
- <Button
- type="button"
- variant="outline"
- size="xs"
- isPending={isPreviewing}
- isDisabled={isPreviewing}
- onClick={() => retryPreview()}
- >
- Retry
- </Button>
- )}
- </div>
-
- <div className="mt-3">
- <PkiSyncMatchedCertificatesTable
- rows={showPreviewRows ? (preview?.certificates ?? []) : []}
- isLoading={showPreviewRows && !preview}
- emptyTitle={previewEmptyState.title}
- emptyDescription={previewEmptyState.description}
- />
- {showPreviewRows && matchedCount > MATCHED_PAGE_SIZE && (
- <Pagination
- className="mt-2"
- count={matchedCount}
- page={page}
- perPage={MATCHED_PAGE_SIZE}
- onChangePage={setPage}
- onChangePerPage={() => {}}
- perPageList={[MATCHED_PAGE_SIZE]}
- />
- )}
- </div>
+ {!isSignerEvent && <MatchedCertificatesPreview filters={filters} projectId={projectId} />}
</div>
);
};
diff --git a/frontend/src/pages/cert-manager/components/CertificateAlerts/ReviewStep.tsx b/frontend/src/pages/cert-manager/components/CertificateAlerts/ReviewStep.tsx
index d621c743fb..f3984cf03b 100644
--- a/frontend/src/pages/cert-manager/components/CertificateAlerts/ReviewStep.tsx
+++ b/frontend/src/pages/cert-manager/components/CertificateAlerts/ReviewStep.tsx
@@ -16,10 +16,11 @@ import {
CertificateAlertScopeKind,
CertificateFilterKind,
formatAlertBefore,
+ getFilterKinds,
getFilterName,
+ getNoFiltersDescription,
isExpiryEventType,
- isFilterableEventType,
- NO_FILTERS_DESCRIPTION,
+ isSignerEventType,
TCertificateAlertForm,
TCertificateAlertScope,
TMemberEmails,
@@ -73,14 +74,16 @@ const describeChannel = (channel: TChannelForm, members: TMemberEmails): string
};
const FilterDetails = ({
+ kinds,
filters,
conditionNames
}: {
+ kinds: CertificateFilterKind[];
filters: Partial<Record<CertificateFilterKind, string[]>>;
conditionNames: Record<string, string>;
}) => (
<>
- {Object.values(CertificateFilterKind).map((kind) => {
+ {kinds.map((kind) => {
const ids = filters[kind] ?? [];
return (
<Detail key={kind} label={CERTIFICATE_FILTER_DEFINITIONS[kind].label}>
@@ -100,6 +103,7 @@ const FilterDetails = ({
export const ReviewStep = ({ form, scope, members }: Props) => {
const values = useWatch({ control: form.control }) as TCertificateAlertForm;
const isExpiry = isExpiryEventType(values.eventType);
+ const filterKinds = getFilterKinds(values.eventType);
return (
<div className="flex flex-col gap-8">
@@ -122,18 +126,23 @@ export const ReviewStep = ({ form, scope, members }: Props) => {
</div>
</Section>
- {scope.kind === CertificateAlertScopeKind.CertificateManager &&
- isFilterableEventType(values.eventType) && (
- <Section title="Certificate Filters">
- {Object.values(CertificateFilterKind).some((kind) => values[kind]?.length) ? (
- <div className="grid grid-cols-2 gap-x-6 gap-y-4">
- <FilterDetails filters={values} conditionNames={values.conditionNames} />
- </div>
- ) : (
- <span className="text-sm text-muted">{NO_FILTERS_DESCRIPTION}</span>
- )}
- </Section>
- )}
+ {scope.kind === CertificateAlertScopeKind.CertificateManager && (
+ <Section
+ title={isSignerEventType(values.eventType) ? "Signer Filters" : "Certificate Filters"}
+ >
+ {filterKinds.some((kind) => values[kind]?.length) ? (
+ <div className="grid grid-cols-2 gap-x-6 gap-y-4">
+ <FilterDetails
+ kinds={filterKinds}
+ filters={values}
+ conditionNames={values.conditionNames}
+ />
+ </div>
+ ) : (
+ <span className="text-sm text-muted">{getNoFiltersDescription(values.eventType)}</span>
+ )}
+ </Section>
+ )}
<Section title="Notification Channels">
<div className="flex flex-col gap-3">
diff --git a/frontend/src/pages/cert-manager/components/CertificateAlerts/types.ts b/frontend/src/pages/cert-manager/components/CertificateAlerts/types.ts
index 286e4caea1..db5612bb5c 100644
--- a/frontend/src/pages/cert-manager/components/CertificateAlerts/types.ts
+++ b/frontend/src/pages/cert-manager/components/CertificateAlerts/types.ts
@@ -70,8 +70,8 @@ export const isExpiryEventType = (eventType: TCertificateAlertEventType) =>
eventType === CertificateApplicationAlertEventType.Expiry ||
eventType === SignerAlertEventType.CertificateExpiry;
-export const isFilterableEventType = (eventType: TCertificateAlertEventType) =>
- eventType !== SignerAlertEventType.CertificateExpiry;
+export const isSignerEventType = (eventType: TCertificateAlertEventType) =>
+ eventType === SignerAlertEventType.CertificateExpiry;
const CERTIFICATE_MANAGER_EVENT_TYPES: Partial<
Record<TCertificateAlertEventType, CertificateManagerAlertEventType>
@@ -185,9 +185,19 @@ export const toRecipientEmails = (
export enum CertificateFilterKind {
Applications = "applicationIds",
Profiles = "profileIds",
- Sources = "sources"
+ Sources = "sources",
+ Signers = "signerIds"
}
+export const getFilterKinds = (eventType: TCertificateAlertEventType) =>
+ isSignerEventType(eventType)
+ ? [CertificateFilterKind.Signers]
+ : [
+ CertificateFilterKind.Applications,
+ CertificateFilterKind.Profiles,
+ CertificateFilterKind.Sources
+ ];
+
export const CERTIFICATE_FILTER_DEFINITIONS: Record<
CertificateFilterKind,
{ label: string; noun: string; hint: string; allLabel: string; unknownLabel: string }
@@ -212,10 +222,20 @@ export const CERTIFICATE_FILTER_DEFINITIONS: Record<
hint: "Managed, imported, or discovered certificates",
allLabel: "All sources",
unknownLabel: "Unknown source"
+ },
+ [CertificateFilterKind.Signers]: {
+ label: "Signers",
+ noun: "signer",
+ hint: "Certificates of one of these signers",
+ allLabel: "All signers",
+ unknownLabel: "Unknown signer"
}
};
-export const NO_FILTERS_DESCRIPTION = "No filters. This alert covers every certificate.";
+export const getNoFiltersDescription = (eventType: TCertificateAlertEventType) =>
+ isSignerEventType(eventType)
+ ? "No filters. This alert covers every active signer."
+ : "No filters. This alert covers every certificate.";
export const getFilterName = (
kind: CertificateFilterKind,
@@ -238,7 +258,8 @@ const isUnfinishedFilter = (ids?: string[]) => ids?.length === 0;
const UNFINISHED_FILTER_MESSAGES: Record<CertificateFilterKind, string> = {
[CertificateFilterKind.Applications]: "Select at least one application, or remove this filter",
[CertificateFilterKind.Profiles]: "Select at least one profile, or remove this filter",
- [CertificateFilterKind.Sources]: "Select at least one source, or remove this filter"
+ [CertificateFilterKind.Sources]: "Select at least one source, or remove this filter",
+ [CertificateFilterKind.Signers]: "Select at least one signer, or remove this filter"
};
export enum CertificateAlertStep {
@@ -275,8 +296,14 @@ const STEP_DEFINITIONS = {
}
};
+const SIGNER_FILTERS_STEP = {
+ shortDescription: "Which signers",
+ title: "Signer Filters",
+ subtitle: "Narrow which signers this alert covers, or leave it on every active signer."
+};
+
export const getSteps = (scope: TCertificateAlertScope, eventType: TCertificateAlertEventType) =>
- (scope.kind === CertificateAlertScopeKind.CertificateManager && isFilterableEventType(eventType)
+ (scope.kind === CertificateAlertScopeKind.CertificateManager
? [
CertificateAlertStep.Details,
CertificateAlertStep.Filters,
@@ -284,7 +311,13 @@ export const getSteps = (scope: TCertificateAlertScope, eventType: TCertificateA
CertificateAlertStep.Review
]
: [CertificateAlertStep.Details, CertificateAlertStep.Channels, CertificateAlertStep.Review]
- ).map((key) => ({ key, ...STEP_DEFINITIONS[key] }));
+ ).map((key) => ({
+ key,
+ ...STEP_DEFINITIONS[key],
+ ...(key === CertificateAlertStep.Filters && isSignerEventType(eventType)
+ ? SIGNER_FILTERS_STEP
+ : {})
+ }));
export const certificateAlertFormSchema = z
.object({
@@ -312,11 +345,18 @@ export const certificateAlertFormSchema = z
)
.optional(),
sources: z.array(z.nativeEnum(CertSource)).optional(),
+ signerIds: z
+ .array(z.string())
+ .max(
+ MAX_CERTIFICATE_ALERT_FILTER_IDS,
+ `Select up to ${MAX_CERTIFICATE_ALERT_FILTER_IDS} signers`
+ )
+ .optional(),
conditionNames: z.record(z.string()),
channels: z.array(channelFormSchema).min(1, "Add at least one channel").max(MAX_CHANNELS)
})
.superRefine((form, ctx) => {
- Object.values(CertificateFilterKind).forEach((kind) => {
+ getFilterKinds(form.eventType).forEach((kind) => {
if (isUnfinishedFilter(form[kind])) {
ctx.addIssue({ code: "custom", path: [kind], message: UNFINISHED_FILTER_MESSAGES[kind] });
}
@@ -378,6 +418,7 @@ export const toCertificateAlertForm = (
applicationIds: alert.condition?.applicationIds,
profileIds: alert.condition?.profileIds,
sources: alert.condition?.sources,
+ signerIds: alert.condition?.signerIds,
conditionNames: toConditionNames(alert),
channels: alert.channels.map(
(channel): TChannelForm => ({
@@ -394,13 +435,12 @@ export const toCertificateAlertForm = (
export const toCondition = (scope: TCertificateAlertScope, form: TCertificateAlertForm) => {
const filters =
- scope.kind === CertificateAlertScopeKind.CertificateManager &&
- isFilterableEventType(form.eventType)
- ? {
- ...(form.applicationIds?.length ? { applicationIds: form.applicationIds } : {}),
- ...(form.profileIds?.length ? { profileIds: form.profileIds } : {}),
- ...(form.sources?.length ? { sources: form.sources } : {})
- }
+ scope.kind === CertificateAlertScopeKind.CertificateManager
+ ? Object.fromEntries(
+ getFilterKinds(form.eventType).flatMap((kind) =>
+ form[kind]?.length ? [[kind, form[kind]] as const] : []
+ )
+ )
: {};
if (isExpiryEventType(form.eventType)) {