Skip to content

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

Move alert UI to a shared CertificateAlerts folder

Carlos Monastyrski67d32a259e3d
diff --git a/backend/CLAUDE.md b/backend/CLAUDE.md
index 61b1d7de61..88ad6d938c 100644
--- a/backend/CLAUDE.md
+++ b/backend/CLAUDE.md
@@ -707,7 +707,7 @@ Invariants worth knowing before extending it:
- **The alert module owns no CASL subject.** Each provider reuses its own resource's existing permissions inside `assertPermission`, so authorization stays with the domain that owns the resource.
- **New delivery mediums are channel definitions**, not providers: add one under `src/services/alert/channels/` and register it in `ALERT_CHANNEL_REGISTRY`. `directed: true` means the channel addresses principals and needs recipients (email); undirected channels carry their destination in config. `secretFields` drives masking on read and merge-from-stored on update.
- **Channel configs are encrypted** with the org/project KMS cipher (`alert-channel-crypto-fns.ts`) — never store or return them in plaintext.
-- **One alert per `(scope, resource, event)` for resource-bound alerts**, enforced by the partial `alert_unique_scope_resource_event_bound` index. A provider that sets `supportsScopeWideAlerts` also accepts alerts with no `resourceId`: such an alert watches every resource of its type in scope, several can watch the same event because they differ by condition, and `assertConditionInScope` is where the provider checks the IDs inside a condition, on create and on update (newly added IDs only). `findEnabledForEvent` matches exactly: the bound alerts for a `resourceId`, or the resource-less ones when it is null. To let a scope-wide provider hear another provider's events without a second outbox write, an event definition can declare `relayedFrom: { resourceType, eventKey }`; the consumer then runs the source resource's alerts plus every relaying provider's resource-less alerts (`alertProviderRegistry.relaysFor`), each under its own `eventType`. Certificate Manager-wide alerts are their own provider, `cert-manager` (`cert-manager-alert-provider.ts`, events `cert-manager.certificate.*`), narrowed by `applicationIds` and `profileIds`; its issuance, renewal and revocation events are relayed from the `cert-manager.application` events the certificate code emits, and creating or editing one requires unconditional certificate read, since it sends details from every application. `cert-manager.application` alerts are always bound to one application. Signer certificate expiration has its own provider, `cert-manager.signer` (`cert-manager-signer-alert-provider.ts`, event `cert-manager.signer.certificate.expiry`), that only exists scope-wide: it scans one row per certificate an active signer points at through `pki_signers.certificateId`, naming every signer that shares it (so a reissue moves the alert to the new certificate), takes no filters, and creating or editing one requires the project Admin role (unconditional `code-signers` read only opens the signer list; non-admins see only signers they are members of). Helpers the three Certificate Manager providers share (expiry schema, dedup windows, certificate payload, license gate, audit and telemetry builders) live in `cert-manager-alert-fns.ts`. **Every provider hook is opt-in, and its absence must reproduce the behaviour identity alerts had before any other provider existed.** `recipientPolicy` decides who can receive: `atOrgScope` validates and resolves user and group recipients against the org instead of the alert's project, and `allowEmailAddresses` accepts plain `EMAIL` recipients and makes test sends validate recipients like create and update do, instead of silently dropping out-of-scope ones (application alerts set both). `includeLastRun` adds `lastRun` to alert responses, and `resourceName` is only returned by providers that implement `getResourceNames`, and `filters` (read-only `{ id, name }` lists for the IDs inside a condition, keyed by kind, such as `applications` and `profiles` on a Certificate Manager-wide alert, with a null name for deleted IDs, matching how approval policies return approvers) only by providers that implement `getFilters`. Resolve such names there rather than adding ID filters to another domain's list endpoint. `assertChannelTypesAllowed` is where a provider gates paid channel types on create and on update (new, retyped, or re-enabled channels only, so a downgraded org can still edit the alert). `getResourceNames` (batched) supplies the resource's display name for alert responses and for a provider's own audit events. `resolveProjectId` lets create, list and test sends omit `projectId` when the resource already belongs to one project (`resolveAlertProjectId` in `alert-provider-registry.ts`). `getTelemetryEvent` lets a provider map alert create, update and delete to its own PostHog event, so the shared router never branches on a resource type. `getAuditEvent` does the same for audit logs: a provider that needs distinct event types (application alerts log `create-pki-application-alert` and its siblings, with the application's ID and name) returns its own event, and every other provider falls back to the generic `create-alert` family via `buildGenericAlertAuditEvent`. Add a provider's own event interfaces next to the generic ones; never widen the generic ones. The deprecated `pki/alerts` and `applications/:applicationId/alerts` routes only serve legacy PKI Alerts V2 rows. Add features to `/api/v1/alerts`, not to them.
+- **One alert per `(scope, resource, event)` for resource-bound alerts**, enforced by the partial `alert_unique_scope_resource_event_bound` index. A provider that sets `supportsScopeWideAlerts` also accepts alerts with no `resourceId`: such an alert watches every resource of its type in scope, several can watch the same event because they differ by condition, and `assertConditionInScope` is where the provider checks the IDs inside a condition, on create and on update (newly added IDs only). `findEnabledForEvent` matches exactly: the bound alerts for a `resourceId`, or the resource-less ones when it is null. To let a scope-wide provider hear another provider's events without a second outbox write, an event definition can declare `relayedFrom: { resourceType, eventKey }`; the consumer then runs the source resource's alerts plus every relaying provider's resource-less alerts (`alertProviderRegistry.relaysFor`), each under its own `eventType`. Certificate Manager-wide alerts are their own provider, `cert-manager` (`cert-manager-alert-provider.ts`, events `cert-manager.certificate.*`), narrowed by `applicationIds` and `profileIds`; its issuance, renewal and revocation events are relayed from the `cert-manager.application` events the certificate code emits, and creating or editing one requires the project Admin role, since it sends details from every application (PKI permissions are admin or member, not granular). `cert-manager.application` alerts are always bound to one application. Signer certificate expiration has its own provider, `cert-manager.signer` (`cert-manager-signer-alert-provider.ts`, event `cert-manager.signer.certificate.expiry`), that only exists scope-wide: it scans one row per certificate an active signer points at through `pki_signers.certificateId`, naming every signer that shares it (so a reissue moves the alert to the new certificate), takes no filters, and creating or editing one requires the project Admin role too (`assertCertManagerAdminAlertPermission` in `cert-manager-alert-fns.ts`). Helpers the three Certificate Manager providers share (expiry schema, dedup windows, certificate payload, license gate, audit and telemetry builders) live in `cert-manager-alert-fns.ts`. **Every provider hook is opt-in, and its absence must reproduce the behaviour identity alerts had before any other provider existed.** `recipientPolicy` decides who can receive: `atOrgScope` validates and resolves user and group recipients against the org instead of the alert's project, and `allowEmailAddresses` accepts plain `EMAIL` recipients and makes test sends validate recipients like create and update do, instead of silently dropping out-of-scope ones (application alerts set both). `includeLastRun` adds `lastRun` to alert responses, and `resourceName` is only returned by providers that implement `getResourceNames`, and `filters` (read-only `{ id, name }` lists for the IDs inside a condition, keyed by kind, such as `applications` and `profiles` on a Certificate Manager-wide alert, with a null name for deleted IDs, matching how approval policies return approvers) only by providers that implement `getFilters`. Resolve such names there rather than adding ID filters to another domain's list endpoint. `assertChannelTypesAllowed` is where a provider gates paid channel types on create and on update (new, retyped, or re-enabled channels only, so a downgraded org can still edit the alert). `getResourceNames` (batched) supplies the resource's display name for alert responses and for a provider's own audit events. `resolveProjectId` lets create, list and test sends omit `projectId` when the resource already belongs to one project (`resolveAlertProjectId` in `alert-provider-registry.ts`). `getTelemetryEvent` lets a provider map alert create, update and delete to its own PostHog event, so the shared router never branches on a resource type. `getAuditEvent` does the same for audit logs: a provider that needs distinct event types (application alerts log `create-pki-application-alert` and its siblings, with the application's ID and name) returns its own event, and every other provider falls back to the generic `create-alert` family via `buildGenericAlertAuditEvent`. Add a provider's own event interfaces next to the generic ones; never widen the generic ones. The deprecated `pki/alerts` and `applications/:applicationId/alerts` routes only serve legacy PKI Alerts V2 rows. Add features to `/api/v1/alerts`, not to them.
- **Email channels accept plain addresses as `EMAIL` recipients when the provider opts in** (`recipientPolicy.allowEmailAddresses`), with the address as `principalId`, besides users and groups. Every address must be on one of the org's verified email domains, checked on create, update and test sends (`alert-channel-service.ts`), and again at send time, so an address on a domain the org has since removed stops receiving alerts. The resolver sends to them directly and skips an address that a user recipient on the same channel already covers.
- **`findScheduledTargets` must return most-urgent-first.** The engine's per-channel `maxTargetsPerRun` cap keeps the head of the list and defers the tail, so ordering is what guarantees the closest-to-expiry targets are never the dropped ones.
- **A `findScheduledTargets` that caps its own row count must honour `alreadyAlerted`.** The engine passes `{ alertId, channelIds, since }` (the alert's enabled channels and its dedup cutoff), and the provider drops targets every one of those channels already delivered since then, in SQL before the limit. Dedup otherwise runs after the fetch, so once more targets are due than the cap, the same head of the list comes back every run, is deduped, and nothing past it is ever alerted. That filter alone is not enough when the dedup window is shorter than the scan interval (a daily reminder), because yesterday's head is due again, so such a provider also orders the targets this alert notified least recently first, then by expiry. The certificate alert DAL does both in `findExpiringCertificates`.
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 3167f124c1..8d4298b48c 100644
--- a/backend/src/services/alert/providers/cert-manager-alert-fns.ts
+++ b/backend/src/services/alert/providers/cert-manager-alert-fns.ts
@@ -1,13 +1,13 @@
import { ForbiddenError } from "@casl/ability";
import { z } from "zod";
-import { ActionProjectType } from "@app/db/schemas";
+import { ActionProjectType, ProjectMembershipRole } from "@app/db/schemas";
import { Event as TAuditEvent, EventType } from "@app/ee/services/audit-log/audit-log-types";
import { TLicenseServiceFactory } from "@app/ee/services/license/license-service";
import { TPermissionServiceFactory } from "@app/ee/services/permission/permission-service-types";
import { ProjectPermissionActions, ProjectPermissionSub } from "@app/ee/services/permission/project-permission";
import { CertificateSource } from "@app/ee/services/pki-discovery/pki-discovery-types";
-import { BadRequestError, NotFoundError } from "@app/lib/errors";
+import { BadRequestError, ForbiddenRequestError, NotFoundError } from "@app/lib/errors";
import { TCertManagerProjectResolverFactory } from "@app/services/cert-manager-instance/cert-manager-project-resolver";
import { getRevocationReasonLabel } from "@app/services/pki-alert-v2/pki-alert-v2-types";
import { PkiAlertScope, PostHogEventTypes } from "@app/services/telemetry/telemetry-types";
@@ -72,11 +72,12 @@ export const assertNoAlertResource = (resourceId: string | null | undefined, mes
if (resourceId) throw new BadRequestError({ message });
};
-export const getCertManagerAlertPermission = async (
+export const assertCertManagerAdminAlertPermission = async (
permissionService: Pick<TPermissionServiceFactory, "getProjectPermission">,
- { action, projectId, actor }: Pick<TAlertPermissionInput, "action" | "actor"> & { projectId: string }
+ { action, projectId, actor }: Pick<TAlertPermissionInput, "action" | "actor"> & { projectId: string },
+ adminOnlyMessage: string
) => {
- const result = await permissionService.getProjectPermission({
+ const { permission, hasRole } = await permissionService.getProjectPermission({
actor: actor.actor,
actorId: actor.actorId,
projectId,
@@ -84,11 +85,15 @@ export const getCertManagerAlertPermission = async (
actorOrgId: actor.actorOrgId,
actionProjectType: ActionProjectType.CertificateManager
});
- ForbiddenError.from(result.permission).throwUnlessCan(
+ ForbiddenError.from(permission).throwUnlessCan(
CERT_MANAGER_ALERT_PERMISSION_ACTIONS[action],
ProjectPermissionSub.PkiAlerts
);
- return result;
+
+ const definesDelivery = action === AlertPermissionAction.Create || action === AlertPermissionAction.Edit;
+ if (definesDelivery && !hasRole(ProjectMembershipRole.Admin)) {
+ throw new ForbiddenRequestError({ message: adminOnlyMessage });
+ }
};
export const splitAltNames = (altNames: string | null): string[] =>
diff --git a/backend/src/services/alert/providers/cert-manager-alert-provider.test.ts b/backend/src/services/alert/providers/cert-manager-alert-provider.test.ts
index d4635743e2..45e68ef80b 100644
--- a/backend/src/services/alert/providers/cert-manager-alert-provider.test.ts
+++ b/backend/src/services/alert/providers/cert-manager-alert-provider.test.ts
@@ -58,7 +58,8 @@ const buildProvider = (opts?: {
onFindByIds?: (args: Record<string, unknown>) => void;
onFindNames?: (ids: string[], orgId: string) => void;
onFindApplicationIds?: (ids: string[]) => void;
- abilityRules?: { action: string; subject: string; inverted?: boolean; conditions?: unknown }[];
+ abilityRules?: { action: string; subject: string }[];
+ projectRoles?: string[];
pkiEnterpriseAlerting?: boolean;
}) => {
const application = opts?.application ?? {
@@ -94,7 +95,10 @@ const buildProvider = (opts?: {
const ability = () =>
createMongoAbility((opts?.abilityRules ?? [{ action: "read", subject: "pki-alerts" }]) as never);
const permissionService = {
- getProjectPermission: vi.fn(async () => ({ permission: ability() }))
+ getProjectPermission: vi.fn(async () => ({
+ permission: ability(),
+ hasRole: (role: string) => (opts?.projectRoles ?? []).includes(role)
+ }))
};
const licenseService = {
getPlan: async () => ({ pkiEnterpriseAlerting: opts?.pkiEnterpriseAlerting ?? false })
@@ -317,10 +321,8 @@ describe("cert manager alert provider", () => {
test("refuses a resource everywhere a caller can name one", async () => {
const { provider } = buildProvider({
- abilityRules: [
- { action: "create", subject: "pki-alerts" },
- { action: "read", subject: "certificates" }
- ]
+ abilityRules: [{ action: "create", subject: "pki-alerts" }],
+ projectRoles: ["admin"]
});
const create = { action: AlertPermissionAction.Create, orgId: "org-1", projectId: "proj-1", actor };
await expect(provider.assertPermission({ ...create, resourceId: APPLICATION_ID })).rejects.toThrow(
@@ -460,38 +462,31 @@ describe("cert manager alert provider", () => {
expect(permissionService.getProjectPermission).toHaveBeenCalled();
});
- test("creating or editing an alert with no application requires reading every certificate", async () => {
+ test("creating or editing an alert with no application requires a project admin, reading and deleting only PKI alert access", async () => {
const create = { action: AlertPermissionAction.Create, orgId: "org-1", projectId: "proj-1", actor };
const alertRules = [
+ { action: "read", subject: "pki-alerts" },
{ action: "create", subject: "pki-alerts" },
- { action: "edit", subject: "pki-alerts" }
+ { action: "edit", subject: "pki-alerts" },
+ { action: "delete", subject: "pki-alerts" }
];
-
- await expect(
- buildProvider({
- abilityRules: [...alertRules, { action: "read", subject: "certificates" }]
- }).provider.assertPermission(create)
- ).resolves.toBeUndefined();
- await expect(buildProvider({ abilityRules: alertRules }).provider.assertPermission(create)).rejects.toThrow(
- "require permission to read all certificates"
+ const admin = buildProvider({ abilityRules: alertRules, projectRoles: ["admin"] }).provider;
+ const member = buildProvider({
+ abilityRules: [...alertRules, { action: "read", subject: "certificates" }],
+ projectRoles: ["member"]
+ }).provider;
+
+ await expect(admin.assertPermission(create)).resolves.toBeUndefined();
+ await expect(admin.assertPermission({ ...create, action: AlertPermissionAction.Edit })).resolves.toBeUndefined();
+ await expect(member.assertPermission(create)).rejects.toThrow("only Certificate Manager admins");
+ await expect(member.assertPermission({ ...create, action: AlertPermissionAction.Edit })).rejects.toThrow(
+ "only Certificate Manager admins"
);
+ await expect(member.assertPermission({ ...create, action: AlertPermissionAction.Read })).resolves.toBeUndefined();
+ await expect(member.assertPermission({ ...create, action: AlertPermissionAction.Delete })).resolves.toBeUndefined();
await expect(
- buildProvider({
- abilityRules: [
- ...alertRules,
- { action: "read", subject: "certificates", conditions: { commonName: { $glob: "*.internal" } } }
- ]
- }).provider.assertPermission({ ...create, action: AlertPermissionAction.Edit })
- ).rejects.toThrow("require permission to read all certificates");
- await expect(
- buildProvider({
- abilityRules: [
- ...alertRules,
- { action: "read", subject: "certificates" },
- { action: "read", subject: "certificates", inverted: true, conditions: { commonName: { $glob: "*.prod" } } }
- ]
- }).provider.assertPermission(create)
- ).rejects.toThrow("require permission to read all certificates");
+ buildProvider({ abilityRules: [], projectRoles: ["admin"] }).provider.assertPermission(create)
+ ).rejects.toThrow();
});
test("resolveProjectId falls back to the org's Certificate Manager project without an application", async () => {
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 4168a19c96..4c9e3d438e 100644
--- a/backend/src/services/alert/providers/cert-manager-alert-provider.ts
+++ b/backend/src/services/alert/providers/cert-manager-alert-provider.ts
@@ -1,16 +1,10 @@
-import { MongoAbility } from "@casl/ability";
import { z } from "zod";
import { TLicenseServiceFactory } from "@app/ee/services/license/license-service";
import { TPermissionServiceFactory } from "@app/ee/services/permission/permission-service-types";
-import {
- ProjectPermissionCertificateActions,
- ProjectPermissionSet,
- ProjectPermissionSub
-} from "@app/ee/services/permission/project-permission";
import { CertificateSource } from "@app/ee/services/pki-discovery/pki-discovery-types";
import { getConfig } from "@app/lib/config/env";
-import { BadRequestError, ForbiddenRequestError, NotFoundError } 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_APPLICATION_RESOURCE_TYPE,
@@ -24,7 +18,6 @@ import { durationToDays } from "../alert-format-fns";
import {
ALERT_SCAN_LEAD_INTERVAL,
AlertAuditAction,
- AlertPermissionAction,
AlertTriggerType,
IEventAlertProvider,
IScheduledAlertProvider,
@@ -37,6 +30,7 @@ import {
TFindScheduledTargetsInput
} from "../alert-types";
import {
+ assertCertManagerAdminAlertPermission,
assertCertManagerAlertChannelTypesAllowed,
assertNoAlertResource,
buildCertificateAlertPayload,
@@ -46,7 +40,6 @@ import {
CertificateAlertKind,
expiryDedupWindowHours,
ExpiryFieldsSchema,
- getCertManagerAlertPermission,
resolveCertManagerProjectId
} from "./cert-manager-alert-fns";
import {
@@ -114,9 +107,6 @@ const parseFilters = (condition: unknown) => {
return filters.success ? filters.data : {};
};
-const isUnconditionalGrant = (rules: ReturnType<MongoAbility<ProjectPermissionSet>["rulesFor"]>) =>
- rules.some((rule) => !rule.inverted && !rule.conditions) && !rules.some((rule) => rule.inverted);
-
const assertNoResource = (resourceId?: string | null) =>
assertNoAlertResource(
resourceId,
@@ -215,20 +205,11 @@ export const certManagerAlertProviderFactory = ({
}
assertNoResource(resourceId);
- const { permission } = await getCertManagerAlertPermission(permissionService, { action, projectId, actor });
-
- const definesDelivery = action === AlertPermissionAction.Create || action === AlertPermissionAction.Edit;
- if (
- definesDelivery &&
- !isUnconditionalGrant(
- permission.rulesFor(ProjectPermissionCertificateActions.Read, ProjectPermissionSub.Certificates)
- )
- ) {
- throw new ForbiddenRequestError({
- message:
- "Certificate Manager alerts send certificate details from every application, so they require permission to read all certificates. Create the alert on an application instead."
- });
- }
+ await assertCertManagerAdminAlertPermission(
+ permissionService,
+ { action, projectId, actor },
+ "Certificate Manager alerts send certificate details from every application, so only Certificate Manager admins can create or edit them. Create the alert on an application instead."
+ );
};
const assertConditionInScope = async (input: {
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 c40505c9cd..8f518b605c 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,8 +1,7 @@
-import { ProjectMembershipRole } from "@app/db/schemas";
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, ForbiddenRequestError } from "@app/lib/errors";
+import { BadRequestError } 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";
@@ -11,7 +10,6 @@ import { TAlertPayload } from "../alert-channel-types";
import { durationToDays, expirySeverity, formatUtcDate, humanizeDays } from "../alert-format-fns";
import {
ALERT_SCAN_LEAD_INTERVAL,
- AlertPermissionAction,
AlertTriggerType,
IScheduledAlertProvider,
TAlertContext,
@@ -20,6 +18,7 @@ import {
TFindScheduledTargetsInput
} from "../alert-types";
import {
+ assertCertManagerAdminAlertPermission,
assertCertManagerAlertChannelTypesAllowed,
assertNoAlertResource,
buildCertificateManagerAlertAuditEvent,
@@ -27,7 +26,6 @@ import {
certificateDisplayName,
expiryDedupWindowHours,
ExpiryFieldsSchema,
- getCertManagerAlertPermission,
resolveCertManagerProjectId,
splitAltNames
} from "./cert-manager-alert-fns";
@@ -134,15 +132,11 @@ export const certManagerSignerAlertProviderFactory = ({
}
assertNoResource(resourceId);
- const { hasRole } = await getCertManagerAlertPermission(permissionService, { action, projectId, actor });
-
- const definesDelivery = action === AlertPermissionAction.Create || action === AlertPermissionAction.Edit;
- if (definesDelivery && !hasRole(ProjectMembershipRole.Admin)) {
- throw new ForbiddenRequestError({
- message:
- "Signer certificate expiration alerts send certificate details from every signer, so only Certificate Manager admins can create or edit them."
- });
- }
+ await assertCertManagerAdminAlertPermission(
+ permissionService,
+ { action, projectId, actor },
+ "Signer certificate expiration alerts send certificate details from every signer, so only Certificate Manager admins can create or edit them."
+ );
};
const getTelemetryEvent = ({ action, orgId, projectId }: TAlertTelemetryInput) => {
diff --git a/docs/documentation/platform/pki/settings/alerts.mdx b/docs/documentation/platform/pki/settings/alerts.mdx
index 968d95500f..51a8914b63 100644
--- a/docs/documentation/platform/pki/settings/alerts.mdx
+++ b/docs/documentation/platform/pki/settings/alerts.mdx
@@ -10,9 +10,7 @@ Certificate Manager alerts use the same events and [notification channels](/docu
## Prerequisites
-- The **Create** action on **PKI Alerts**, which only the Certificate Manager **Admin** role has by default
-- The **Read** action on **Certificates** with no conditions, because the alert sends details of certificates from every application. Editing an alert needs it too.
-- For a **Signer Certificate Expiration** alert, the **Admin** role instead, because the alert sends details of every signer's certificate, including signers you aren't a member of
+- The Certificate Manager **Admin** role to create or edit an alert, because it sends details of certificates from every application and every signer
- For Slack, PagerDuty, and webhook channels, the Enterprise plan. Email channels are available on every plan.
- For email alerts, recipients who are organization members, or addresses on one of your organization's [verified email domains](/documentation/platform/email-domain)
diff --git a/frontend/src/pages/cert-manager/ApplicationDetailsByIDPage/components/ApplicationSettingsTab.tsx b/frontend/src/pages/cert-manager/ApplicationDetailsByIDPage/components/ApplicationSettingsTab.tsx
index 5b9806b3f6..d7f6bc4edc 100644
--- a/frontend/src/pages/cert-manager/ApplicationDetailsByIDPage/components/ApplicationSettingsTab.tsx
+++ b/frontend/src/pages/cert-manager/ApplicationDetailsByIDPage/components/ApplicationSettingsTab.tsx
@@ -72,17 +72,17 @@ import {
useGetPkiApplicationPermissions
} from "@app/hooks/api/pkiApplications";
import { PolicyModal } from "@app/pages/cert-manager/ApprovalsPage/components/PolicyTab/components/PolicyModal";
+import { CertificateAlertsCard } from "@app/pages/cert-manager/components/CertificateAlerts/CertificateAlertsCard";
+import { CertificateAlertScopeKind } from "@app/pages/cert-manager/components/CertificateAlerts/types";
import { CreateProfileModal } from "@app/pages/cert-manager/PoliciesPage/components/CertificateProfilesTab/CreateProfileModal";
import { PkiDocsUrls } from "../../pki-docs-urls";
-import { ApplicationAlertsCard } from "./ApplicationAlerts/ApplicationAlertsCard";
-import { LegacyApplicationAlertsCard } from "./ApplicationAlerts/LegacyApplicationAlertsCard";
-import { CertificateAlertScopeKind } from "./ApplicationAlerts/types";
import {
ConfigureEnrollmentModal,
EnrollmentMethod,
METHOD_LABELS
} from "./ConfigureEnrollmentModal";
+import { LegacyApplicationAlertsCard } from "./LegacyApplicationAlertsCard";
type Props = { application: TPkiApplication; profiles: TPkiApplicationProfile[] };
@@ -619,7 +619,7 @@ export const ApplicationSettingsTab = ({ application, profiles }: Props) => {
</CardContent>
</Card>
- <ApplicationAlertsCard
+ <CertificateAlertsCard
projectId={application.projectId}
scope={{
kind: CertificateAlertScopeKind.Application,
diff --git a/frontend/src/pages/cert-manager/ApplicationDetailsByIDPage/components/ApplicationAlerts/LegacyApplicationAlertsCard.tsx b/frontend/src/pages/cert-manager/ApplicationDetailsByIDPage/components/LegacyApplicationAlertsCard.tsx
similarity index 98%
rename from frontend/src/pages/cert-manager/ApplicationDetailsByIDPage/components/ApplicationAlerts/LegacyApplicationAlertsCard.tsx
rename to frontend/src/pages/cert-manager/ApplicationDetailsByIDPage/components/LegacyApplicationAlertsCard.tsx
index e5caa96ff1..bc6f5be364 100644
--- a/frontend/src/pages/cert-manager/ApplicationDetailsByIDPage/components/ApplicationAlerts/LegacyApplicationAlertsCard.tsx
+++ b/frontend/src/pages/cert-manager/ApplicationDetailsByIDPage/components/LegacyApplicationAlertsCard.tsx
@@ -31,11 +31,10 @@ import {
useDeletePkiAlertV2,
useGetPkiAlertsV2
} from "@app/hooks/api/pkiAlertsV2";
+import { formatAlertBefore } from "@app/pages/cert-manager/components/CertificateAlerts/types";
import { ViewPkiAlertV2Modal } from "@app/views/PkiAlertsV2Page/components/ViewPkiAlertV2Modal";
import { formatEventType } from "@app/views/PkiAlertsV2Page/utils/pki-alert-formatters";
-import { formatAlertBefore } from "./types";
-
type LegacyAlertRowProps = {
alert: TPkiAlertV2;
onView: () => void;
diff --git a/frontend/src/pages/cert-manager/SettingsPage/components/AlertsTab.tsx b/frontend/src/pages/cert-manager/SettingsPage/components/AlertsTab.tsx
index 577f97118a..51e3fe3915 100644
--- a/frontend/src/pages/cert-manager/SettingsPage/components/AlertsTab.tsx
+++ b/frontend/src/pages/cert-manager/SettingsPage/components/AlertsTab.tsx
@@ -4,43 +4,23 @@ import {
useProject,
useProjectPermission
} from "@app/context";
-import { ProjectPermissionCertificateActions } from "@app/context/ProjectPermissionContext/types";
import { ProjectMembershipRole } from "@app/hooks/api/roles/types";
-
-import { ApplicationAlertsCard } from "../../ApplicationDetailsByIDPage/components/ApplicationAlerts/ApplicationAlertsCard";
-import {
- CertificateAlertAccess,
- CertificateAlertScopeKind,
- getEventTypesForAccess
-} from "../../ApplicationDetailsByIDPage/components/ApplicationAlerts/types";
+import { CertificateAlertsCard } from "@app/pages/cert-manager/components/CertificateAlerts/CertificateAlertsCard";
+import { CertificateAlertScopeKind } from "@app/pages/cert-manager/components/CertificateAlerts/types";
export const AlertsTab = () => {
const { currentProject } = useProject();
const { permission, hasProjectRole } = useProjectPermission();
-
- const isUnconditionalGrant = (rules: ReturnType<typeof permission.rulesFor>) =>
- rules.some((rule) => !rule.inverted && !rule.conditions) &&
- !rules.some((rule) => rule.inverted);
-
- const allowedEventTypes = getEventTypesForAccess([
- ...(isUnconditionalGrant(
- permission.rulesFor(
- ProjectPermissionCertificateActions.Read,
- ProjectPermissionSub.Certificates
- )
- )
- ? [CertificateAlertAccess.ReadAllCertificates]
- : []),
- ...(hasProjectRole(ProjectMembershipRole.Admin) ? [CertificateAlertAccess.Admin] : [])
- ]);
+ const isAdmin = hasProjectRole(ProjectMembershipRole.Admin);
return (
- <ApplicationAlertsCard
+ <CertificateAlertsCard
projectId={currentProject.id}
scope={{ kind: CertificateAlertScopeKind.CertificateManager }}
- allowedEventTypes={allowedEventTypes}
- canCreate={permission.can(ProjectPermissionActions.Create, ProjectPermissionSub.PkiAlerts)}
- canEdit={permission.can(ProjectPermissionActions.Edit, ProjectPermissionSub.PkiAlerts)}
+ canCreate={
+ isAdmin && permission.can(ProjectPermissionActions.Create, ProjectPermissionSub.PkiAlerts)
+ }
+ canEdit={isAdmin && permission.can(ProjectPermissionActions.Edit, ProjectPermissionSub.PkiAlerts)}
canDelete={permission.can(ProjectPermissionActions.Delete, ProjectPermissionSub.PkiAlerts)}
/>
);
diff --git a/frontend/src/pages/cert-manager/ApplicationDetailsByIDPage/components/ApplicationAlerts/CertificateAlertSheet.tsx b/frontend/src/pages/cert-manager/components/CertificateAlerts/CertificateAlertSheet.tsx
similarity index 100%
rename from frontend/src/pages/cert-manager/ApplicationDetailsByIDPage/components/ApplicationAlerts/CertificateAlertSheet.tsx
rename to frontend/src/pages/cert-manager/components/CertificateAlerts/CertificateAlertSheet.tsx
diff --git a/frontend/src/pages/cert-manager/ApplicationDetailsByIDPage/components/ApplicationAlerts/ApplicationAlertsCard.tsx b/frontend/src/pages/cert-manager/components/CertificateAlerts/CertificateAlertsCard.tsx
similarity index 94%
rename from frontend/src/pages/cert-manager/ApplicationDetailsByIDPage/components/ApplicationAlerts/ApplicationAlertsCard.tsx
rename to frontend/src/pages/cert-manager/components/CertificateAlerts/CertificateAlertsCard.tsx
index 32eab3c6db..87a931c411 100644
--- a/frontend/src/pages/cert-manager/ApplicationDetailsByIDPage/components/ApplicationAlerts/ApplicationAlertsCard.tsx
+++ b/frontend/src/pages/cert-manager/components/CertificateAlerts/CertificateAlertsCard.tsx
@@ -56,7 +56,7 @@ import {
useUpdateAlert
} from "@app/hooks/api/alerts";
-import { PkiDocsUrls } from "../../../pki-docs-urls";
+import { PkiDocsUrls } from "../../pki-docs-urls";
import { CertificateAlertSheet } from "./CertificateAlertSheet";
import {
CERTIFICATE_ALERT_EVENT_LABELS,
@@ -290,16 +290,14 @@ const AlertRow = ({
type Props = {
projectId: string;
scope: TCertificateAlertScope;
- allowedEventTypes?: CertificateAlertEventType[];
canCreate: boolean;
canEdit: boolean;
canDelete: boolean;
};
-export const ApplicationAlertsCard = ({
+export const CertificateAlertsCard = ({
projectId,
scope,
- allowedEventTypes,
canCreate,
canEdit,
canDelete
@@ -350,10 +348,7 @@ export const ApplicationAlertsCard = ({
scope.kind === CertificateAlertScopeKind.Application
? alerts.map((alert) => alert.eventType as CertificateAlertEventType)
: [];
- const isEventTypeAllowed = (eventType: string) =>
- !allowedEventTypes || allowedEventTypes.includes(eventType as CertificateAlertEventType);
- const creatableEventTypes = getScopeEventTypes(scope).filter(isEventTypeAllowed);
- const canCreateAny = canCreate && creatableEventTypes.length > 0;
+ const creatableEventTypes = getScopeEventTypes(scope);
const hasAllEventTypes = creatableEventTypes.every((eventType) =>
usedEventTypes.includes(eventType)
);
@@ -395,7 +390,7 @@ export const ApplicationAlertsCard = ({
<Button
variant="outline"
onClick={() => setAlertModal({ isOpen: true })}
- isDisabled={!canCreateAny || hasAllEventTypes}
+ isDisabled={!canCreate || hasAllEventTypes}
>
<PlusIcon />
Create Alert
@@ -404,16 +399,12 @@ export const ApplicationAlertsCard = ({
</TooltipTrigger>
{!canCreate && (
<TooltipContent side="left">
- You don&apos;t have permission to create alerts
+ {scope.kind === CertificateAlertScopeKind.CertificateManager
+ ? "Only Certificate Manager admins can create these alerts"
+ : "You don't have permission to create alerts"}
</TooltipContent>
)}
- {canCreate && !canCreateAny && (
- <TooltipContent side="left">
- Creating an alert requires permission to read all certificates, or the Admin role
- for signer alerts
- </TooltipContent>
- )}
- {canCreateAny && hasAllEventTypes && (
+ {canCreate && hasAllEventTypes && (
<TooltipContent side="left">
This application already has an alert for every alert type
</TooltipContent>
@@ -474,7 +465,7 @@ export const ApplicationAlertsCard = ({
onDelete={() =>
setDeleteAlertModal({ isOpen: true, alertId: a.id, name: a.name })
}
- canEdit={canEdit && isEventTypeAllowed(a.eventType)}
+ canEdit={canEdit}
canDelete={canDelete}
scope={scope}
/>
diff --git a/frontend/src/pages/cert-manager/ApplicationDetailsByIDPage/components/ApplicationAlerts/CertificateFilterSelects.tsx b/frontend/src/pages/cert-manager/components/CertificateAlerts/CertificateFilterSelects.tsx
similarity index 100%
rename from frontend/src/pages/cert-manager/ApplicationDetailsByIDPage/components/ApplicationAlerts/CertificateFilterSelects.tsx
rename to frontend/src/pages/cert-manager/components/CertificateAlerts/CertificateFilterSelects.tsx
diff --git a/frontend/src/pages/cert-manager/ApplicationDetailsByIDPage/components/ApplicationAlerts/ChannelsStep.tsx b/frontend/src/pages/cert-manager/components/CertificateAlerts/ChannelsStep.tsx
similarity index 100%
rename from frontend/src/pages/cert-manager/ApplicationDetailsByIDPage/components/ApplicationAlerts/ChannelsStep.tsx
rename to frontend/src/pages/cert-manager/components/CertificateAlerts/ChannelsStep.tsx
diff --git a/frontend/src/pages/cert-manager/ApplicationDetailsByIDPage/components/ApplicationAlerts/DetailsStep.tsx b/frontend/src/pages/cert-manager/components/CertificateAlerts/DetailsStep.tsx
similarity index 100%
rename from frontend/src/pages/cert-manager/ApplicationDetailsByIDPage/components/ApplicationAlerts/DetailsStep.tsx
rename to frontend/src/pages/cert-manager/components/CertificateAlerts/DetailsStep.tsx
diff --git a/frontend/src/pages/cert-manager/ApplicationDetailsByIDPage/components/ApplicationAlerts/FiltersStep.tsx b/frontend/src/pages/cert-manager/components/CertificateAlerts/FiltersStep.tsx
similarity index 100%
rename from frontend/src/pages/cert-manager/ApplicationDetailsByIDPage/components/ApplicationAlerts/FiltersStep.tsx
rename to frontend/src/pages/cert-manager/components/CertificateAlerts/FiltersStep.tsx
diff --git a/frontend/src/pages/cert-manager/ApplicationDetailsByIDPage/components/ApplicationAlerts/ReviewStep.tsx b/frontend/src/pages/cert-manager/components/CertificateAlerts/ReviewStep.tsx
similarity index 100%
rename from frontend/src/pages/cert-manager/ApplicationDetailsByIDPage/components/ApplicationAlerts/ReviewStep.tsx
rename to frontend/src/pages/cert-manager/components/CertificateAlerts/ReviewStep.tsx
diff --git a/frontend/src/pages/cert-manager/ApplicationDetailsByIDPage/components/ApplicationAlerts/types.ts b/frontend/src/pages/cert-manager/components/CertificateAlerts/types.ts
similarity index 96%
rename from frontend/src/pages/cert-manager/ApplicationDetailsByIDPage/components/ApplicationAlerts/types.ts
rename to frontend/src/pages/cert-manager/components/CertificateAlerts/types.ts
index b45adb5105..6d5c85b884 100644
--- a/frontend/src/pages/cert-manager/ApplicationDetailsByIDPage/components/ApplicationAlerts/types.ts
+++ b/frontend/src/pages/cert-manager/components/CertificateAlerts/types.ts
@@ -35,16 +35,10 @@ export const CERTIFICATE_ALERT_EVENT_LABELS: Record<CertificateAlertEventType, s
[CertificateAlertEventType.SignerCertificateExpiry]: "Signer Certificate Expiration"
};
-export enum CertificateAlertAccess {
- ReadAllCertificates = "read-all-certificates",
- Admin = "admin"
-}
-
const CERTIFICATE_ALERT_EVENT_GROUPS: {
label: string;
events: CertificateAlertEventType[];
scopes: CertificateAlertScopeKind[];
- requiredAccess: CertificateAlertAccess;
}[] = [
{
label: "Certificate Lifecycle",
@@ -54,22 +48,15 @@ const CERTIFICATE_ALERT_EVENT_GROUPS: {
CertificateAlertEventType.Renewal,
CertificateAlertEventType.Revocation
],
- scopes: [CertificateAlertScopeKind.Application, CertificateAlertScopeKind.CertificateManager],
- requiredAccess: CertificateAlertAccess.ReadAllCertificates
+ scopes: [CertificateAlertScopeKind.Application, CertificateAlertScopeKind.CertificateManager]
},
{
label: "Code Signing",
events: [CertificateAlertEventType.SignerCertificateExpiry],
- scopes: [CertificateAlertScopeKind.CertificateManager],
- requiredAccess: CertificateAlertAccess.Admin
+ scopes: [CertificateAlertScopeKind.CertificateManager]
}
];
-export const getEventTypesForAccess = (access: CertificateAlertAccess[]) =>
- CERTIFICATE_ALERT_EVENT_GROUPS.filter((group) => access.includes(group.requiredAccess)).flatMap(
- (group) => group.events
- );
-
export const getScopeEventGroups = (scope: TCertificateAlertScope) =>
CERTIFICATE_ALERT_EVENT_GROUPS.filter((group) => group.scopes.includes(scope.kind));