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
update to only admin change
Thiago Araujo da Silva9f2f4bd9b276
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.tsindex be581a6467..a7df30a33c 100644--- 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.ts@@ -1,7 +1,10 @@import { createMongoAbility } from "@casl/ability";import { beforeEach, describe, expect, test, vi } from "vitest";+import { ActorType } from "@app/services/auth/auth-type";+import { OrgPermissionActions, OrgPermissionSubjects } from "../permission/org-permission";+import { ProjectPermissionActions, ProjectPermissionSub } from "../permission/project-permission";import { AuditLogEventClass } from "./audit-log-event-classes";import { auditLogSettingsServiceFactory, isAuditLogEventEnabled } from "./audit-log-settings-service";import { TEffectiveAuditLogSettings } from "./audit-log-settings-types";@@ -57,7 +60,7 @@ const orgActor = {parentOrgId: "org-1"} as never;-const createHarness = ({ rows = [] as TRow[], shouldUseNewPrivilegeSystem = true } = {}) => {+const createHarness = ({ rows = [] as TRow[], shouldUseNewPrivilegeSystem = true, isAdmin = true } = {}) => {const orgDAL = {findById: vi.fn(async (id: string) => ({ id, shouldUseNewPrivilegeSystem }))};@@ -79,14 +82,30 @@ const createHarness = ({ rows = [] as TRow[], shouldUseNewPrivilegeSystem = trueconst permissionService = {getOrgPermission: vi.fn(async () => ({- permission: createMongoAbility([{ action: OrgPermissionActions.Edit, subject: OrgPermissionSubjects.Settings }])+ permission: createMongoAbility([+ { action: [OrgPermissionActions.Read, OrgPermissionActions.Edit], subject: OrgPermissionSubjects.Settings }+ ]),+ hasRole: (role: string) => isAdmin && role === "admin"+ })),+ getProjectPermission: vi.fn(async () => ({+ permission: createMongoAbility([+ {+ action: [ProjectPermissionActions.Read, ProjectPermissionActions.Edit],+ subject: ProjectPermissionSub.Settings+ }+ ]),+ hasRole: (role: string) => isAdmin && role === "admin"}))};+ const projectDAL = {+ findById: vi.fn(async (id: string) => ({ id, orgId: "org-1" }))+ };+const service = auditLogSettingsServiceFactory({auditLogSettingsDAL: auditLogSettingsDAL as never,orgDAL: orgDAL as never,- projectDAL: {} as never,+ projectDAL: projectDAL as never,permissionService: permissionService as never,keyStore: keyStore as never});@@ -127,11 +146,34 @@ describe("getEffectiveSettings", () => {});});+const fullEventClasses = [+ { eventClass: AuditLogEventClass.DataAccess, isEnabled: false },+ { eventClass: AuditLogEventClass.Authentication, isEnabled: true },+ { eventClass: AuditLogEventClass.Authorization, isEnabled: false }+];+describe("updateOrgSettings", () => {beforeEach(() => {vi.clearAllMocks();});+ test("refuses a non-admin even with edit on settings", async () => {+ const { service, auditLogSettingsDAL } = createHarness({ isAdmin: false });++ await expect(service.updateOrgSettings({ actor: orgActor, eventClasses: fullEventClasses })).rejects.toThrow(+ "Only organization admins can change which audit log event classes are recorded"+ );+ expect(auditLogSettingsDAL.transaction).not.toHaveBeenCalled();+ });++ test("still lets a non-admin with read on settings read them", async () => {+ const { service } = createHarness({ isAdmin: false });++ const result = await service.getOrgSettings({ actor: orgActor });++ expect(result.eventClasses).toHaveLength(4);+ });+test.each([false, true])("refuses any management entry (isEnabled=%s)", async (isEnabled) => {const { service, auditLogSettingsDAL } = createHarness();@@ -247,3 +289,34 @@ describe("updateOrgSettings", () => {});});});++describe("updateProjectSettings", () => {+ beforeEach(() => {+ vi.clearAllMocks();+ });++ const projectActor = {+ actor: ActorType.USER,+ actorId: "user-1",+ actorAuthMethod: null,+ actorOrgId: "org-1",+ projectId: "p1"+ };++ test("refuses a non-admin even with edit on settings", async () => {+ const { service, auditLogSettingsDAL } = createHarness({ isAdmin: false });++ await expect(service.updateProjectSettings({ ...projectActor, eventClasses: fullEventClasses })).rejects.toThrow(+ "Only project admins can change which audit log event classes are recorded"+ );+ expect(auditLogSettingsDAL.transaction).not.toHaveBeenCalled();+ });++ test("lets a project admin save", async () => {+ const { service, auditLogSettingsDAL } = createHarness();++ await service.updateProjectSettings({ ...projectActor, eventClasses: fullEventClasses });++ expect(auditLogSettingsDAL.delete).toHaveBeenCalledWith({ orgId: "org-1", projectId: "p1" }, expect.anything());+ });+});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 1515597b69..a5bbc97752 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@@ -1,6 +1,12 @@import { ForbiddenError } from "@casl/ability";-import { ActionProjectType, OrganizationActionScope, ProjectMembershipRole, TAuditLogSettings } from "@app/db/schemas";+import {+ ActionProjectType,+ OrganizationActionScope,+ OrgMembershipRole,+ ProjectMembershipRole,+ TAuditLogSettings+} from "@app/db/schemas";import { KeyStorePrefixes, KeyStoreTtls, TKeyStoreFactory } from "@app/keystore/keystore";import { BadRequestError, ForbiddenRequestError, NotFoundError } from "@app/lib/errors";import { logger } from "@app/lib/logger";@@ -127,8 +133,8 @@ export const auditLogSettingsServiceFactory = ({return project;};- const assertOrgSettingsPermission = async (actor: OrgServiceActor, action: OrgPermissionActions) => {- const { permission } = await permissionService.getOrgPermission({+ const getOrgPermission = (actor: OrgServiceActor) =>+ permissionService.getOrgPermission({scope: OrganizationActionScope.Any,actor: actor.type,actorId: actor.id,@@ -136,8 +142,6 @@ export const auditLogSettingsServiceFactory = ({actorAuthMethod: actor.authMethod,actorOrgId: actor.orgId});- ForbiddenError.from(permission).throwUnlessCan(action, OrgPermissionSubjects.Settings);- };const toResponse = (overrides: TAuditLogEventClassOverrides,@@ -208,14 +212,20 @@ export const auditLogSettingsServiceFactory = ({};const getOrgSettings = async ({ actor }: TGetOrgAuditLogSettingsDTO) => {- await assertOrgSettingsPermission(actor, OrgPermissionActions.Read);+ const { permission } = await getOrgPermission(actor);+ ForbiddenError.from(permission).throwUnlessCan(OrgPermissionActions.Read, OrgPermissionSubjects.Settings);const org = await findOrgOrThrow(actor.orgId);const rows = await auditLogSettingsDAL.find({ orgId: org.id, projectId: null });return toResponse(toOverrides(rows), org);};const updateOrgSettings = async ({ actor, eventClasses }: TUpdateOrgAuditLogSettingsDTO) => {- await assertOrgSettingsPermission(actor, OrgPermissionActions.Edit);+ const { hasRole } = await getOrgPermission(actor);+ if (!hasRole(OrgMembershipRole.Admin)) {+ throw new ForbiddenRequestError({+ message: "Only organization admins can change which audit log event classes are recorded"+ });+ }const org = await findOrgOrThrow(actor.orgId);const overrides = toFullOverrides(eventClasses);assertAuthorizationClassAllowed(org, overrides);diff --git a/backend/src/server/routes/v1/organization-router.ts b/backend/src/server/routes/v1/organization-router.tsindex e03ba49273..f5efed4277 100644--- a/backend/src/server/routes/v1/organization-router.ts+++ b/backend/src/server/routes/v1/organization-router.ts@@ -180,7 +180,8 @@ export const registerOrgRouter = async (server: FastifyZodProvider) => {hide: false,operationId: "updateOrganizationAuditLogSettings",tags: [ApiDocsTags.AuditLogs],- description: "Update which audit log event classes the organization records",+ description:+ "Update which audit log event classes the organization records. Requires the organization admin role.",body: updateAuditLogSettingsBodySchema(AUDIT_LOG_SETTINGS.UPDATE_ORG.isEnabled),response: {200: AuditLogSettingsResponseSchemadiff --git a/backend/src/server/routes/v1/project-router.ts b/backend/src/server/routes/v1/project-router.tsindex bc72ef074e..e5fc3e11ca 100644--- a/backend/src/server/routes/v1/project-router.ts+++ b/backend/src/server/routes/v1/project-router.ts@@ -766,7 +766,7 @@ export const registerProjectRouter = async (server: FastifyZodProvider) => {hide: false,operationId: "updateProjectAuditLogSettings",tags: [ApiDocsTags.AuditLogs],- description: "Update which audit log event classes the project records",+ description: "Update which audit log event classes the project records. Requires the project admin role.",params: z.object({projectId: z.string().uuid().describe(AUDIT_LOG_SETTINGS.UPDATE_PROJECT.projectId)}),diff --git a/docs/documentation/platform/audit-logs.mdx b/docs/documentation/platform/audit-logs.mdxindex 2d7bc819d6..ef0ba53187 100644--- a/docs/documentation/platform/audit-logs.mdx+++ b/docs/documentation/platform/audit-logs.mdx@@ -253,7 +253,7 @@ By default, Infisical records every class except `authorization`. The `managemen</Step></Steps>- You need the **Edit** permission on **Settings** to change these toggles.+ Only admins of the organization or sub-organization can change these toggles. Anyone with the **Read** permission on **Settings** can view them.</Tab><Tab title="For a project"><Steps>diff --git a/frontend/src/pages/organization/AuditLogsPage/components/AuditLogSettingsTab/AuditLogSettingsTab.tsx b/frontend/src/pages/organization/AuditLogsPage/components/AuditLogSettingsTab/AuditLogSettingsTab.tsxindex 30ae5c988a..5fb840280c 100644--- a/frontend/src/pages/organization/AuditLogsPage/components/AuditLogSettingsTab/AuditLogSettingsTab.tsx+++ b/frontend/src/pages/organization/AuditLogsPage/components/AuditLogSettingsTab/AuditLogSettingsTab.tsx@@ -5,6 +5,7 @@ import {useOrganization,useOrgPermission} from "@app/context";+import { OrgMembershipRole } from "@app/helpers/roles";import { withPermission } from "@app/hoc";import { useScopeVariant } from "@app/hooks";import { useGetOrgAuditLogSettings, useUpdateOrgAuditLogSettings } from "@app/hooks/api";@@ -12,9 +13,9 @@ import { useGetOrgAuditLogSettings, useUpdateOrgAuditLogSettings } from "@app/hoexport const AuditLogSettingsTab = withPermission(() => {const { currentOrg } = useOrganization();- const { permission } = useOrgPermission();+ const { hasOrgRole } = useOrgPermission();const scopeVariant = useScopeVariant();- const canEdit = permission.can(OrgPermissionActions.Edit, OrgPermissionSubjects.Settings);+ const canEdit = hasOrgRole(OrgMembershipRole.Admin);const { data: settings, isPending } = useGetOrgAuditLogSettings(currentOrg.id);const { mutateAsync: updateSettings, isPending: isSaving } = useUpdateOrgAuditLogSettings(