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 log
Thiago Araujo da Silva05128a1b0fff
diff --git a/backend/src/ee/services/audit-log/audit-log-types.ts b/backend/src/ee/services/audit-log/audit-log-types.tsindex 2179d4b357..2efbfcfcaf 100644--- a/backend/src/ee/services/audit-log/audit-log-types.ts+++ b/backend/src/ee/services/audit-log/audit-log-types.ts@@ -556,6 +556,8 @@ export enum EventType {GET_APP_CONNECTION_USAGE = "get-app-connection-usage",MIGRATE_APP_CONNECTION = "migrate-app-connection",ROTATE_APP_CONNECTION_CREDENTIALS = "rotate-app-connection-credentials",+ CREATE_GITHUB_APP = "create-github-app",+ DELETE_GITHUB_APP = "delete-github-app",CREATE_SHARED_SECRET = "create-shared-secret",CREATE_SECRET_REQUEST = "create-secret-request",DELETE_SHARED_SECRET = "delete-shared-secret",@@ -4472,6 +4474,29 @@ interface RotateAppConnectionCredentialsEvent {};}+interface CreateGitHubAppEvent {+ type: EventType.CREATE_GITHUB_APP;+ metadata: {+ gitHubAppId: string;+ name: string;+ appId: string;+ slug: string;+ owner?: string | null;+ host?: string | null;+ instanceType: string;+ };+}++interface DeleteGitHubAppEvent {+ type: EventType.DELETE_GITHUB_APP;+ metadata: {+ gitHubAppId: string;+ name: string;+ appId: string;+ slug: string;+ };+}+interface CreateSharedSecretEvent {type: EventType.CREATE_SHARED_SECRET;metadata: {@@ -7602,6 +7627,8 @@ export type Event =| GetAppConnectionUsageEvent| MigrateAppConnectionEvent| RotateAppConnectionCredentialsEvent+ | CreateGitHubAppEvent+ | DeleteGitHubAppEvent| GetSshHostGroupEvent| CreateSshHostGroupEvent| UpdateSshHostGroupEventdiff --git a/backend/src/server/routes/index.ts b/backend/src/server/routes/index.tsindex c39568105d..5be3249ef8 100644--- a/backend/src/server/routes/index.ts+++ b/backend/src/server/routes/index.ts@@ -1657,7 +1657,9 @@ export const registerRoutes = async (gatewayService,gatewayV2Service,gatewayDAL,- gatewayV2DAL+ gatewayV2DAL,+ auditLogService,+ userDAL});const secretSyncQueue = secretSyncQueueFactory({diff --git a/backend/src/server/routes/v1/github-app-router.ts b/backend/src/server/routes/v1/github-app-router.tsindex 8550a2d9d1..8fd925a3f0 100644--- a/backend/src/server/routes/v1/github-app-router.ts+++ b/backend/src/server/routes/v1/github-app-router.ts@@ -1,5 +1,6 @@import { z } from "zod";+import { EventType } from "@app/ee/services/audit-log/audit-log-types";import { readLimit, writeLimit } from "@app/server/config/rateLimiter";import { verifyAuth } from "@app/server/plugins/auth/verify-auth";import { AuthMode } from "@app/services/auth/auth-type";@@ -58,7 +59,12 @@ export const registerGitHubAppRouter = async (server: FastifyZodProvider) => {handler: async (req, reply) => {const { redirectUrl } = await server.services.gitHubApp.handleManifestCallback({code: req.query.code,- state: req.query.state+ state: req.query.state,+ auditLogInfo: {+ ipAddress: req.auditLogInfo.ipAddress,+ userAgent: req.auditLogInfo.userAgent,+ userAgentType: req.auditLogInfo.userAgentType+ }});return reply.redirect(redirectUrl);@@ -155,6 +161,20 @@ export const registerGitHubAppRouter = async (server: FastifyZodProvider) => {id: req.params.id});+ await server.services.auditLog.createAuditLog({+ ...req.auditLogInfo,+ orgId: req.permission.orgId,+ event: {+ type: EventType.DELETE_GITHUB_APP,+ metadata: {+ gitHubAppId: req.params.id,+ name: gitHubApp.name,+ appId: gitHubApp.appId,+ slug: gitHubApp.slug+ }+ }+ });+return { gitHubApp };}});diff --git a/backend/src/services/github-app/github-app-service.ts b/backend/src/services/github-app/github-app-service.tsindex f8d025d215..ea1816fde8 100644--- a/backend/src/services/github-app/github-app-service.ts+++ b/backend/src/services/github-app/github-app-service.ts@@ -2,6 +2,7 @@ import { ForbiddenError } from "@casl/ability";import { AxiosError, AxiosRequestConfig, AxiosResponse } from "axios";import { ActionProjectType, OrganizationActionScope } from "@app/db/schemas";+import { EventType, TAuditLogServiceFactory } from "@app/ee/services/audit-log/audit-log-types";import { TGatewayDALFactory } from "@app/ee/services/gateway/gateway-dal";import { TGatewayServiceFactory } from "@app/ee/services/gateway/gateway-service";import { TGatewayV2DALFactory } from "@app/ee/services/gateway-v2/gateway-v2-dal";@@ -41,6 +42,7 @@ import {import { ActorAuthMethod, ActorType } from "@app/services/auth/auth-type";import { TKmsServiceFactory } from "@app/services/kms/kms-service";import { KmsDataKey } from "@app/services/kms/kms-types";+import { TUserDALFactory } from "@app/services/user/user-dal";import { TGitHubAppDALFactory } from "./github-app-dal";import {@@ -48,6 +50,7 @@ import {TGitHubAppInstallation,TGitHubAppManifestResponse,TGitHubManifestStatePayload,+ THandleManifestCallbackDTO,TInitiateGitHubManifestDTO,TListGitHubAppsDTO,TResolveGitHubAppInstallationsDTO,@@ -64,6 +67,8 @@ type TGitHubAppServiceFactoryDep = {gatewayV2Service: Pick<TGatewayV2ServiceFactory, "getPlatformConnectionDetailsByGatewayId">;gatewayDAL: Pick<TGatewayDALFactory, "find">;gatewayV2DAL: Pick<TGatewayV2DALFactory, "find">;+ auditLogService: Pick<TAuditLogServiceFactory, "createAuditLog">;+ userDAL: Pick<TUserDALFactory, "findById">;};export type TGitHubAppServiceFactory = ReturnType<typeof gitHubAppServiceFactory>;@@ -77,7 +82,9 @@ export const gitHubAppServiceFactory = ({gatewayService,gatewayV2Service,gatewayDAL,- gatewayV2DAL+ gatewayV2DAL,+ auditLogService,+ userDAL}: TGitHubAppServiceFactoryDep) => {const listGitHubApps = async ({ orgPermission }: TListGitHubAppsDTO): Promise<TSanitizedGitHubApp[]> => {const { permission } = await permissionService.getOrgPermission({@@ -363,7 +370,7 @@ export const gitHubAppServiceFactory = ({return { state: stateToken, manifest, githubActionUrl };};- const handleManifestCallback = async ({ code, state }: { code: string; state: string }) => {+ const handleManifestCallback = async ({ code, state, auditLogInfo }: THandleManifestCallbackDTO) => {const { AUTH_SECRET, SITE_URL } = getConfig();if (!SITE_URL) {@@ -496,6 +503,40 @@ export const gitHubAppServiceFactory = ({throw err;}+ // The callback route is unauthenticated (GitHub redirects the browser here) — the actor is+ // carried in the signed state token. Manifest initiation is JWT-only, so the actor is a user.+ const actorUser = actorType === ActorType.USER ? await userDAL.findById(actorId) : null;+ await auditLogService.createAuditLog({+ ...auditLogInfo,+ orgId,+ actor: actorUser+ ? {+ type: ActorType.USER,+ metadata: {+ userId: actorUser.id,+ email: actorUser.email,+ username: actorUser.username,+ ...(authMethod ? { authMethod } : {})+ }+ }+ : {+ type: ActorType.UNKNOWN_USER,+ metadata: {}+ },+ event: {+ type: EventType.CREATE_GITHUB_APP,+ metadata: {+ gitHubAppId: created.id,+ name: created.name,+ appId: created.appId,+ slug: created.slug,+ owner: created.owner,+ host: created.host,+ instanceType+ }+ }+ });+const callbackUrl = new URL(`${SITE_URL}/organizations/${orgId}/app-connections/github/manifest/callback`);callbackUrl.searchParams.set("gitHubAppId", created.id ?? "");callbackUrl.searchParams.set("slug", created.slug);diff --git a/backend/src/services/github-app/github-app-types.ts b/backend/src/services/github-app/github-app-types.tsindex eb62993eca..72f966e707 100644--- a/backend/src/services/github-app/github-app-types.ts+++ b/backend/src/services/github-app/github-app-types.ts@@ -1,5 +1,6 @@import { z } from "zod";+import { AuditLogInfo } from "@app/ee/services/audit-log/audit-log-types";import { OrgServiceActor } from "@app/lib/types";export type TInitiateGitHubManifestDTO = {@@ -24,6 +25,12 @@ export type TGitHubManifestStatePayload = {installState: string;};+export type THandleManifestCallbackDTO = {+ code: string;+ state: string;+ auditLogInfo: Pick<AuditLogInfo, "ipAddress" | "userAgent" | "userAgentType">;+};+export type TListGitHubAppsDTO = {orgPermission: OrgServiceActor;};diff --git a/frontend/src/hooks/api/auditLogs/constants.tsx b/frontend/src/hooks/api/auditLogs/constants.tsxindex b969caba01..501bdaa7ab 100644--- a/frontend/src/hooks/api/auditLogs/constants.tsx+++ b/frontend/src/hooks/api/auditLogs/constants.tsx@@ -169,6 +169,8 @@ export const eventToNameMap: { [K in EventType]: string } = {[EventType.DELETE_APP_CONNECTION]: "Delete App Connection",[EventType.GET_APP_CONNECTION_USAGE]: "Get App Connection Usage",[EventType.MIGRATE_APP_CONNECTION]: "Migrate App Connection",+ [EventType.CREATE_GITHUB_APP]: "Create GitHub App",+ [EventType.DELETE_GITHUB_APP]: "Delete GitHub App",[EventType.GET_SECRET_SYNCS]: "List secret syncs",[EventType.GET_SECRET_SYNC]: "Get Secret Sync",[EventType.CREATE_SECRET_SYNC]: "Create Secret Sync",diff --git a/frontend/src/hooks/api/auditLogs/enums.tsx b/frontend/src/hooks/api/auditLogs/enums.tsxindex 49dcd625d0..e54e9ec1e8 100644--- a/frontend/src/hooks/api/auditLogs/enums.tsx+++ b/frontend/src/hooks/api/auditLogs/enums.tsx@@ -179,6 +179,8 @@ export enum EventType {DELETE_APP_CONNECTION = "delete-app-connection",GET_APP_CONNECTION_USAGE = "get-app-connection-usage",MIGRATE_APP_CONNECTION = "migrate-app-connection",+ CREATE_GITHUB_APP = "create-github-app",+ DELETE_GITHUB_APP = "delete-github-app",GET_SECRET_SYNCS = "get-secret-syncs",GET_SECRET_SYNC = "get-secret-sync",CREATE_SECRET_SYNC = "create-secret-sync",