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
refactor(audit-log): simplify event handling and remove unused encryption events
Victor Hugo dos Santos40ca21b90c0c
diff --git a/backend/src/ee/services/audit-log/audit-log-service.ts b/backend/src/ee/services/audit-log/audit-log-service.tsindex 22e388b30f..e986a30cb3 100644--- a/backend/src/ee/services/audit-log/audit-log-service.ts+++ b/backend/src/ee/services/audit-log/audit-log-service.ts@@ -156,17 +156,8 @@ export const auditLogServiceFactory = ({if (appCfg.DISABLE_AUDIT_LOG_GENERATION) {return;}- // Events with no inherent scope. Logins have no org context yet; instance root-key rotation is- // instance-level, and req.permission.orgId is only guaranteed for machine identities, so requiring a- // scope here would let the audit write fail an operation that has already happened.- const SCOPELESS_EVENTS: EventType[] = [- EventType.LOGIN_IDENTITY_UNIVERSAL_AUTH,- EventType.GET_ENCRYPTION_STATUS,- EventType.CREATE_ENCRYPTION_KEY_ROTATION,- EventType.DELETE_ENCRYPTION_KEY_ROTATION,- EventType.COMPLETE_ENCRYPTION_KEY_ROTATION- ];- if (!SCOPELESS_EVENTS.includes(data.event.type)) {+ // Events that don't require projectId or orgId (login events where org context may not be available)+ if (data.event.type !== EventType.LOGIN_IDENTITY_UNIVERSAL_AUTH) {if (!data.projectId && !data.orgId)throw new BadRequestError({ message: "Must specify either project id or org id" });}diff --git a/backend/src/ee/services/audit-log/audit-log-types.ts b/backend/src/ee/services/audit-log/audit-log-types.tsindex 6326074e81..f37c8b8473 100644--- a/backend/src/ee/services/audit-log/audit-log-types.ts+++ b/backend/src/ee/services/audit-log/audit-log-types.ts@@ -891,13 +891,7 @@ export enum EventType {CREATE_ALERT = "create-alert",UPDATE_ALERT = "update-alert",DELETE_ALERT = "delete-alert",- TEST_ALERT_CHANNEL = "test-alert-channel",-- // Instance root encryption key rotation- GET_ENCRYPTION_STATUS = "get-encryption-status",- CREATE_ENCRYPTION_KEY_ROTATION = "create-encryption-key-rotation",- DELETE_ENCRYPTION_KEY_ROTATION = "delete-encryption-key-rotation",- COMPLETE_ENCRYPTION_KEY_ROTATION = "complete-encryption-key-rotation"+ TEST_ALERT_CHANNEL = "test-alert-channel"}// Maps each actor type to the JSONB key that holds the actor's primary ID in actorMetadata.@@ -7099,40 +7093,6 @@ interface TestAlertChannelEvent {};}-interface GetEncryptionStatusEvent {- type: EventType.GET_ENCRYPTION_STATUS;- metadata: {- activeFingerprint: string | null;- hasPendingRotation: boolean;- hasRetainedKey: boolean;- };-}--interface CreateEncryptionKeyRotationEvent {- type: EventType.CREATE_ENCRYPTION_KEY_ROTATION;- metadata: {- rotationId: string;- fingerprint: string;- supersededPending: boolean;- };-}--interface DeleteEncryptionKeyRotationEvent {- type: EventType.DELETE_ENCRYPTION_KEY_ROTATION;- metadata: {- rotationId: string;- fingerprint: string | null;- };-}--interface CompleteEncryptionKeyRotationEvent {- type: EventType.COMPLETE_ENCRYPTION_KEY_ROTATION;- metadata: {- retainedKeyId: string;- retiredFingerprint: string | null;- };-}-export type Event =| CreateAlertEvent| UpdateAlertEvent@@ -7764,8 +7724,4 @@ export type Event =| UpdateGroupProjectMembershipEvent| RemoveGroupFromProjectEvent| CreateProjectFolderGrantEvent- | DeleteProjectFolderGrantEvent- | GetEncryptionStatusEvent- | CreateEncryptionKeyRotationEvent- | DeleteEncryptionKeyRotationEvent- | CompleteEncryptionKeyRotationEvent;+ | DeleteProjectFolderGrantEvent;diff --git a/backend/src/server/routes/v1/admin-router.ts b/backend/src/server/routes/v1/admin-router.tsindex 86a5344aa1..89274550be 100644--- a/backend/src/server/routes/v1/admin-router.ts+++ b/backend/src/server/routes/v1/admin-router.ts@@ -8,7 +8,6 @@ import {OrgMembershipsSchema,OrgMembershipStatus} from "@app/db/schemas";-import { EventType } from "@app/ee/services/audit-log/audit-log-types";import { getLicenseKeyConfig } from "@app/ee/services/license/license-fns";import { LicenseType } from "@app/ee/services/license/license-types";import { ENCRYPTION_KEY_ROTATION } from "@app/lib/api-docs";@@ -31,7 +30,7 @@ import { getServerCfg } from "@app/services/super-admin/super-admin-service";import { CacheType, LoginMethod } from "@app/services/super-admin/super-admin-types";import { PostHogEventTypes } from "@app/services/telemetry/telemetry-types";-import { SanitizedUserSchema } from "../sanitizedSchemas";+import { booleanSchema, SanitizedUserSchema } from "../sanitizedSchemas";const SuperAdminSchema = SanitizedUserSchema.extend({superAdmin: z.boolean().optional().nullable()@@ -689,21 +688,9 @@ export const registerAdminRouter = async (server: FastifyZodProvider) => {verifySuperAdmin(req, res, done);});},- handler: async (req) => {+ handler: async () => {const status = await server.services.encryptionKeyRotation.getStatus();- await server.services.auditLog.createAuditLog({- ...req.auditLogInfo,- event: {- type: EventType.GET_ENCRYPTION_STATUS,- metadata: {- activeFingerprint: status.activeFingerprint,- hasPendingRotation: Boolean(status.pendingRotation),- hasRetainedKey: Boolean(status.retainedKey)- }- }- });-return { status };}});@@ -718,7 +705,7 @@ export const registerAdminRouter = async (server: FastifyZodProvider) => {operationId: "createAdminEncryptionKeyRotation",description: ENCRYPTION_KEY_ROTATION.CREATE.description,querystring: z.object({- supersede: z.coerce.boolean().default(false).describe(ENCRYPTION_KEY_ROTATION.CREATE.supersede)+ supersede: booleanSchema.default(false).describe(ENCRYPTION_KEY_ROTATION.CREATE.supersede)}),response: {201: z.object({@@ -744,19 +731,6 @@ export const registerAdminRouter = async (server: FastifyZodProvider) => {supersede: req.query.supersede});- // Fingerprint only. The key itself is in the response body and must reach no other sink.- await server.services.auditLog.createAuditLog({- ...req.auditLogInfo,- event: {- type: EventType.CREATE_ENCRYPTION_KEY_ROTATION,- metadata: {- rotationId: rotation.id,- fingerprint: rotation.fingerprint,- supersededPending: req.query.supersede- }- }- });-// The key appears here and nowhere else, so it must not be cached along the way.void res.header("Cache-Control", "no-store");void res.status(201);@@ -783,15 +757,7 @@ export const registerAdminRouter = async (server: FastifyZodProvider) => {});},handler: async (req, res) => {- const { fingerprint } = await server.services.encryptionKeyRotation.discardRotation(req.params.rotationId);-- await server.services.auditLog.createAuditLog({- ...req.auditLogInfo,- event: {- type: EventType.DELETE_ENCRYPTION_KEY_ROTATION,- metadata: { rotationId: req.params.rotationId, fingerprint }- }- });+ await server.services.encryptionKeyRotation.discardRotation(req.params.rotationId);void res.status(204);}@@ -824,19 +790,11 @@ export const registerAdminRouter = async (server: FastifyZodProvider) => {});},handler: async (req, res) => {- const { retiredFingerprint } = await server.services.encryptionKeyRotation.completeRotation({+ await server.services.encryptionKeyRotation.completeRotation({rotationId: req.params.rotationId,acknowledged: req.body?.acknowledged});- await server.services.auditLog.createAuditLog({- ...req.auditLogInfo,- event: {- type: EventType.COMPLETE_ENCRYPTION_KEY_ROTATION,- metadata: { retainedKeyId: req.params.rotationId, retiredFingerprint }- }- });-void res.status(204);}});diff --git a/backend/src/services/encryption-key-rotation/encryption-key-rotation-service.ts b/backend/src/services/encryption-key-rotation/encryption-key-rotation-service.tsindex 90b921af7a..b2417e06a0 100644--- a/backend/src/services/encryption-key-rotation/encryption-key-rotation-service.ts+++ b/backend/src/services/encryption-key-rotation/encryption-key-rotation-service.ts@@ -225,7 +225,6 @@ export const encryptionKeyRotationServiceFactory = ({logger.info(`Encryption key rotation discarded [rotationId=${rotationId}] [fingerprint=${row.kekFingerprint ?? "unknown"}]`);- return { fingerprint: row.kekFingerprint ?? null };});};@@ -264,8 +263,9 @@ export const encryptionKeyRotationServiceFactory = ({});}- logger.info(`Encryption key rotation completed, previous key removed [retainedKeyId=${rotationId}]`);- return { retiredFingerprint: row.kekFingerprint ?? null };+ logger.info(+ `Encryption key rotation completed, previous key removed [retainedKeyId=${rotationId}] [fingerprint=${row.kekFingerprint ?? "unknown"}]`+ );});};@@ -284,7 +284,10 @@ export const encryptionKeyRotationServiceFactory = ({if (!current || current.activatedAt) return false;return Boolean(await kmsRootConfigDAL.deleteById(row.id, tx));});- if (removed) logger.info(`Discarded an encryption key rotation that was never applied [rotationId=${row.id}]`);+ if (removed)+ logger.info(+ `Discarded an encryption key rotation that was never applied [rotationId=${row.id}] [fingerprint=${row.kekFingerprint ?? "unknown"}]`+ );}if (!retained.length) return;@@ -311,7 +314,10 @@ export const encryptionKeyRotationServiceFactory = ({if (!current || !current.supersededAt) return false;return $retireRetainedKey(tx, current);});- if (removed) logger.info(`Removed a superseded encryption key [retainedKeyId=${row.id}]`);+ if (removed)+ logger.info(+ `Removed a superseded encryption key [retainedKeyId=${row.id}] [fingerprint=${row.kekFingerprint ?? "unknown"}]`+ );}const kept = retained.filter((row) => !eligible.includes(row) && row.lastResolvedAt);diff --git a/backend/src/services/kms/kms-root-config-dal.ts b/backend/src/services/kms/kms-root-config-dal.tsindex f4316433ba..54f6a24100 100644--- a/backend/src/services/kms/kms-root-config-dal.ts+++ b/backend/src/services/kms/kms-root-config-dal.ts@@ -44,7 +44,6 @@ export const kmsRootConfigDALFactory = (db: TDbClient) => {}};- /** Newest first; the GC relies on that ordering. */const findRetained = async (tx?: Knex) => {try {return await (tx || db)(TableName.KmsServerRootConfig)