Skip to content

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

create audit log for triggers

Matheus Nogueirabd507bb3ce87
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 79f9119e7c..ea2abbdc12 100644
--- a/backend/src/ee/services/audit-log/audit-log-types.ts
+++ b/backend/src/ee/services/audit-log/audit-log-types.ts
@@ -822,7 +822,8 @@ export enum EventType {
// Honey Tokens
CREATE_HONEY_TOKEN = "create-honey-token",
UPDATE_HONEY_TOKEN = "update-honey-token",
- REVOKE_HONEY_TOKEN = "revoke-honey-token"
+ REVOKE_HONEY_TOKEN = "revoke-honey-token",
+ TRIGGER_HONEY_TOKEN = "trigger-honey-token"
}
// Maps each actor type to the JSONB key that holds the actor's primary ID in actorMetadata.
@@ -6563,6 +6564,20 @@ interface RevokeHoneyTokenEvent {
};
}
+interface TriggerHoneyTokenEvent {
+ type: EventType.TRIGGER_HONEY_TOKEN;
+ metadata: {
+ honeyTokenId: string;
+ name: string;
+ type: HoneyTokenType;
+ projectId: string;
+ eventName: string;
+ eventTime: string;
+ sourceIp: string;
+ awsRegion: string;
+ };
+}
+
export type Event =
| CreateSubOrganizationEvent
| UpdateSubOrganizationEvent
@@ -7145,6 +7160,7 @@ export type Event =
| CreateHoneyTokenEvent
| UpdateHoneyTokenEvent
| RevokeHoneyTokenEvent
+ | TriggerHoneyTokenEvent
| CreateGroupEvent
| UpdateGroupEvent
| DeleteGroupEvent
diff --git a/backend/src/ee/services/honey-token/honey-token-service.ts b/backend/src/ee/services/honey-token/honey-token-service.ts
index 71eb2d3922..51429f85ff 100644
--- a/backend/src/ee/services/honey-token/honey-token-service.ts
+++ b/backend/src/ee/services/honey-token/honey-token-service.ts
@@ -32,6 +32,7 @@ import { SmtpTemplates, TSmtpService } from "@app/services/smtp/smtp-service";
import { TTelemetryServiceFactory } from "@app/services/telemetry/telemetry-service";
import { PostHogEventTypes } from "@app/services/telemetry/telemetry-types";
+import { EventType, TAuditLogServiceFactory } from "../audit-log/audit-log-types";
import { THoneyTokenConfigDALFactory } from "../honey-token-config/honey-token-config-dal";
import { HoneyTokenConfigStatus } from "../honey-token-config/honey-token-config-enums";
import { TLicenseServiceFactory } from "../license/license-service";
@@ -109,6 +110,7 @@ export type THoneyTokenServiceFactoryDep = {
snapshotService: Pick<TSecretSnapshotServiceFactory, "performSnapshot">;
secretQueueService: Pick<TSecretQueueFactory, "syncSecrets" | "removeSecretReminder">;
telemetryService: Pick<TTelemetryServiceFactory, "sendPostHogEvents">;
+ auditLogService: Pick<TAuditLogServiceFactory, "createAuditLog">;
};
type TSendTriggerNotificationInput = {
@@ -150,7 +152,8 @@ export const honeyTokenServiceFactory = ({
resourceMetadataDAL,
snapshotService,
secretQueueService,
- telemetryService
+ telemetryService,
+ auditLogService
}: THoneyTokenServiceFactoryDep) => {
const honeyTokenProviderHooksByType = getHoneyTokenServiceHooksByType({
honeyTokenDAL,
@@ -174,7 +177,8 @@ export const honeyTokenServiceFactory = ({
resourceMetadataDAL,
snapshotService,
secretQueueService,
- telemetryService
+ telemetryService,
+ auditLogService
});
const create = async (
@@ -1020,11 +1024,17 @@ export const honeyTokenServiceFactory = ({
eventType: HoneyTokenEventType.AWS,
metadata: parsed.data
});
+
const updatedToken = await honeyTokenDAL.tryMarkTriggered(
parsed.data.accessKeyId,
TRIGGER_NOTIFICATION_COOLDOWN_MS
);
- void telemetryService
+
+ // This block only is executed once per token trigger. So, even if we get 100 events
+ // this will run only once.
+ if (updatedToken) {
+ void $sendTriggerNotification({ orgId: honeyTokenWithOrg.orgId, honeyToken, eventMetadata: parsed.data });
+ void telemetryService
.sendPostHogEvents({
event: PostHogEventTypes.HoneyTokenTriggered,
distinctId: `honey-token-${honeyToken.id}`,
@@ -1036,8 +1046,30 @@ export const honeyTokenServiceFactory = ({
}
})
.catch(() => {});
- if (updatedToken) {
- void $sendTriggerNotification({ orgId: honeyTokenWithOrg.orgId, honeyToken, eventMetadata: parsed.data });
+
+ void auditLogService
+ .createAuditLog({
+ actor: {
+ type: ActorType.UNKNOWN_USER,
+ metadata: {}
+ },
+ orgId: honeyTokenWithOrg.orgId,
+ projectId: honeyToken.projectId,
+ event: {
+ type: EventType.TRIGGER_HONEY_TOKEN,
+ metadata: {
+ honeyTokenId: honeyToken.id,
+ name: honeyToken.name,
+ type: honeyToken.type as HoneyTokenType,
+ projectId: honeyToken.projectId,
+ eventName: parsed.data.eventName,
+ eventTime: parsed.data.eventTime,
+ sourceIp: parsed.data.sourceIp ?? "Unknown",
+ awsRegion: parsed.data.awsRegion
+ }
+ }
+ })
+ .catch(() => {});
}
}
/* eslint-enable no-continue */
diff --git a/backend/src/server/routes/index.ts b/backend/src/server/routes/index.ts
index 65a8ad4b11..6dbc5b392f 100644
--- a/backend/src/server/routes/index.ts
+++ b/backend/src/server/routes/index.ts
@@ -2380,7 +2380,8 @@ export const registerRoutes = async (
snapshotService,
secretQueueService,
appConnectionService,
- telemetryService
+ telemetryService,
+ auditLogService
});
const webhookService = webhookServiceFactory({