Skip to content

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

feat: changed audit log pushing to only push to one source

=0f57aa7285ad
diff --git a/backend/src/ee/services/audit-log/audit-log-queue.ts b/backend/src/ee/services/audit-log/audit-log-queue.ts
index f8a775d639..9c81a9e729 100644
--- a/backend/src/ee/services/audit-log/audit-log-queue.ts
+++ b/backend/src/ee/services/audit-log/audit-log-queue.ts
@@ -98,47 +98,38 @@ export const auditLogQueueServiceFactory = async ({
const id = randomUUID();
const eventMetadata = normalizeJsonPayload(event.metadata);
const actorMetadata = normalizeJsonPayload(actor.metadata);
- const auditLog = await auditLogDAL.create({
- // @ts-expect-error: id is added from our side to make it easier for us to correlate between the database and the stream
+
+ const createdAt = new Date(job.timestamp);
+ const auditLog = {
id,
actor: actor.type,
actorMetadata,
- userAgent,
- projectId,
- projectName: project?.name,
- ipAddress,
- orgId,
+ ipAddress: ipAddress ?? "",
eventType: event.type,
- expiresAt: new Date(Date.now() + ttl),
eventMetadata,
- userAgentType
- });
- await auditLogStreamService.streamLog(orgId, auditLog);
+ userAgent: userAgent ?? "",
+ userAgentType: userAgentType ?? "",
+ projectId: projectId ?? "",
+ orgId,
+ expiresAt: new Date(createdAt.getTime() + ttl),
+ createdAt,
+ updatedAt: createdAt
+ };
- const createdAt = new Date(job.timestamp);
// Push to Redis stream for ClickHouse batch processing
if (isClickHouseBatchEnabled) {
try {
await keyStore.streamAdd(AUDIT_LOG_CLICKHOUSE_STREAM_KEY, "*", {
- data: JSON.stringify({
- id,
- actor: actor.type,
- actorMetadata,
- ipAddress: ipAddress ?? "",
- eventType: event.type,
- eventMetadata,
- userAgent: userAgent ?? "",
- userAgentType: userAgentType ?? "",
- projectId: projectId ?? "",
- orgId,
- expiresAt: new Date(createdAt.getTime() + ttl),
- createdAt
- })
+ data: JSON.stringify(auditLog)
});
} catch (error) {
logger.error(error, "Failed to push audit log to Redis stream for ClickHouse batch");
}
+ } else {
+ await auditLogDAL.create(auditLog);
}
+
+ await auditLogStreamService.streamLog(orgId, auditLog);
}
});
diff --git a/backend/src/ee/services/audit-log/audit-log-service.ts b/backend/src/ee/services/audit-log/audit-log-service.ts
index 4d93f211d6..7b0870243e 100644
--- a/backend/src/ee/services/audit-log/audit-log-service.ts
+++ b/backend/src/ee/services/audit-log/audit-log-service.ts
@@ -67,7 +67,7 @@ export const auditLogServiceFactory = ({
}
const appCfg = getConfig();
- const useClickHouse = appCfg.CLICKHOUSE_AUDIT_LOG_QUERY_ENABLED && clickhouseAuditLogDAL;
+ const useClickHouse = appCfg.CLICKHOUSE_AUDIT_LOG_ENABLED && clickhouseAuditLogDAL;
const findArgs = {
startDate: filter.startDate,
@@ -98,7 +98,7 @@ export const auditLogServiceFactory = ({
return auditLogs.map(({ eventType: logEventType, actor: eActor, actorMetadata, eventMetadata, ...el }) => ({
...el,
updatedAt: el.createdAt,
- expiresAt: null as Date | null,
+ expiresAt: el.expiresAt,
event: { type: logEventType, metadata: eventMetadata },
actor: { type: eActor, metadata: actorMetadata }
}));