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
add support for clickhouse
adilson1c1517ff9049
diff --git a/backend/src/ee/services/audit-log/audit-log-clickhouse-dal.ts b/backend/src/ee/services/audit-log/audit-log-clickhouse-dal.tsindex a11141db50..bb7e391813 100644--- a/backend/src/ee/services/audit-log/audit-log-clickhouse-dal.ts+++ b/backend/src/ee/services/audit-log/audit-log-clickhouse-dal.ts@@ -208,5 +208,38 @@ export const clickhouseAuditLogDALFactory = (clickhouseClient: ClickHouseClient,}};- return { find };+ const findById = async (+ id: string,+ orgId: string+ ): Promise<{ id: string; orgId: string; projectId: string | null } | null> => {+ const query = `+ SELECT id, orgId, projectId+ FROM ${tableName}+ WHERE id = {id:UUID} AND orgId = {orgId:UUID}+ LIMIT 1+ `;++ try {+ const result = await clickhouseClient.query({+ query,+ query_params: { id, orgId },+ format: "JSONEachRow"+ });++ const rows = await result.json<{ id: string; orgId: string; projectId: string }>();+ if (rows.length === 0) return null;++ const row = rows[0];+ return {+ id: row.id,+ orgId: row.orgId,+ projectId: row.projectId || null+ };+ } catch (error) {+ logger.error(error, "Failed to find audit log by id from ClickHouse");+ throw new DatabaseError({ error });+ }+ };++ return { find, findById };};diff --git a/backend/src/ee/services/audit-log/audit-log-service.ts b/backend/src/ee/services/audit-log/audit-log-service.tsindex 7cb96c9757..f3212cd9bf 100644--- a/backend/src/ee/services/audit-log/audit-log-service.ts+++ b/backend/src/ee/services/audit-log/audit-log-service.ts@@ -209,7 +209,13 @@ export const auditLogServiceFactory = ({auditLogId,auditLogInfo}) => {- const row = await auditLogDAL.findById(auditLogId);+ const appCfg = getConfig();+ const useClickHouse = appCfg.CLICKHOUSE_AUDIT_LOG_ENABLED && clickhouseAuditLogDAL;++ const row = useClickHouse+ ? await clickhouseAuditLogDAL.findById(auditLogId, actorOrgId)+ : await auditLogDAL.findById(auditLogId);+if (!row || row.orgId !== actorOrgId) {throw new NotFoundError({ message: "Audit log not found" });}diff --git a/backend/src/server/routes/v1/organization-router.ts b/backend/src/server/routes/v1/organization-router.tsindex c07a27b0cd..e6db0803e7 100644--- a/backend/src/server/routes/v1/organization-router.ts+++ b/backend/src/server/routes/v1/organization-router.ts@@ -240,18 +240,6 @@ export const registerOrgRouter = async (server: FastifyZodProvider) => {},onRequest: verifyAuth([AuthMode.JWT, AuthMode.IDENTITY_ACCESS_TOKEN]),handler: async (req) => {- if (req.query.offset === 0) {- await server.services.auditLog.createAuditLog({- ...req.auditLogInfo,- orgId: req.permission.orgId,- projectId: req.query.projectId,- event: {- type: EventType.VIEW_AUDIT_LOGS,- metadata: {}- }- });- }-const auditLogs = await server.services.auditLog.listAuditLogs({filter: {...req.query,@@ -268,6 +256,18 @@ export const registerOrgRouter = async (server: FastifyZodProvider) => {actor: req.permission.type});+ if (req.query.offset === 0) {+ await server.services.auditLog.createAuditLog({+ ...req.auditLogInfo,+ orgId: req.permission.orgId,+ projectId: req.query.projectId,+ event: {+ type: EventType.VIEW_AUDIT_LOGS,+ metadata: {}+ }+ });+ }+return { auditLogs };}});@@ -305,7 +305,7 @@ export const registerOrgRouter = async (server: FastifyZodProvider) => {server.route({method: "POST",- url: "/audit-logs/:auditLogId/track-view",+ url: "/audit-logs/:auditLogId/track-log-details-view",config: {rateLimit: writeLimit},diff --git a/frontend/src/hooks/api/auditLogs/mutations.tsx b/frontend/src/hooks/api/auditLogs/mutations.tsxindex e42ebcc873..887b4238b9 100644--- a/frontend/src/hooks/api/auditLogs/mutations.tsx+++ b/frontend/src/hooks/api/auditLogs/mutations.tsx@@ -8,7 +8,7 @@ export const useTrackAuditLogView = () =>useMutation({mutationFn: async ({ auditLogId }: TrackAuditLogViewInput) => {const { data } = await apiRequest.post<{ tracked: boolean }>(- `/api/v1/organization/audit-logs/${auditLogId}/track-view`+ `/api/v1/organization/audit-logs/${auditLogId}/track-log-details-view`);return data;}