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
feat(alerts): record resource name in alert audit events
Carlos Monastyrskibff2675ffde1
diff --git a/backend/CLAUDE.md b/backend/CLAUDE.mdindex 7b8331d38c..2c0beea4fa 100644--- a/backend/CLAUDE.md+++ b/backend/CLAUDE.md@@ -755,7 +755,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 `sourceEvent: { resourceType, eventKey }`; the consumer then runs the source resource's alerts plus the resource-less alerts of every event sourced from it (`alertProviderRegistry.findEventsBySource`), each under its own `eventType`. Certificate Manager-wide (`cert-manager`) and signer (`cert-manager.signer`) alerts are scope-wide providers, and creating or editing either requires the project Admin role, since PKI permissions are admin or member, not granular. **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. `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. Audit logs are not a provider hook: every alert, whatever its resource type, logs the generic `create-alert`, `update-alert`, `delete-alert` and `test-alert-channel` events (`getAuditEvent` in `alert-service.ts`), which carry `resourceType` so admins can tell them apart. Do not add per-provider audit event types. 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 `sourceEvent: { resourceType, eventKey }`; the consumer then runs the source resource's alerts plus the resource-less alerts of every event sourced from it (`alertProviderRegistry.findEventsBySource`), each under its own `eventType`. Certificate Manager-wide (`cert-manager`) and signer (`cert-manager.signer`) alerts are scope-wide providers, and creating or editing either requires the project Admin role, since PKI permissions are admin or member, not granular. **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. `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. Audit logs are not a provider hook: every alert, whatever its resource type, logs the generic `create-alert`, `update-alert`, `delete-alert` and `test-alert-channel` events (`getAuditEvent` in `alert-service.ts`), which carry `resourceType`, `resourceId` and `resourceName` (from `getResourceNames`, so a provider with resource-bound alerts must implement it) so admins can tell them apart. Do not add per-provider audit event types. 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. For dedup windows shorter than the scan interval (daily reminders), also order least-recently-notified first. `scanExpiringCertificates` (`cert-manager-expiring-certificates-fns.ts`) does both.diff --git a/backend/src/ee/services/audit-log/audit-log-types.ts b/backend/src/ee/services/audit-log/audit-log-types.tsindex 1f950fc685..1fff0a3e52 100644--- a/backend/src/ee/services/audit-log/audit-log-types.ts+++ b/backend/src/ee/services/audit-log/audit-log-types.ts@@ -7983,6 +7983,7 @@ interface CreateAlertEvent {name: string;resourceType: string;resourceId?: string | null;+ resourceName?: string | null;eventType: string;};}@@ -7993,6 +7994,8 @@ interface UpdateAlertEvent {alertId: string;name: string;resourceType: string;+ resourceId?: string | null;+ resourceName?: string | null;eventType: string;};}@@ -8003,6 +8006,8 @@ interface DeleteAlertEvent {alertId: string;name: string;resourceType: string;+ resourceId?: string | null;+ resourceName?: string | null;eventType: string;};}@@ -8014,6 +8019,7 @@ interface TestAlertChannelEvent {channelType: string;resourceType: string;resourceId?: string | null;+ resourceName?: string | null;success: boolean;deliveredTo?: number;error?: string;diff --git a/backend/src/server/routes/v1/alert-router.ts b/backend/src/server/routes/v1/alert-router.tsindex c4a8035fe9..dd12a83e2b 100644--- a/backend/src/server/routes/v1/alert-router.ts+++ b/backend/src/server/routes/v1/alert-router.ts@@ -140,7 +140,7 @@ export const registerAlertRouter = async (server: FastifyZodProvider) => {},onRequest: verifyAuth([AuthMode.JWT, AuthMode.IDENTITY_ACCESS_TOKEN, AuthMode.OAUTH]),handler: async (req) => {- const { projectId, ...result } = await server.services.alertChannelTest.testChannel({+ const { projectId, resourceName, ...result } = await server.services.alertChannelTest.testChannel({...req.body,actor: req.permission.type,actorId: req.permission.id,@@ -156,6 +156,7 @@ export const registerAlertRouter = async (server: FastifyZodProvider) => {test: {resourceType: req.body.resourceType,resourceId: req.body.resourceId,+ resourceName,channelId: req.body.channelId,channelType: req.body.channelType,success: result.success,diff --git a/backend/src/services/alert/alert-channel-test-service.test.ts b/backend/src/services/alert/alert-channel-test-service.test.tsindex c0a355bc4f..b7cee9368a 100644--- a/backend/src/services/alert/alert-channel-test-service.test.ts+++ b/backend/src/services/alert/alert-channel-test-service.test.ts@@ -205,7 +205,8 @@ describe("alertChannelTestService", () => {expect(result).toEqual({success: true,deliveredTo: 1,- projectId: null+ projectId: null,+ resourceName: null});expect(sent).toHaveLength(1);expect(sent[0].config).toEqual({ webhookUrl: "https://hooks.slack.com/services/T/B/x" });@@ -465,7 +466,8 @@ describe("alertChannelTestService", () => {await expect(service.testChannel(dto)).resolves.toEqual({success: true,deliveredTo: 1,- projectId: null+ projectId: null,+ resourceName: null});await expect(service.testChannel(dto)).rejects.toThrow(/Try again in 60s/);} finally {@@ -499,7 +501,8 @@ describe("alertChannelTestService", () => {).resolves.toEqual({success: true,deliveredTo: 1,- projectId: null+ projectId: null,+ resourceName: null});} finally {restoreSlack();@@ -526,7 +529,8 @@ describe("alertChannelTestService", () => {expect(result).toEqual({success: false,error: "connect ECONNREFUSED",- projectId: null+ projectId: null,+ resourceName: null});} finally {restore();diff --git a/backend/src/services/alert/alert-channel-test-service.ts b/backend/src/services/alert/alert-channel-test-service.tsindex 8191e3b436..aedb53cfca 100644--- a/backend/src/services/alert/alert-channel-test-service.ts+++ b/backend/src/services/alert/alert-channel-test-service.ts@@ -15,7 +15,7 @@ import { TAlertChannelServiceFactory } from "./alert-channel-service";import { TAlertChannelDeps, TAlertRecipient } from "./alert-channel-types";import { TAlertDALFactory } from "./alert-dal";import { getRecipientScope } from "./alert-principal-scope-fns";-import { resolveAlertProjectId, TAlertProviderRegistry } from "./alert-provider-registry";+import { getAlertResourceName, resolveAlertProjectId, TAlertProviderRegistry } from "./alert-provider-registry";import { TAlertRecipientResolver } from "./alert-recipient-resolver";import { TTestAlertChannelDTO, TTestAlertChannelResponse, TTestAlertChannelResult } from "./alert-service-types";import { buildTestAlertPayload } from "./alert-test-payload-fns";@@ -237,7 +237,8 @@ export const alertChannelTestServiceFactory = ({const config = await $resolveConfig(dto, projectId);const result = await $sendTest(dto, projectId, provider, config);- return { ...result, projectId };+ const resourceName = await getAlertResourceName(provider, dto.actorOrgId, dto.resourceId);+ return { ...result, projectId, resourceName };};return { testChannel };diff --git a/backend/src/services/alert/alert-service-types.ts b/backend/src/services/alert/alert-service-types.tsindex 2422157ae6..0bdb8fb916 100644--- a/backend/src/services/alert/alert-service-types.ts+++ b/backend/src/services/alert/alert-service-types.ts@@ -57,6 +57,7 @@ export type TTestAlertChannelResponse = {export type TTestAlertChannelResult = TTestAlertChannelResponse & {projectId: string | null;+ resourceName: string | null;};export type TAlertResponse = {diff --git a/backend/src/services/alert/alert-service.test.ts b/backend/src/services/alert/alert-service.test.tsindex e0c101f834..7fb5bd8355 100644--- a/backend/src/services/alert/alert-service.test.ts+++ b/backend/src/services/alert/alert-service.test.ts@@ -334,6 +334,7 @@ describe("alert service", () => {name: "expiry",resourceType: RESOURCE_TYPE,resourceId: "resource-1",+ resourceName: "Resource One",eventType: "test.resource.expiration"};@@ -344,6 +345,7 @@ describe("alert service", () => {name: "expiry",resourceType: RESOURCE_TYPE,resourceId: "resource-1",+ resourceName: "Resource One",eventType: "test.resource.expiration"}});@@ -353,6 +355,8 @@ describe("alert service", () => {alertId: "alert-1",name: "expiry",resourceType: RESOURCE_TYPE,+ resourceId: "resource-1",+ resourceName: "Resource One",eventType: "test.resource.expiration"}});@@ -362,6 +366,8 @@ describe("alert service", () => {alertId: "alert-1",name: "expiry",resourceType: RESOURCE_TYPE,+ resourceId: "resource-1",+ resourceName: "Resource One",eventType: "test.resource.expiration"}});@@ -377,6 +383,7 @@ describe("alert service", () => {channelType: "slack",resourceType: RESOURCE_TYPE,resourceId: "resource-1",+ resourceName: null,success: true,deliveredTo: undefined,error: undefineddiff --git a/backend/src/services/alert/alert-service.ts b/backend/src/services/alert/alert-service.tsindex a987eabee1..029b41f2f6 100644--- a/backend/src/services/alert/alert-service.ts+++ b/backend/src/services/alert/alert-service.ts@@ -108,6 +108,7 @@ const getAuditEvent = (input: TAlertAuditInput): TAuditEvent => {channelType: test.channelType,resourceType: test.resourceType,resourceId: test.resourceId,+ resourceName: test.resourceName ?? null,success: test.success,deliveredTo: test.deliveredTo,error: test.error@@ -119,11 +120,11 @@ const getAuditEvent = (input: TAlertAuditInput): TAuditEvent => {alertId: alert.id,name: alert.name,resourceType: alert.resourceType,+ resourceId: alert.resourceId,+ resourceName: alert.resourceName ?? null,eventType: alert.eventType};- if (input.action === AlertAuditAction.Create) {- return { type: EventType.CREATE_ALERT, metadata: { ...metadata, resourceId: alert.resourceId } };- }+ if (input.action === AlertAuditAction.Create) return { type: EventType.CREATE_ALERT, metadata };if (input.action === AlertAuditAction.Update) return { type: EventType.UPDATE_ALERT, metadata };return { type: EventType.DELETE_ALERT, metadata };};diff --git a/backend/src/services/alert/alert-types.ts b/backend/src/services/alert/alert-types.tsindex 061edbd816..48755ef3ed 100644--- a/backend/src/services/alert/alert-types.ts+++ b/backend/src/services/alert/alert-types.ts@@ -140,12 +140,14 @@ type TAlertAuditAlert = {name: string;resourceType: string;resourceId: string | null;+ resourceName?: string | null;eventType: string;};type TAlertChannelTestAudit = {resourceType: string;resourceId?: string | null;+ resourceName?: string | null;channelId?: string;channelType: string;success: boolean;diff --git a/backend/src/services/alert/providers/identity-credential-alert-provider.ts b/backend/src/services/alert/providers/identity-credential-alert-provider.tsindex 0b342dc7f9..d9acfe9e10 100644--- a/backend/src/services/alert/providers/identity-credential-alert-provider.ts+++ b/backend/src/services/alert/providers/identity-credential-alert-provider.ts@@ -526,6 +526,13 @@ export const identityCredentialAlertProviderFactory = ({);},assertPermission,- assertResourceInScope+ assertResourceInScope,+ getResourceNames: async ({ orgId, resourceIds }) =>+ new Map(+ (await identityCredentialAlertDAL.findIdentitiesByIds(resourceIds, orgId)).map((identity) => [+ identity.id,+ identity.name+ ])+ )};};diff --git a/backend/src/services/alert/providers/secret-reminder-alert-provider.ts b/backend/src/services/alert/providers/secret-reminder-alert-provider.tsindex 1a9aef1667..45b166c567 100644--- a/backend/src/services/alert/providers/secret-reminder-alert-provider.ts+++ b/backend/src/services/alert/providers/secret-reminder-alert-provider.ts@@ -237,6 +237,12 @@ export const secretReminderAlertProviderFactory = ({buildPayload,targetId: (target) => `${target.secretId}:${target.occurrenceDate}`,assertPermission,- assertResourceInScope+ assertResourceInScope,+ getResourceNames: async ({ orgId, resourceIds }) =>+ new Map(+ (await secretReminderAlertDAL.findSecretsByIds(resourceIds))+ .filter((secret) => secret.orgId === orgId)+ .map((secret) => [secret.secretId, secret.secretKey])+ )};};