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
settings to each scope
Thiago Araujo da Silva86e8fa2fe3c9
diff --git a/backend/CLAUDE.md b/backend/CLAUDE.mdindex 2d448c580d..3fa35c223a 100644--- a/backend/CLAUDE.md+++ b/backend/CLAUDE.md@@ -1004,10 +1004,12 @@ fails if a type lands in two lists. Reads, lists, dashboards, insights views, CMand the dynamic secret lease lifecycle are data access; VIEW_AUDIT_LOGS and privileged sessionlifecycle are management on purpose.-Any class can be turned off per org, and a project row overrides the org in either direction. The rows live in-`audit_log_settings` (one per scope and class, `projectId` null for the org scope; no row means-the default in `AUDIT_LOG_EVENT_CLASS_DEFAULTS`: data access on, authorization off) behind `audit-log-settings-service.ts`, which caches the org's whole picture in the-keystore for 60s (`getEffectiveSettings`, never throws: a lookup failure records everything).+Any class can be turned off per scope, and scopes do not inherit: an org (root or sub-org) has its own+rows for org-level events, each project has its own rows for its events, and a scope without a row uses+the default in `AUDIT_LOG_EVENT_CLASS_DEFAULTS` (data access on, authorization off). The rows live in+`audit_log_settings` (one per scope and class, `projectId` null for the org scope) behind+`audit-log-settings-service.ts`, which caches the org's rows and all of its projects' rows in the+keystore for 5 minutes (`getEffectiveSettings`, never throws: a lookup failure records everything).Enforcement happens in `buildStreamEntry` in `audit-log-queue.ts`, memoized per request so abatch of events costs one settings read. Suppressed events are dropped silently and do notcount on the dropped counter.diff --git a/backend/src/ee/services/audit-log/audit-log-queue.test.ts b/backend/src/ee/services/audit-log/audit-log-queue.test.tsindex c2184a2c2e..cea82ab268 100644--- a/backend/src/ee/services/audit-log/audit-log-queue.test.ts+++ b/backend/src/ee/services/audit-log/audit-log-queue.test.ts@@ -288,18 +288,15 @@ describe("audit-log-queue event class settings", () => {expect(keyStore.streamAdd).toHaveBeenCalledTimes(1);});- test("a project setting overrides the org in both directions", async () => {+ test("a project event uses the project's own setting, never the org's", async () => {const { service, keyStore, auditLogSettingsService } = await createHarness();auditLogSettingsService.getEffectiveSettings.mockResolvedValue(- settings({ org: { "data-access": false }, projects: { "p-on": { "data-access": true } } })+ settings({ org: { "data-access": false }, projects: { "p-off": { "data-access": false } } }));- await service.pushToLog(dto({ projectId: "p-on", event: { type: "get-secrets", metadata: {} } }) as never);+ await service.pushToLog(dto({ projectId: "p-none", event: { type: "get-secrets", metadata: {} } }) as never);expect(keyStore.streamAdd).toHaveBeenCalledTimes(1);- auditLogSettingsService.getEffectiveSettings.mockResolvedValue(- settings({ org: {}, projects: { "p-off": { "data-access": false } } })- );await service.pushToLog(dto({ projectId: "p-off", event: { type: "get-secrets", metadata: {} } }) as never);expect(keyStore.streamAdd).toHaveBeenCalledTimes(1);});diff --git a/backend/src/ee/services/audit-log/audit-log-service.test.ts b/backend/src/ee/services/audit-log/audit-log-service.test.tsindex 7cda904aa0..2c29ab40da 100644--- a/backend/src/ee/services/audit-log/audit-log-service.test.ts+++ b/backend/src/ee/services/audit-log/audit-log-service.test.ts@@ -60,8 +60,8 @@ const createHarness = ({ windowAcquired = true, storedCount = "0" } = {}) => {const auditLogQueue = { pushToLog: vi.fn<(data: TPushedLog) => Promise<void>>(async () => undefined) };const auditLogSettingsService = {getEffectiveSettings: vi.fn<(orgId: string) => Promise<TEffectiveAuditLogSettings>>(async () => ({- org: { [AuditLogEventClass.Authorization]: true },- projects: {},+ org: {},+ projects: { "project-1": { [AuditLogEventClass.Authorization]: true } },shouldUseNewPrivilegeSystem: true}))};@@ -138,8 +138,8 @@ describe("recordPermissionDenied", () => {test("nothing is recorded when the authorization class is off", async () => {const { service, keyStore, auditLogQueue, auditLogSettingsService } = createHarness();auditLogSettingsService.getEffectiveSettings.mockResolvedValueOnce({- org: { [AuditLogEventClass.Authorization]: false },- projects: {},+ org: {},+ projects: { "project-1": { [AuditLogEventClass.Authorization]: false } },shouldUseNewPrivilegeSystem: true});diff --git a/backend/src/ee/services/audit-log/audit-log-settings-service.test.ts b/backend/src/ee/services/audit-log/audit-log-settings-service.test.tsnew file mode 100644index 0000000000..957e285dc4--- /dev/null+++ b/backend/src/ee/services/audit-log/audit-log-settings-service.test.ts@@ -0,0 +1,96 @@+import { beforeEach, describe, expect, test, vi } from "vitest";++import { AuditLogEventClass } from "./audit-log-event-classes";+import { auditLogSettingsServiceFactory, isAuditLogEventClassEnabled } from "./audit-log-settings-service";+import { TEffectiveAuditLogSettings } from "./audit-log-settings-types";++vi.mock("@app/lib/logger", () => ({+ logger: { info: vi.fn(), warn: vi.fn(), error: vi.fn(), debug: vi.fn() }+}));++const settings = (overrides: Partial<TEffectiveAuditLogSettings> = {}): TEffectiveAuditLogSettings => ({+ org: {},+ projects: {},+ shouldUseNewPrivilegeSystem: true,+ ...overrides+});++describe("isAuditLogEventClassEnabled", () => {+ const eventClass = AuditLogEventClass.DataAccess;++ test("a project uses its own row or the default, never the org's row", () => {+ expect(isAuditLogEventClassEnabled(settings({ org: { [eventClass]: false } }), eventClass, "p1")).toBe(true);+ expect(isAuditLogEventClassEnabled(settings({ projects: { p1: { [eventClass]: false } } }), eventClass, "p1")).toBe(+ false+ );+ });++ test("an org-scoped event uses the org's row or the default", () => {+ expect(isAuditLogEventClassEnabled(settings(), eventClass)).toBe(true);+ expect(isAuditLogEventClassEnabled(settings({ org: { [eventClass]: false } }), eventClass)).toBe(false);+ expect(isAuditLogEventClassEnabled(settings(), AuditLogEventClass.Authorization)).toBe(false);+ });++ test("records everything when the lookup failed", () => {+ expect(isAuditLogEventClassEnabled(null, AuditLogEventClass.Authorization)).toBe(true);+ });+});++type TRow = { orgId: string; projectId: string | null; eventClass: string; isEnabled: boolean };++const createHarness = ({ rows = [] as TRow[] } = {}) => {+ const orgDAL = {+ findById: vi.fn(async (id: string) => ({ id, shouldUseNewPrivilegeSystem: true }))+ };+ const auditLogSettingsDAL = {+ findByOrgIds: vi.fn(async (orgIds: string[]) => rows.filter((row) => orgIds.includes(row.orgId)))+ };+ const keyStore = {+ getItem: vi.fn(async () => null),+ setItemWithExpiry: vi.fn(async () => "OK"),+ deleteItem: vi.fn(async () => 1)+ };++ const service = auditLogSettingsServiceFactory({+ auditLogSettingsDAL: auditLogSettingsDAL as never,+ orgDAL: orgDAL as never,+ projectDAL: {} as never,+ permissionService: {} as never,+ keyStore: keyStore as never+ });++ return { service, orgDAL, auditLogSettingsDAL, keyStore };+};++describe("getEffectiveSettings", () => {+ beforeEach(() => {+ vi.clearAllMocks();+ });++ test("loads only the org's own rows, split by scope", async () => {+ const { service, auditLogSettingsDAL } = createHarness({+ rows: [+ { orgId: "org-1", projectId: null, eventClass: "data-access", isEnabled: false },+ { orgId: "org-1", projectId: "p1", eventClass: "authentication", isEnabled: false },+ { orgId: "org-2", projectId: null, eventClass: "management", isEnabled: false }+ ]+ });++ const result = await service.getEffectiveSettings("org-1");++ expect(auditLogSettingsDAL.findByOrgIds).toHaveBeenCalledWith(["org-1"]);+ expect(result).toEqual({+ org: { "data-access": false },+ projects: { p1: { authentication: false } },+ shouldUseNewPrivilegeSystem: true+ });+ });++ test("caches the loaded settings", async () => {+ const { service, keyStore } = createHarness();++ await service.getEffectiveSettings("org-1");++ expect(keyStore.setItemWithExpiry).toHaveBeenCalledTimes(1);+ });+});diff --git a/backend/src/ee/services/audit-log/audit-log-settings-service.ts b/backend/src/ee/services/audit-log/audit-log-settings-service.tsindex 04cf5b974a..d9b7a7579a 100644--- a/backend/src/ee/services/audit-log/audit-log-settings-service.ts+++ b/backend/src/ee/services/audit-log/audit-log-settings-service.ts@@ -18,7 +18,6 @@ import {TEffectiveAuditLogSettings,TGetOrgAuditLogSettingsDTO,TGetProjectAuditLogSettingsDTO,- TProjectAuditLogEventClassSetting,TUpdateOrgAuditLogSettingsDTO,TUpdateProjectAuditLogSettingsDTO} from "./audit-log-settings-types";@@ -40,6 +39,7 @@ const ORDERED_EVENT_CLASSES = [AuditLogEventClass.Authorization] as const;+// Scopes don't inherit. A project without a row gets the default, not its org's value.export const isAuditLogEventClassEnabled = (settings: TEffectiveAuditLogSettings | null,eventClass: AuditLogEventClass,@@ -47,13 +47,19 @@ export const isAuditLogEventClassEnabled = () => {// null means the lookup failed. Don't silence the log over it.if (!settings) return true;- const projectValue = projectId ? settings.projects[projectId]?.[eventClass] : undefined;- return projectValue ?? settings.org[eventClass] ?? AUDIT_LOG_EVENT_CLASS_DEFAULTS[eventClass];+ const scope = projectId ? settings.projects[projectId] : settings.org;+ return scope?.[eventClass] ?? AUDIT_LOG_EVENT_CLASS_DEFAULTS[eventClass];};const isKnownEventClass = (value: string): value is AuditLogEventClass =>(Object.values(AuditLogEventClass) as string[]).includes(value);+const toSettings = (overrides: TAuditLogEventClassOverrides): TAuditLogEventClassSetting[] =>+ ORDERED_EVENT_CLASSES.map((eventClass) => ({+ eventClass,+ isEnabled: overrides[eventClass] ?? AUDIT_LOG_EVENT_CLASS_DEFAULTS[eventClass]+ }));+export const auditLogSettingsServiceFactory = ({auditLogSettingsDAL,orgDAL,@@ -65,16 +71,11 @@ export const auditLogSettingsServiceFactory = ({await keyStore.deleteItem(KeyStorePrefixes.AuditLogOrgSettings(orgId));};- // Org rows live on the root org, so a sub-org inherits them. Project rows carry the- // project's own org id.const loadSettings = async (orgId: string): Promise<TEffectiveAuditLogSettings | null> => {const org = await orgDAL.findById(orgId);if (!org) return null;- const settingsOrgId = org.rootOrgId ?? orgId;- const orgIds = settingsOrgId === orgId ? [orgId] : [orgId, settingsOrgId];- const rows = await auditLogSettingsDAL.findByOrgIds(orgIds);-+ const rows = await auditLogSettingsDAL.findByOrgIds([orgId]);const settings: TEffectiveAuditLogSettings = {org: {},projects: {},@@ -84,7 +85,7 @@ export const auditLogSettingsServiceFactory = ({if (!isKnownEventClass(row.eventClass)) return;if (row.projectId) {settings.projects[row.projectId] = { ...settings.projects[row.projectId], [row.eventClass]: row.isEnabled };- } else if (row.orgId === settingsOrgId) {+ } else {settings.org[row.eventClass] = row.isEnabled;}});@@ -114,12 +115,6 @@ export const auditLogSettingsServiceFactory = ({}};- const toOrgSettings = (overrides: TAuditLogEventClassOverrides): TAuditLogEventClassSetting[] =>- ORDERED_EVENT_CLASSES.map((eventClass) => ({- eventClass,- isEnabled: overrides[eventClass] ?? AUDIT_LOG_EVENT_CLASS_DEFAULTS[eventClass]- }));-const getOrgSettings = async ({ actor }: TGetOrgAuditLogSettingsDTO) => {const { permission } = await permissionService.getOrgPermission({scope: OrganizationActionScope.Any,@@ -135,14 +130,14 @@ export const auditLogSettingsServiceFactory = ({if (!settings) throw new NotFoundError({ message: `Organization with ID '${actor.orgId}' not found` });return {- eventClasses: toOrgSettings(settings.org),+ eventClasses: toSettings(settings.org),shouldUseNewPrivilegeSystem: settings.shouldUseNewPrivilegeSystem};};const updateOrgSettings = async ({ actor, eventClasses }: TUpdateOrgAuditLogSettingsDTO) => {const { permission } = await permissionService.getOrgPermission({- scope: OrganizationActionScope.ParentOrganization,+ scope: OrganizationActionScope.Any,actor: actor.type,actorId: actor.id,orgId: actor.orgId,@@ -151,8 +146,7 @@ export const auditLogSettingsServiceFactory = ({});ForbiddenError.from(permission).throwUnlessCan(OrgPermissionActions.Edit, OrgPermissionSubjects.Settings);- const byClass = new Map(eventClasses.map((el) => [el.eventClass, el.isEnabled]));- const changed = [...byClass.entries()];+ const changed = [...new Map(eventClasses.map((el) => [el.eventClass, el.isEnabled])).entries()];if (changed.length) {await auditLogSettingsDAL.transaction(async (tx) => {@@ -194,17 +188,10 @@ export const auditLogSettingsServiceFactory = ({const settings = await loadSettings(project.orgId);if (!settings) throw new NotFoundError({ message: `Organization with ID '${project.orgId}' not found` });- const projectOverrides = settings.projects[projectId] ?? {};- const eventClasses: TProjectAuditLogEventClassSetting[] = toOrgSettings(settings.org).map((setting) => {- const override = projectOverrides[setting.eventClass];- return {- ...setting,- isEnabled: override ?? setting.isEnabled,- source: override === undefined ? "organization" : "project"- };- });-- return { eventClasses, shouldUseNewPrivilegeSystem: settings.shouldUseNewPrivilegeSystem };+ return {+ eventClasses: toSettings(settings.projects[projectId] ?? {}),+ shouldUseNewPrivilegeSystem: settings.shouldUseNewPrivilegeSystem+ };};const updateProjectSettings = async ({ eventClasses, ...dto }: TUpdateProjectAuditLogSettingsDTO) => {@@ -225,8 +212,7 @@ export const auditLogSettingsServiceFactory = ({const project = await projectDAL.findById(dto.projectId);if (!project) throw new NotFoundError({ message: `Project with ID '${dto.projectId}' not found` });- const byClass = new Map(eventClasses.map((el) => [el.eventClass, el.isEnabled]));- const changed = [...byClass.entries()];+ const changed = [...new Map(eventClasses.map((el) => [el.eventClass, el.isEnabled])).entries()];if (changed.length) {await auditLogSettingsDAL.transaction(async (tx) => {@@ -234,15 +220,15 @@ export const auditLogSettingsServiceFactory = ({{ projectId: dto.projectId, $in: { eventClass: changed.map(([eventClass]) => eventClass) } },tx);- const rows = changed- .filter((entry): entry is [AuditLogEventClass, boolean] => typeof entry[1] === "boolean")- .map(([eventClass, isEnabled]) => ({+ await auditLogSettingsDAL.insertMany(+ changed.map(([eventClass, isEnabled]) => ({orgId: project.orgId,projectId: dto.projectId,eventClass,isEnabled- }));- if (rows.length) await auditLogSettingsDAL.insertMany(rows, tx);+ })),+ tx+ );});await invalidateCache(project.orgId);}diff --git a/backend/src/ee/services/audit-log/audit-log-settings-types.ts b/backend/src/ee/services/audit-log/audit-log-settings-types.tsindex b1e68f59c8..af9cca89eb 100644--- a/backend/src/ee/services/audit-log/audit-log-settings-types.ts+++ b/backend/src/ee/services/audit-log/audit-log-settings-types.ts@@ -7,23 +7,19 @@ export type TAuditLogEventClassSetting = {isEnabled: boolean;};-export type TProjectAuditLogEventClassSetting = TAuditLogEventClassSetting & {- source: "organization" | "project";-};-export type TGetOrgAuditLogSettingsDTO = {actor: OrgServiceActor;};export type TUpdateOrgAuditLogSettingsDTO = {actor: OrgServiceActor;- eventClasses: { eventClass: AuditLogEventClass; isEnabled: boolean }[];+ eventClasses: TAuditLogEventClassSetting[];};export type TGetProjectAuditLogSettingsDTO = TProjectPermission;export type TUpdateProjectAuditLogSettingsDTO = TProjectPermission & {- eventClasses: { eventClass: AuditLogEventClass; isEnabled: boolean | null }[];+ eventClasses: TAuditLogEventClassSetting[];};// A missing key means not set at this scope.diff --git a/backend/src/ee/services/audit-log/audit-log-types.ts b/backend/src/ee/services/audit-log/audit-log-types.tsindex c639f9421c..acd181cda4 100644--- a/backend/src/ee/services/audit-log/audit-log-types.ts+++ b/backend/src/ee/services/audit-log/audit-log-types.ts@@ -6008,7 +6008,7 @@ interface UpdateAuditLogSettingsEvent {metadata: {scope: "organization" | "project";projectId?: string;- eventClasses: { eventClass: string; isEnabled: boolean | null }[];+ eventClasses: { eventClass: string; isEnabled: boolean }[];};}diff --git a/backend/src/lib/api-docs/constants.ts b/backend/src/lib/api-docs/constants.tsindex e947534e27..2fb419afab 100644--- a/backend/src/lib/api-docs/constants.ts+++ b/backend/src/lib/api-docs/constants.ts@@ -2083,19 +2083,18 @@ export const INTEGRATION = {export const AUDIT_LOG_SETTINGS = {eventClass: "The audit log event class: management, authentication, data-access, or authorization.",isEnabled: "Whether events of this class are recorded.",- source:- 'Where the effective value comes from: "project" when the project has its own setting, "organization" when it inherits the organization default.',shouldUseNewPrivilegeSystem:"Whether the organization is on the new privilege system. Permission denials (the authorization class) are only recorded on the new privilege system.",UPDATE_ORG: {eventClasses: "The event classes to update.",- isEnabled: "Whether to record events of this class for the organization. Projects can override it."+ isEnabled:+ "Whether to record events of this class for the organization. This only covers organization-level events; each project has its own setting."},UPDATE_PROJECT: {projectId: "The ID of the project to update the audit log settings for.",eventClasses: "The event classes to update.",isEnabled:- "Whether to record events of this class for the project. true or false overrides the organization default; null removes the override so the project follows the organization."+ "Whether to record events of this class for the project. A project that has never saved a setting uses the default."},GET_PROJECT: {projectId: "The ID of the project to get the audit log settings for."diff --git a/backend/src/server/routes/v1/project-router.ts b/backend/src/server/routes/v1/project-router.tsindex 8470ee7b9a..9571fbedf6 100644--- a/backend/src/server/routes/v1/project-router.ts+++ b/backend/src/server/routes/v1/project-router.ts@@ -742,8 +742,7 @@ export const registerProjectRouter = async (server: FastifyZodProvider) => {eventClasses: z.object({eventClass: z.nativeEnum(AuditLogEventClass).describe(AUDIT_LOG_SETTINGS.eventClass),- isEnabled: z.boolean().describe(AUDIT_LOG_SETTINGS.isEnabled),- source: z.enum(["organization", "project"]).describe(AUDIT_LOG_SETTINGS.source)+ isEnabled: z.boolean().describe(AUDIT_LOG_SETTINGS.isEnabled)}).array(),shouldUseNewPrivilegeSystem: z.boolean().describe(AUDIT_LOG_SETTINGS.shouldUseNewPrivilegeSystem)@@ -782,7 +781,7 @@ export const registerProjectRouter = async (server: FastifyZodProvider) => {eventClasses: z.object({eventClass: z.nativeEnum(AuditLogEventClass).describe(AUDIT_LOG_SETTINGS.eventClass),- isEnabled: z.boolean().nullable().describe(AUDIT_LOG_SETTINGS.UPDATE_PROJECT.isEnabled)+ isEnabled: z.boolean().describe(AUDIT_LOG_SETTINGS.UPDATE_PROJECT.isEnabled)}).array().min(1)@@ -795,8 +794,7 @@ export const registerProjectRouter = async (server: FastifyZodProvider) => {eventClasses: z.object({eventClass: z.nativeEnum(AuditLogEventClass).describe(AUDIT_LOG_SETTINGS.eventClass),- isEnabled: z.boolean().describe(AUDIT_LOG_SETTINGS.isEnabled),- source: z.enum(["organization", "project"]).describe(AUDIT_LOG_SETTINGS.source)+ isEnabled: z.boolean().describe(AUDIT_LOG_SETTINGS.isEnabled)}).array(),shouldUseNewPrivilegeSystem: z.boolean().describe(AUDIT_LOG_SETTINGS.shouldUseNewPrivilegeSystem)diff --git a/docs/documentation/platform/audit-logs.mdx b/docs/documentation/platform/audit-logs.mdxindex 5c2aeebad9..cbe0505dda 100644--- a/docs/documentation/platform/audit-logs.mdx+++ b/docs/documentation/platform/audit-logs.mdx@@ -240,7 +240,7 @@ A class follows the operation that was attempted, not its outcome, so a failed l### Choose which classes to record-By default, Infisical records every class except `authorization`. An organization admin can turn any class on or off for the whole organization, and a project admin can override that choice for one project in either direction.+By default, Infisical records every class except `authorization`. Each organization, sub-organization, and project has its own settings, and they don't inherit from each other. The organization settings cover organization-level events such as membership and login changes. A project's settings cover that project's events, so turning a class off for the organization doesn't turn it off for its projects.<Tabs><Tab title="For an organization">@@ -265,7 +265,7 @@ By default, Infisical records every class except `authorization`. An organizatio</Step></Steps>- Only project admins can change these toggles. A row labeled **Organization Default** follows the organization setting. A row labeled **Project Override** uses the project's own setting, even if the organization turned the class off. Select **Use Organization Default** to remove an override.+ Only project admins can change these toggles. A project that has never saved a setting uses the defaults.</Tab><Tab title="API">Update the organization's classes with [the organization audit log settings endpoint](/api-reference/endpoints/audit-logs/update-organization-audit-log-settings), or one project's classes with [the project audit log settings endpoint](/api-reference/endpoints/audit-logs/update-project-audit-log-settings).@@ -277,7 +277,6 @@ By default, Infisical records every class except `authorization`. An organizatio-d '{"eventClasses": [{"eventClass": "data-access", "isEnabled": false}]}'```- For a project, `isEnabled` also accepts `null`, which removes the project's override so the project follows the organization again.</Tab></Tabs>diff --git a/frontend/src/hooks/api/auditLogSettings/mutations.tsx b/frontend/src/hooks/api/auditLogSettings/mutations.tsxindex 02bca58ba9..339b0ce30a 100644--- a/frontend/src/hooks/api/auditLogSettings/mutations.tsx+++ b/frontend/src/hooks/api/auditLogSettings/mutations.tsx@@ -4,8 +4,7 @@ import { apiRequest } from "@app/config/request";import { auditLogSettingsKeys } from "./queries";import {- TOrgAuditLogSettings,- TProjectAuditLogSettings,+ TAuditLogSettings,TUpdateOrgAuditLogSettingsDTO,TUpdateProjectAuditLogSettingsDTO} from "./types";@@ -14,7 +13,7 @@ export const useUpdateOrgAuditLogSettings = (orgId: string) => {const queryClient = useQueryClient();return useMutation({mutationFn: async (dto: TUpdateOrgAuditLogSettingsDTO) => {- const { data } = await apiRequest.put<{ auditLogSettings: TOrgAuditLogSettings }>(+ const { data } = await apiRequest.put<{ auditLogSettings: TAuditLogSettings }>("/api/v1/organization/audit-log-settings",dto);@@ -22,8 +21,6 @@ export const useUpdateOrgAuditLogSettings = (orgId: string) => {},onSuccess: (data) => {queryClient.setQueryData(auditLogSettingsKeys.org(orgId), data);- // Project settings inherit from the org, so they may have changed too.- queryClient.invalidateQueries({ queryKey: auditLogSettingsKeys.all });}});};@@ -32,7 +29,7 @@ export const useUpdateProjectAuditLogSettings = () => {const queryClient = useQueryClient();return useMutation({mutationFn: async ({ projectId, ...dto }: TUpdateProjectAuditLogSettingsDTO) => {- const { data } = await apiRequest.put<{ auditLogSettings: TProjectAuditLogSettings }>(+ const { data } = await apiRequest.put<{ auditLogSettings: TAuditLogSettings }>(`/api/v1/projects/${projectId}/audit-log-settings`,dto);diff --git a/frontend/src/hooks/api/auditLogSettings/queries.tsx b/frontend/src/hooks/api/auditLogSettings/queries.tsxindex eb81a4162a..747c6a9337 100644--- a/frontend/src/hooks/api/auditLogSettings/queries.tsx+++ b/frontend/src/hooks/api/auditLogSettings/queries.tsx@@ -2,7 +2,7 @@ import { useQuery } from "@tanstack/react-query";import { apiRequest } from "@app/config/request";-import { TOrgAuditLogSettings, TProjectAuditLogSettings } from "./types";+import { TAuditLogSettings } from "./types";export const auditLogSettingsKeys = {all: ["audit-log-settings"] as const,@@ -14,7 +14,7 @@ export const useGetOrgAuditLogSettings = (orgId: string) => {return useQuery({queryKey: auditLogSettingsKeys.org(orgId),queryFn: async () => {- const { data } = await apiRequest.get<{ auditLogSettings: TOrgAuditLogSettings }>(+ const { data } = await apiRequest.get<{ auditLogSettings: TAuditLogSettings }>("/api/v1/organization/audit-log-settings");return data.auditLogSettings;@@ -27,7 +27,7 @@ export const useGetProjectAuditLogSettings = (projectId: string) => {return useQuery({queryKey: auditLogSettingsKeys.project(projectId),queryFn: async () => {- const { data } = await apiRequest.get<{ auditLogSettings: TProjectAuditLogSettings }>(+ const { data } = await apiRequest.get<{ auditLogSettings: TAuditLogSettings }>(`/api/v1/projects/${projectId}/audit-log-settings`);return data.auditLogSettings;diff --git a/frontend/src/hooks/api/auditLogSettings/types.tsx b/frontend/src/hooks/api/auditLogSettings/types.tsxindex ea0939aa13..251daf97d9 100644--- a/frontend/src/hooks/api/auditLogSettings/types.tsx+++ b/frontend/src/hooks/api/auditLogSettings/types.tsx@@ -10,25 +10,16 @@ export type TAuditLogEventClassSetting = {isEnabled: boolean;};-export type TProjectAuditLogEventClassSetting = TAuditLogEventClassSetting & {- source: "organization" | "project";-};--export type TOrgAuditLogSettings = {+export type TAuditLogSettings = {eventClasses: TAuditLogEventClassSetting[];shouldUseNewPrivilegeSystem: boolean;};-export type TProjectAuditLogSettings = {- eventClasses: TProjectAuditLogEventClassSetting[];- shouldUseNewPrivilegeSystem: boolean;-};-export type TUpdateOrgAuditLogSettingsDTO = {- eventClasses: { eventClass: AuditLogEventClass; isEnabled: boolean }[];+ eventClasses: TAuditLogEventClassSetting[];};export type TUpdateProjectAuditLogSettingsDTO = {projectId: string;- eventClasses: { eventClass: AuditLogEventClass; isEnabled: boolean | null }[];+ eventClasses: TAuditLogEventClassSetting[];};diff --git a/frontend/src/pages/organization/AuditLogsPage/components/AuditLogSettingsTab/AuditLogSettingsTab.tsx b/frontend/src/pages/organization/AuditLogsPage/components/AuditLogSettingsTab/AuditLogSettingsTab.tsxindex 103acabdfe..f585c9c7dc 100644--- a/frontend/src/pages/organization/AuditLogsPage/components/AuditLogSettingsTab/AuditLogSettingsTab.tsx+++ b/frontend/src/pages/organization/AuditLogsPage/components/AuditLogSettingsTab/AuditLogSettingsTab.tsx@@ -52,7 +52,7 @@ export const AuditLogSettingsTab = withPermission(control,handleSubmit,reset,- formState: { isDirty }+ formState: { isDirty, dirtyFields }} = useForm<TForm>({values: Object.fromEntries(AUDIT_LOG_EVENT_CLASSES.map((eventClass) => [eventClass, isEnabled(eventClass)])@@ -63,12 +63,12 @@ export const AuditLogSettingsTab = withPermission(settings?.shouldUseNewPrivilegeSystem ?? currentOrg.shouldUseNewPrivilegeSystem;const onSubmit = async (form: TForm) => {- await updateSettings({- eventClasses: AUDIT_LOG_EVENT_CLASSES.map((eventClass) => ({- eventClass,- isEnabled: form[eventClass]- }))- });+ const eventClasses = AUDIT_LOG_EVENT_CLASSES.filter(+ (eventClass) => dirtyFields[eventClass]+ ).map((eventClass) => ({ eventClass, isEnabled: form[eventClass] }));+ if (!eventClasses.length) return;++ await updateSettings({ eventClasses });createNotification({ text: "Audit log settings saved", type: "success" });};@@ -81,8 +81,8 @@ export const AuditLogSettingsTab = withPermission(<DocumentationLinkBadge href="https://infisical.com/docs/documentation/platform/audit-logs" /></CardTitle><CardDescription>- Choose which classes of events are recorded. Every event type belongs to exactly one- class.+ Choose which classes of organization-level events are recorded. Each project has its+ own setting for its events.</CardDescription></CardHeader>{isPending ? (diff --git a/frontend/src/pages/project/SettingsPage/components/AuditLogEventClassesSection/AuditLogEventClassesSection.tsx b/frontend/src/pages/project/SettingsPage/components/AuditLogEventClassesSection/AuditLogEventClassesSection.tsxindex 12dfb97087..4aeb302680 100644--- a/frontend/src/pages/project/SettingsPage/components/AuditLogEventClassesSection/AuditLogEventClassesSection.tsx+++ b/frontend/src/pages/project/SettingsPage/components/AuditLogEventClassesSection/AuditLogEventClassesSection.tsx@@ -4,7 +4,6 @@ import { Link } from "@tanstack/react-router";import { AuditLogEventClassRow } from "@app/components/auditLogSettings";import { createNotification } from "@app/components/notifications";import {- Badge,Button,Card,CardDescription,@@ -20,10 +19,7 @@ import {AUDIT_LOG_EVENT_CLASS_DEFAULTS,AUDIT_LOG_EVENT_CLASSES} from "@app/hooks/api/auditLogSettings/constants";-import {- AuditLogEventClass,- TProjectAuditLogEventClassSetting-} from "@app/hooks/api/auditLogSettings/types";+import { AuditLogEventClass } from "@app/hooks/api/auditLogSettings/types";import { ProjectMembershipRole } from "@app/hooks/api/roles/types";type TForm = Record<AuditLogEventClass, boolean>;@@ -39,12 +35,9 @@ export const AuditLogEventClassesSection = () => {const { data: settings, isPending } = useGetProjectAuditLogSettings(currentProject.id);const { mutateAsync: updateSettings, isPending: isSaving } = useUpdateProjectAuditLogSettings();- const settingFor = (eventClass: AuditLogEventClass): TProjectAuditLogEventClassSetting =>- settings?.eventClasses.find((el) => el.eventClass === eventClass) ?? {- eventClass,- isEnabled: AUDIT_LOG_EVENT_CLASS_DEFAULTS[eventClass],- source: "organization"- };+ const isEnabled = (eventClass: AuditLogEventClass) =>+ settings?.eventClasses.find((el) => el.eventClass === eventClass)?.isEnabled ??+ AUDIT_LOG_EVENT_CLASS_DEFAULTS[eventClass];const {control,@@ -53,14 +46,13 @@ export const AuditLogEventClassesSection = () => {formState: { isDirty, dirtyFields }} = useForm<TForm>({values: Object.fromEntries(- AUDIT_LOG_EVENT_CLASSES.map((eventClass) => [eventClass, settingFor(eventClass).isEnabled])+ AUDIT_LOG_EVENT_CLASSES.map((eventClass) => [eventClass, isEnabled(eventClass)])) as TForm});const shouldUseNewPrivilegeSystem =settings?.shouldUseNewPrivilegeSystem ?? currentOrg.shouldUseNewPrivilegeSystem;- // Only send touched rows, so untouched ones keep following the org.const onSubmit = async (form: TForm) => {const eventClasses = AUDIT_LOG_EVENT_CLASSES.filter((eventClass) => dirtyFields[eventClass]@@ -71,17 +63,6 @@ export const AuditLogEventClassesSection = () => {createNotification({ text: "Audit log settings saved", type: "success" });};- const applyOrgDefault = async (eventClass: AuditLogEventClass) => {- await updateSettings({- projectId: currentProject.id,- eventClasses: [{ eventClass, isEnabled: null }]- });- createNotification({- text: "Project now follows the organization default for this class",- type: "success"- });- };-return (<form onSubmit={handleSubmit(onSubmit)} className="mb-6"><Card className="gap-0 overflow-hidden p-0">@@ -90,10 +71,7 @@ export const AuditLogEventClassesSection = () => {Audit Log Event Classes<DocumentationLinkBadge href="https://infisical.com/docs/documentation/platform/audit-logs" /></CardTitle>- <CardDescription>- Choose which classes of events this project records. Rows without an override follow the- organization setting.- </CardDescription>+ <CardDescription>Choose which classes of events this project records.</CardDescription></CardHeader>{isPending ? (<div className="space-y-4 p-6">@@ -106,7 +84,6 @@ export const AuditLogEventClassesSection = () => {{AUDIT_LOG_EVENT_CLASSES.map((eventClass) => {const isAuthorization = eventClass === AuditLogEventClass.Authorization;const isLocked = isAuthorization && !shouldUseNewPrivilegeSystem;- const hasOverride = settingFor(eventClass).source === "project";return (<Controllerkey={eventClass}@@ -120,27 +97,6 @@ export const AuditLogEventClassesSection = () => {isDisabled={!isAdmin}lockedReason={isLocked ? REQUIRES_NEW_PRIVILEGE_SYSTEM : undefined}onCheckedChange={field.onChange}- badge={- hasOverride ? (- <Badge variant="project">Project Override</Badge>- ) : (- <Badge variant="neutral">Organization Default</Badge>- )- }- action={- isAdmin && hasOverride && !isLocked ? (- <Button- type="button"- variant="ghost"- size="xs"- className="h-auto px-1.5 py-0.5 text-2xs font-normal text-muted hover:text-foreground"- isDisabled={isSaving}- onClick={() => applyOrgDefault(eventClass)}- >- Use Organization Default- </Button>- ) : undefined- }warning={eventClass === AuditLogEventClass.DataAccess && !field.value? "Secret Insights are counted from these events and stay flat while this is off."