Skip to content

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

refactor(audit-log): enhance getAuditLogMigrationStatus with permission checks and email alert logic

Victor Hugo dos Santos2b7a827b017e
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 3eff37f51a..42e6ef69ab 100644
--- a/backend/src/ee/services/audit-log/audit-log-service.ts
+++ b/backend/src/ee/services/audit-log/audit-log-service.ts
@@ -147,7 +147,23 @@ export const auditLogServiceFactory = ({
return auditLogQueue.pushToLog(el);
};
- const getAuditLogMigrationStatus = async () => {
+ const getAuditLogMigrationStatus: TAuditLogServiceFactory["getAuditLogMigrationStatus"] = async ({
+ actorAuthMethod,
+ actorId,
+ actorOrgId,
+ actor
+ }) => {
+ const { permission } = await permissionService.getOrgPermission({
+ scope: OrganizationActionScope.Any,
+ actor,
+ actorId,
+ orgId: actorOrgId,
+ actorAuthMethod,
+ actorOrgId
+ });
+
+ ForbiddenError.from(permission).throwUnlessCan(OrgPermissionAuditLogsActions.Read, OrgPermissionSubjects.AuditLogs);
+
const appCfg = getConfig();
const clickHouseConfigured = Boolean(appCfg.isClickHouseConfigured && appCfg.CLICKHOUSE_AUDIT_LOG_ENABLED);
const auditLogGenerationDisabled = Boolean(appCfg.DISABLE_AUDIT_LOG_GENERATION);
@@ -187,28 +203,31 @@ export const auditLogServiceFactory = ({
adminsOnly: true
});
+ if (superAdminsResult.users.length === 0) return;
+
const adminsWithEmail = superAdminsResult.users.filter((admin): admin is TUsers & { email: string } =>
Boolean(admin.email)
);
- if (adminsWithEmail.length === 0) return;
- const emailResults = await Promise.allSettled(
- adminsWithEmail.map((admin) =>
- smtpService.sendMail({
- // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
- template: SmtpTemplates.AuditLogMigrationAlert,
- subjectLine: "Action recommended: Optimize your audit log storage",
- recipients: [admin.email],
- substitutions: {
- siteUrl: appCfg.SITE_URL
- }
- })
- )
- );
+ if (adminsWithEmail.length > 0) {
+ const emailResults = await Promise.allSettled(
+ adminsWithEmail.map((admin) =>
+ smtpService.sendMail({
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
+ template: SmtpTemplates.AuditLogMigrationAlert,
+ subjectLine: "Action recommended: Optimize your audit log storage",
+ recipients: [admin.email],
+ substitutions: {
+ siteUrl: appCfg.SITE_URL
+ }
+ })
+ )
+ );
- const failedEmails = emailResults.filter((r) => r.status === "rejected");
- if (failedEmails.length > 0) {
- logger.error({ failedCount: failedEmails.length }, "Failed to send some audit log migration alert emails");
+ const failedEmails = emailResults.filter((r) => r.status === "rejected");
+ if (failedEmails.length > 0) {
+ logger.error({ failedCount: failedEmails.length }, "Failed to send some audit log migration alert emails");
+ }
}
const adminOrgMap = new Map<string, string>();
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 2aaf67f629..8a5ac898ba 100644
--- a/backend/src/ee/services/audit-log/audit-log-types.ts
+++ b/backend/src/ee/services/audit-log/audit-log-types.ts
@@ -28,7 +28,7 @@ import { SshCertTemplateStatus } from "@app/ee/services/ssh-certificate-template
import { TLoginMapping } from "@app/ee/services/ssh-host/ssh-host-types";
import { SymmetricKeyAlgorithm } from "@app/lib/crypto/cipher";
import { AsymmetricKeyAlgorithm, SigningAlgorithm } from "@app/lib/crypto/sign/types";
-import { TProjectPermission } from "@app/lib/types";
+import { TOrgPermission, TProjectPermission } from "@app/lib/types";
import { AppConnection } from "@app/services/app-connection/app-connection-enums";
import { TCreateAppConnectionDTO, TUpdateAppConnectionDTO } from "@app/services/app-connection/app-connection-types";
import { ActorType } from "@app/services/auth/auth-type";
@@ -117,7 +117,7 @@ export type TAuditLogServiceFactory = {
projectName?: string | null | undefined;
}[]
>;
- getAuditLogMigrationStatus: () => Promise<{
+ getAuditLogMigrationStatus: (arg: TOrgPermission) => Promise<{
clickHouseConfigured: boolean;
auditLogGenerationDisabled: boolean;
auditLogStorageDisabled: boolean;
diff --git a/backend/src/server/routes/v1/organization-router.ts b/backend/src/server/routes/v1/organization-router.ts
index 414697bdf9..cd8c426ef5 100644
--- a/backend/src/server/routes/v1/organization-router.ts
+++ b/backend/src/server/routes/v1/organization-router.ts
@@ -278,8 +278,14 @@ export const registerOrgRouter = async (server: FastifyZodProvider) => {
}
},
onRequest: verifyAuth([AuthMode.JWT, AuthMode.IDENTITY_ACCESS_TOKEN]),
- handler: async () => {
- return server.services.auditLog.getAuditLogMigrationStatus();
+ handler: async (req) => {
+ return server.services.auditLog.getAuditLogMigrationStatus({
+ actor: req.permission.type,
+ actorId: req.permission.id,
+ actorAuthMethod: req.permission.authMethod,
+ actorOrgId: req.permission.orgId,
+ orgId: req.permission.orgId
+ });
}
});
diff --git a/frontend/src/pages/organization/AuditLogsPage/components/LogsSection.tsx b/frontend/src/pages/organization/AuditLogsPage/components/LogsSection.tsx
index c678fb6059..758a31b488 100644
--- a/frontend/src/pages/organization/AuditLogsPage/components/LogsSection.tsx
+++ b/frontend/src/pages/organization/AuditLogsPage/components/LogsSection.tsx
@@ -198,20 +198,29 @@ const LogsSectionComponent = ({
return (
<div className="space-y-2">
{showClickHouseWarning && (
- <UnstableAlert variant="info">
+ <UnstableAlert variant="warning">
<UnstableAlertDescription>
<p>
- Your audit log table is growing large. PostgreSQL performance will degrade over time
- at this scale. Consider configuring{" "}
+ Your audit log volume is growing. To keep searches fast and reduce database load, we
+ recommend streaming logs to an{" "}
<a
- href="https://infisical.com/docs/documentation/platform/audit-logs-clickhouse-setup"
+ href="https://infisical.com/docs/documentation/platform/audit-log-streams/audit-log-streams"
target="_blank"
rel="noopener noreferrer"
className="underline underline-offset-2 hover:opacity-80"
>
- ClickHouse
+ external destination
</a>{" "}
- as your audit log storage backend to maintain query performance.
+ like Splunk or using the built-in{" "}
+ <a
+ href="https://infisical.com/docs/documentation/platform/audit-logs-clickhouse-setup"
+ target="_blank"
+ rel="noopener noreferrer"
+ className="underline underline-offset-2 hover:opacity-80"
+ >
+ ClickHouse integration
+ </a>
+ .
</p>
</UnstableAlertDescription>
</UnstableAlert>