Skip to content

Infisical is the open-source platform for securing secrets, certificates, access, and AI Agents.

only allow update settings if has access to audit log

Thiago Araujo da Silva3e6b0730f038
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.ts
index 01914f9e9c..9bd5d8755d 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
@@ -84,7 +84,12 @@ const orgActor = {
parentOrgId: "org-1"
} as never;
-const createHarness = ({ rows = [] as TRow[], shouldUseNewPrivilegeSystem = true, canEditAuditLogs = true } = {}) => {
+const createHarness = ({
+ rows = [] as TRow[],
+ shouldUseNewPrivilegeSystem = true,
+ canEditAuditLogs = true,
+ planHasAuditLogs = true
+} = {}) => {
const tx = { raw: vi.fn(async () => undefined) };
const orgDAL = {
findById: vi.fn(async (id: string) => ({ id, shouldUseNewPrivilegeSystem }))
@@ -130,16 +135,20 @@ const createHarness = ({ rows = [] as TRow[], shouldUseNewPrivilegeSystem = true
const projectDAL = {
findById: vi.fn(async (id: string) => ({ id, orgId: "org-1" }))
};
+ const licenseService = {
+ getPlan: vi.fn(async () => ({ auditLogs: planHasAuditLogs }))
+ };
const service = auditLogSettingsServiceFactory({
auditLogSettingsDAL: auditLogSettingsDAL as never,
orgDAL: orgDAL as never,
projectDAL: projectDAL as never,
permissionService: permissionService as never,
+ licenseService: licenseService as never,
keyStore: keyStore as never
});
- return { service, orgDAL, auditLogSettingsDAL, keyStore, tx };
+ return { service, orgDAL, auditLogSettingsDAL, keyStore, licenseService, tx };
};
describe("getEffectiveSettings", () => {
@@ -245,6 +254,23 @@ describe("updateOrgSettings", () => {
expect(result.eventClasses).toHaveLength(4);
});
+ test("refuses to save on a plan without audit logs", async () => {
+ const { service, auditLogSettingsDAL } = createHarness({ planHasAuditLogs: false });
+
+ await expect(service.updateOrgSettings({ actor: orgActor, eventClasses: fullEventClasses })).rejects.toThrow(
+ "Audit log settings can only be changed on a plan that includes audit logs"
+ );
+ expect(auditLogSettingsDAL.transaction).not.toHaveBeenCalled();
+ });
+
+ test("still lets a plan without audit logs read the settings", async () => {
+ const { service } = createHarness({ planHasAuditLogs: false });
+
+ const result = await service.getOrgSettings({ actor: orgActor });
+
+ expect(result.eventClasses).toHaveLength(4);
+ });
+
test.each([
[AuditLogEventClass.Management, false],
[AuditLogEventClass.Management, true],
@@ -408,6 +434,16 @@ describe("updateProjectSettings", () => {
expect(auditLogSettingsDAL.delete).toHaveBeenCalledWith({ orgId: "org-1", projectId: "p1" }, expect.anything());
});
+ test("refuses to save on a plan without audit logs, checked against the project's org", async () => {
+ const { service, auditLogSettingsDAL, licenseService } = createHarness({ planHasAuditLogs: false });
+
+ await expect(service.updateProjectSettings({ ...projectActor, eventClasses: fullEventClasses })).rejects.toThrow(
+ "Audit log settings can only be changed on a plan that includes audit logs"
+ );
+ expect(licenseService.getPlan).toHaveBeenCalledWith("org-1");
+ expect(auditLogSettingsDAL.transaction).not.toHaveBeenCalled();
+ });
+
test("invalidates only the project's cached settings", async () => {
const { service, keyStore } = createHarness();
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.ts
index e3599d6575..b2a7ccae22 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
@@ -4,10 +4,13 @@ import { ActionProjectType, OrganizationActionScope, TAuditLogSettings } from "@
import { KeyStorePrefixes, KeyStoreTtls, PgSqlLock, TKeyStoreFactory } from "@app/keystore/keystore";
import { BadRequestError, NotFoundError } from "@app/lib/errors";
import { logger } from "@app/lib/logger";
+import { requestMemoKeys } from "@app/lib/request-context/memo-keys";
+import { requestMemoize } from "@app/lib/request-context/request-memoizer";
import { OrgServiceActor } from "@app/lib/types";
import { TOrgDALFactory } from "@app/services/org/org-dal";
import { TProjectDALFactory } from "@app/services/project/project-dal";
+import { TLicenseServiceFactory } from "../license/license-service";
import {
OrgPermissionActions,
OrgPermissionAuditLogsActions,
@@ -45,6 +48,7 @@ type TAuditLogSettingsServiceFactoryDep = {
orgDAL: Pick<TOrgDALFactory, "findById">;
projectDAL: Pick<TProjectDALFactory, "findById">;
permissionService: Pick<TPermissionServiceFactory, "getOrgPermission" | "getProjectPermission">;
+ licenseService: Pick<TLicenseServiceFactory, "getPlan">;
keyStore: Pick<TKeyStoreFactory, "getItems" | "setItemWithExpiry" | "deleteItem">;
};
@@ -125,8 +129,19 @@ export const auditLogSettingsServiceFactory = ({
orgDAL,
projectDAL,
permissionService,
+ licenseService,
keyStore
}: TAuditLogSettingsServiceFactoryDep) => {
+ const assertPlanAllowsAuditLogs = async (orgId: string) => {
+ const plan = await requestMemoize(requestMemoKeys.licensePlan(orgId), () => licenseService.getPlan(orgId));
+ if (!plan.auditLogs) {
+ throw new BadRequestError({
+ message:
+ "Audit log settings can only be changed on a plan that includes audit logs. Upgrade your plan to continue."
+ });
+ }
+ };
+
const findOrgOrThrow = async (orgId: string) => {
const org = await orgDAL.findById(orgId);
if (!org) throw new NotFoundError({ message: `Organization with ID '${orgId}' not found` });
@@ -275,6 +290,7 @@ export const auditLogSettingsServiceFactory = ({
const updateOrgSettings = async ({ actor, eventClasses }: TUpdateOrgAuditLogSettingsDTO) => {
const { permission } = await getOrgPermission(actor);
ForbiddenError.from(permission).throwUnlessCan(OrgPermissionAuditLogsActions.Edit, OrgPermissionSubjects.AuditLogs);
+ await assertPlanAllowsAuditLogs(actor.orgId);
const org = await findOrgOrThrow(actor.orgId);
const overrides = toFullOverrides(eventClasses);
assertAuthorizationClassAllowed(org, overrides);
@@ -321,6 +337,7 @@ export const auditLogSettingsServiceFactory = ({
const project = await findProjectOrThrow(dto.projectId);
const org = await findOrgOrThrow(project.orgId);
+ await assertPlanAllowsAuditLogs(org.id);
const overrides = toFullOverrides(eventClasses);
assertAuthorizationClassAllowed(org, overrides);
await writeScopeSettings({ orgId: org.id, projectId: project.id }, overrides);
diff --git a/backend/src/server/routes/index.ts b/backend/src/server/routes/index.ts
index 8bff106f94..547c24589f 100644
--- a/backend/src/server/routes/index.ts
+++ b/backend/src/server/routes/index.ts
@@ -1216,6 +1216,7 @@ export const registerRoutes = async (
orgDAL,
projectDAL,
permissionService,
+ licenseService,
keyStore
});
diff --git a/frontend/src/components/auditLogSettings/AuditLogEventClassesForm.tsx b/frontend/src/components/auditLogSettings/AuditLogEventClassesForm.tsx
index 4bdc8354f4..4762537647 100644
--- a/frontend/src/components/auditLogSettings/AuditLogEventClassesForm.tsx
+++ b/frontend/src/components/auditLogSettings/AuditLogEventClassesForm.tsx
@@ -2,6 +2,7 @@ import { Controller, useForm } from "react-hook-form";
import { Link } from "@tanstack/react-router";
import { Info } from "lucide-react";
+import { UpgradePlanModal } from "@app/components/license/UpgradePlanModal";
import { createNotification } from "@app/components/notifications";
import {
Alert,
@@ -15,7 +16,8 @@ import {
DocumentationLinkBadge,
Skeleton
} from "@app/components/v3";
-import { useOrganization } from "@app/context";
+import { useOrganization, useSubscription } from "@app/context";
+import { usePopUp } from "@app/hooks";
import {
ALWAYS_RECORDED_AUDIT_LOG_EVENT_CLASSES,
AUDIT_LOG_EVENT_CLASS_DEFAULTS,
@@ -46,6 +48,7 @@ type Props = {
canEdit: boolean;
readOnlyMessage: string;
variant: ScopeVariant;
+ paywallKey: string;
onSave: (eventClasses: TAuditLogEventClassSetting[]) => Promise<unknown>;
};
@@ -59,9 +62,12 @@ export const AuditLogEventClassesForm = ({
canEdit,
readOnlyMessage,
variant,
+ paywallKey,
onSave
}: Props) => {
const { currentOrg } = useOrganization();
+ const { subscription } = useSubscription();
+ const { popUp, handlePopUpOpen, handlePopUpToggle } = usePopUp(["upgradePlan"] as const);
const shouldUseNewPrivilegeSystem =
settings?.shouldUseNewPrivilegeSystem ?? currentOrg.shouldUseNewPrivilegeSystem;
@@ -81,6 +87,10 @@ export const AuditLogEventClassesForm = ({
});
const onSubmit = async (form: TForm) => {
+ if (subscription && !subscription.auditLogs) {
+ handlePopUpOpen("upgradePlan");
+ return;
+ }
const eventClasses = CONFIGURABLE_AUDIT_LOG_EVENT_CLASSES.map((eventClass) => ({
eventClass,
isEnabled:
@@ -194,6 +204,12 @@ export const AuditLogEventClassesForm = ({
</CardFooter>
)}
</Card>
+ <UpgradePlanModal
+ paywallKey={paywallKey}
+ isOpen={popUp.upgradePlan.isOpen}
+ onOpenChange={(isOpen) => handlePopUpToggle("upgradePlan", isOpen)}
+ text="Your current plan does not include access to audit logs. To change which events are recorded, please upgrade to Infisical Pro plan."
+ />
</form>
);
};
diff --git a/frontend/src/pages/organization/AuditLogsPage/components/AuditLogSettingsTab/AuditLogSettingsTab.tsx b/frontend/src/pages/organization/AuditLogsPage/components/AuditLogSettingsTab/AuditLogSettingsTab.tsx
index 12278549da..474b78bb17 100644
--- a/frontend/src/pages/organization/AuditLogsPage/components/AuditLogSettingsTab/AuditLogSettingsTab.tsx
+++ b/frontend/src/pages/organization/AuditLogsPage/components/AuditLogSettingsTab/AuditLogSettingsTab.tsx
@@ -36,6 +36,7 @@ export const AuditLogSettingsTab = withPermission(
canEdit={canEdit}
readOnlyMessage="You need the Edit Settings permission on Audit Logs to change these settings."
variant={scopeVariant}
+ paywallKey="organization.audit-log-settings"
onSave={(eventClasses) => updateSettings({ eventClasses })}
/>
);
diff --git a/frontend/src/pages/project/AuditLogsPage/components/AuditLogEventClassesSection/AuditLogEventClassesSection.tsx b/frontend/src/pages/project/AuditLogsPage/components/AuditLogEventClassesSection/AuditLogEventClassesSection.tsx
index 2594762bb5..2e3284fc87 100644
--- a/frontend/src/pages/project/AuditLogsPage/components/AuditLogEventClassesSection/AuditLogEventClassesSection.tsx
+++ b/frontend/src/pages/project/AuditLogsPage/components/AuditLogEventClassesSection/AuditLogEventClassesSection.tsx
@@ -31,6 +31,7 @@ export const AuditLogEventClassesSection = () => {
canEdit={canEdit}
readOnlyMessage="You need the Edit Settings permission on Audit Logs to change these settings."
variant={scopeVariant}
+ paywallKey="project.audit-log-settings"
onSave={(eventClasses) => updateSettings({ projectId: currentProject.id, eventClasses })}
/>
);