Skip to content

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

add audit logs

Thiago Araujo da Silva189de309f372
diff --git a/backend/src/ee/services/audit-log/audit-log-types.ts b/backend/src/ee/services/audit-log/audit-log-types.ts
index bc2a0f4534..173f0fc209 100644
--- a/backend/src/ee/services/audit-log/audit-log-types.ts
+++ b/backend/src/ee/services/audit-log/audit-log-types.ts
@@ -932,7 +932,12 @@ export enum EventType {
// Project Grants
CREATE_PROJECT_FOLDER_GRANT = "create-project-folder-grant",
- DELETE_PROJECT_FOLDER_GRANT = "delete-project-folder-grant"
+ DELETE_PROJECT_FOLDER_GRANT = "delete-project-folder-grant",
+
+ // Alerts
+ CREATE_ALERT = "create-alert",
+ UPDATE_ALERT = "update-alert",
+ DELETE_ALERT = "delete-alert"
}
// Maps each actor type to the JSONB key that holds the actor's primary ID in actorMetadata.
@@ -7455,7 +7460,41 @@ interface DeleteProjectFolderGrantEvent {
};
}
+interface CreateAlertEvent {
+ type: EventType.CREATE_ALERT;
+ metadata: {
+ alertId: string;
+ name: string;
+ resourceType: string;
+ resourceId?: string | null;
+ eventType: string;
+ };
+}
+
+interface UpdateAlertEvent {
+ type: EventType.UPDATE_ALERT;
+ metadata: {
+ alertId: string;
+ name: string;
+ resourceType: string;
+ eventType: string;
+ };
+}
+
+interface DeleteAlertEvent {
+ type: EventType.DELETE_ALERT;
+ metadata: {
+ alertId: string;
+ name: string;
+ resourceType: string;
+ eventType: string;
+ };
+}
+
export type Event =
+ | CreateAlertEvent
+ | UpdateAlertEvent
+ | DeleteAlertEvent
| CreateSubOrganizationEvent
| UpdateSubOrganizationEvent
| DeleteSubOrganizationEvent
diff --git a/backend/src/server/routes/v1/alert-router.ts b/backend/src/server/routes/v1/alert-router.ts
index b1b2ee6542..d61f9e81a0 100644
--- a/backend/src/server/routes/v1/alert-router.ts
+++ b/backend/src/server/routes/v1/alert-router.ts
@@ -1,5 +1,6 @@
import { z } from "zod";
+import { EventType } from "@app/ee/services/audit-log/audit-log-types";
import { readLimit, writeLimit } from "@app/server/config/rateLimiter";
import { verifyAuth } from "@app/server/plugins/auth/verify-auth";
import { AlertChannelType } from "@app/services/alert/alert-channel-types";
@@ -87,6 +88,22 @@ export const registerAlertRouter = async (server: FastifyZodProvider) => {
actorAuthMethod: req.permission.authMethod,
actorOrgId: req.permission.orgId
});
+
+ await server.services.auditLog.createAuditLog({
+ ...req.auditLogInfo,
+ ...(alert.projectId ? { projectId: alert.projectId } : { orgId: alert.orgId }),
+ event: {
+ type: EventType.CREATE_ALERT,
+ metadata: {
+ alertId: alert.id,
+ name: alert.name,
+ resourceType: alert.resourceType,
+ resourceId: alert.resourceId,
+ eventType: alert.eventType
+ }
+ }
+ });
+
return { alert };
}
});
@@ -169,6 +186,21 @@ export const registerAlertRouter = async (server: FastifyZodProvider) => {
actorAuthMethod: req.permission.authMethod,
actorOrgId: req.permission.orgId
});
+
+ await server.services.auditLog.createAuditLog({
+ ...req.auditLogInfo,
+ ...(alert.projectId ? { projectId: alert.projectId } : { orgId: alert.orgId }),
+ event: {
+ type: EventType.UPDATE_ALERT,
+ metadata: {
+ alertId: alert.id,
+ name: alert.name,
+ resourceType: alert.resourceType,
+ eventType: alert.eventType
+ }
+ }
+ });
+
return { alert };
}
});
@@ -191,6 +223,21 @@ export const registerAlertRouter = async (server: FastifyZodProvider) => {
actorAuthMethod: req.permission.authMethod,
actorOrgId: req.permission.orgId
});
+
+ await server.services.auditLog.createAuditLog({
+ ...req.auditLogInfo,
+ ...(alert.projectId ? { projectId: alert.projectId } : { orgId: alert.orgId }),
+ event: {
+ type: EventType.DELETE_ALERT,
+ metadata: {
+ alertId: alert.id,
+ name: alert.name,
+ resourceType: alert.resourceType,
+ eventType: alert.eventType
+ }
+ }
+ });
+
return { alert };
}
});
diff --git a/backend/src/services/alert/alert-service.ts b/backend/src/services/alert/alert-service.ts
index 1cd2511c1a..fbf18b5349 100644
--- a/backend/src/services/alert/alert-service.ts
+++ b/backend/src/services/alert/alert-service.ts
@@ -361,7 +361,16 @@ export const alertServiceFactory = ({
return $assembleResponse(updated, channels);
};
- const deleteAlert = async (dto: TDeleteAlertDTO): Promise<{ id: string }> => {
+ const deleteAlert = async (
+ dto: TDeleteAlertDTO
+ ): Promise<{
+ id: string;
+ name: string;
+ resourceType: string;
+ eventType: string;
+ orgId: string;
+ projectId: string | null;
+ }> => {
const alert = await alertDAL.findActiveById(dto.alertId);
if (!alert) throw new NotFoundError({ message: `Alert with ID '${dto.alertId}' not found` });
@@ -382,7 +391,14 @@ export const alertServiceFactory = ({
await alertDAL.deleteById(alert.id, tx);
});
- return { id: alert.id };
+ return {
+ id: alert.id,
+ name: alert.name,
+ resourceType: alert.resourceType,
+ eventType: alert.eventType,
+ orgId: alert.orgId,
+ projectId: alert.projectId ?? null
+ };
};
const deleteAlertsForResource = async (