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 audit logs on the import endpoint
adilson2f3f73a6e8f9
diff --git a/backend/src/ee/services/audit-log/audit-log-types.ts b/backend/src/ee/services/audit-log/audit-log-types.tsindex 5301ca3c1a..6b074adae0 100644--- a/backend/src/ee/services/audit-log/audit-log-types.ts+++ b/backend/src/ee/services/audit-log/audit-log-types.ts@@ -35,6 +35,7 @@ import { ActorType } from "@app/services/auth/auth-type";import { CertExtendedKeyUsage, CertKeyAlgorithm, CertKeyUsage } from "@app/services/certificate/certificate-types";import { CaStatus } from "@app/services/certificate-authority/certificate-authority-enums";import { CertificateRenewalKeySource, TRenewalAuditChange } from "@app/services/certificate-v3/certificate-v3-types";+import type { ExternalMigrationImportStatus } from "@app/services/external-migration/external-migration-types";import { TIdentityTrustedIp } from "@app/services/identity/identity-types";import {TAWSAuthDetails,@@ -846,6 +847,7 @@ export enum EventType {EXTERNAL_MIGRATION_CREATE = "external-migration-create",EXTERNAL_MIGRATION_UPDATE = "external-migration-update",EXTERNAL_MIGRATION_DELETE = "external-migration-delete",+ IMPORT_VAULT_SECRETS = "import-vault-secrets",// OAuth 2.0 authorization server clientsCREATE_OAUTH_CLIENT = "create-oauth-client",@@ -6818,6 +6820,23 @@ interface ExternalMigrationDeleteEvent {provider: string;};}++interface ImportVaultSecretsEvent {+ type: EventType.IMPORT_VAULT_SECRETS;+ metadata: {+ environment: string;+ secretPath: string;+ vaultNamespace: string;+ vaultSecretPaths: string[];+ connectionId: string;+ keepVaultStructure: boolean;+ status: ExternalMigrationImportStatus;+ importedSecretCount: number;+ approvalRequiredSecretCount: number;+ importedPaths?: string[];+ approvalRequiredPaths?: string[];+ };+}interface CreateOauthClientEvent {type: EventType.CREATE_OAUTH_CLIENT;metadata: {@@ -7833,6 +7852,7 @@ export type Event =| ExternalMigrationCreateEvent| ExternalMigrationUpdateEvent| ExternalMigrationDeleteEvent+ | ImportVaultSecretsEvent| CreateOauthClientEvent| UpdateOauthClientEvent| DeleteOauthClientEventdiff --git a/backend/src/server/routes/v3/external-migration-router.ts b/backend/src/server/routes/v3/external-migration-router.tsindex b85780b3f4..805aa4d2b3 100644--- a/backend/src/server/routes/v3/external-migration-router.ts+++ b/backend/src/server/routes/v3/external-migration-router.ts@@ -1,6 +1,7 @@import fastifyMultipart from "@fastify/multipart";import { z } from "zod";+import { EventType } from "@app/ee/services/audit-log/audit-log-types";import { BadRequestError } from "@app/lib/errors";import { readLimit, writeLimit } from "@app/server/config/rateLimiter";import { getTelemetryDistinctId } from "@app/server/lib/telemetry";@@ -303,7 +304,26 @@ export const registerExternalMigrationRouter = async (server: FastifyZodProvider...req.body});- // TODO: add audit log+ await server.services.auditLog.createAuditLog({+ projectId: req.body.projectId,+ ...req.auditLogInfo,+ event: {+ type: EventType.IMPORT_VAULT_SECRETS,+ metadata: {+ environment: req.body.environment,+ secretPath: req.body.secretPath,+ vaultNamespace: req.body.vaultNamespace,+ vaultSecretPaths: req.body.vaultSecretPaths,+ connectionId: req.body.connectionId,+ keepVaultStructure: req.body.keepVaultStructure,+ status: result.status,+ importedSecretCount: result.importedSecretCount,+ approvalRequiredSecretCount: result.approvalRequiredSecretCount,+ importedPaths: result.importedPaths,+ approvalRequiredPaths: result.approvalRequiredPaths+ }+ }+ });return result;}diff --git a/backend/src/services/external-migration/external-migration-service.ts b/backend/src/services/external-migration/external-migration-service.tsindex ca0c18ae54..ffe76ba498 100644--- a/backend/src/services/external-migration/external-migration-service.ts+++ b/backend/src/services/external-migration/external-migration-service.ts@@ -656,7 +656,9 @@ export const externalMigrationServiceFactory = ({? ExternalMigrationImportStatus.ApprovalRequired: ExternalMigrationImportStatus.Imported,importedPaths: writtenResults.map(({ folderPath }) => folderPath),- approvalRequiredPaths: approvedResults.map(({ folderPath }) => folderPath)+ approvalRequiredPaths: approvedResults.map(({ folderPath }) => folderPath),+ importedSecretCount: writtenResults.reduce((count, { secrets }) => count + secrets.length, 0),+ approvalRequiredSecretCount: approvedResults.reduce((count, { secrets }) => count + secrets.length, 0)};};@@ -776,10 +778,18 @@ export const externalMigrationServiceFactory = ({}});- return { status: ExternalMigrationImportStatus.ApprovalRequired };+ return {+ status: ExternalMigrationImportStatus.ApprovalRequired,+ importedSecretCount: 0,+ approvalRequiredSecretCount: Object.keys(vaultSecrets).length+ };}- return { status: ExternalMigrationImportStatus.Imported };+ return {+ status: ExternalMigrationImportStatus.Imported,+ importedSecretCount: Object.keys(vaultSecrets).length,+ approvalRequiredSecretCount: 0+ };} catch (error) {throw new BadRequestError({message: `Failed to import Vault secrets. ${error instanceof Error ? error.message : "Unknown error"}`diff --git a/frontend/src/hooks/api/auditLogs/constants.tsx b/frontend/src/hooks/api/auditLogs/constants.tsxindex c873899893..349ed9b34b 100644--- a/frontend/src/hooks/api/auditLogs/constants.tsx+++ b/frontend/src/hooks/api/auditLogs/constants.tsx@@ -429,6 +429,7 @@ export const eventToNameMap: { [K in EventType]: string } = {[EventType.EXTERNAL_MIGRATION_CREATE]: "Create External Migration",[EventType.EXTERNAL_MIGRATION_UPDATE]: "Update External Migration",[EventType.EXTERNAL_MIGRATION_DELETE]: "Delete External Migration",+ [EventType.IMPORT_VAULT_SECRETS]: "Import Vault secrets",[EventType.GATEWAY_CREATE]: "Create gateway",[EventType.GATEWAY_ENROLL]: "Enroll gateway (legacy)",[EventType.GATEWAY_ENROLLMENT_TOKEN_CREATE]: "Generate gateway enrollment token",diff --git a/frontend/src/hooks/api/auditLogs/enums.tsx b/frontend/src/hooks/api/auditLogs/enums.tsxindex 2abe4658a1..2f23d1c11d 100644--- a/frontend/src/hooks/api/auditLogs/enums.tsx+++ b/frontend/src/hooks/api/auditLogs/enums.tsx@@ -422,6 +422,7 @@ export enum EventType {EXTERNAL_MIGRATION_CREATE = "external-migration-create",EXTERNAL_MIGRATION_UPDATE = "external-migration-update",EXTERNAL_MIGRATION_DELETE = "external-migration-delete",+ IMPORT_VAULT_SECRETS = "import-vault-secrets",// GatewayGATEWAY_CREATE = "gateway-create",