Skip to content

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

address plan check on update policy

adilsonc308cecb4beb
diff --git a/backend/src/server/routes/index.ts b/backend/src/server/routes/index.ts
index 90a518e5bd..1a7bde265c 100644
--- a/backend/src/server/routes/index.ts
+++ b/backend/src/server/routes/index.ts
@@ -3361,6 +3361,7 @@ export const registerRoutes = async (
approvalPolicyDAL,
appConnectionDAL,
appConnectionService,
+ licenseService,
eventEmitter: eventOutboxService
});
diff --git a/backend/src/services/delegated-approval/delegated-approval-service.test.ts b/backend/src/services/delegated-approval/delegated-approval-service.test.ts
index dd65cd6f24..5625aa4283 100644
--- a/backend/src/services/delegated-approval/delegated-approval-service.test.ts
+++ b/backend/src/services/delegated-approval/delegated-approval-service.test.ts
@@ -191,3 +191,28 @@ describe("delegatedApprovalService.retryDispatch", () => {
expect(emit).not.toHaveBeenCalled();
});
});
+
+describe("delegatedApprovalService.assertPlanAllowsPolicyEdit", () => {
+ const createPlanService = (enterpriseAppConnections: boolean) => {
+ const getPlan = vi.fn().mockResolvedValue({ enterpriseAppConnections });
+ const service = delegatedApprovalServiceFactory({ licenseService: { getPlan } } as never);
+ return { service, getPlan };
+ };
+
+ test("refuses the edit when the org's plan lacks enterprise app connections", async () => {
+ const { service, getPlan } = createPlanService(false);
+
+ await expect(service.assertPlanAllowsPolicyEdit(DelegatedApprovalPolicyType.ServiceNow, "org-1")).rejects.toThrow(
+ "remove the delegated approver to edit this policy"
+ );
+ expect(getPlan).toHaveBeenCalledWith("org-1");
+ });
+
+ test("allows the edit when the org's plan includes enterprise app connections", async () => {
+ const { service } = createPlanService(true);
+
+ await expect(
+ service.assertPlanAllowsPolicyEdit(DelegatedApprovalPolicyType.ServiceNow, "org-1")
+ ).resolves.toBeUndefined();
+ });
+});
diff --git a/backend/src/services/delegated-approval/delegated-approval-service.ts b/backend/src/services/delegated-approval/delegated-approval-service.ts
index 1175b95e63..3f2c3c46a8 100644
--- a/backend/src/services/delegated-approval/delegated-approval-service.ts
+++ b/backend/src/services/delegated-approval/delegated-approval-service.ts
@@ -2,12 +2,14 @@ import crypto from "node:crypto";
import { Knex } from "knex";
+import { TLicenseServiceFactory } from "@app/ee/services/license/license-service";
import { DatabaseErrorCode } from "@app/lib/error-codes";
import { BadRequestError, NotFoundError } from "@app/lib/errors";
import { hasPostgresErrorCode } from "@app/lib/errors/postgres";
import { OrgServiceActor } from "@app/lib/types";
import { TAppConnectionDALFactory } from "@app/services/app-connection/app-connection-dal";
import { AppConnection } from "@app/services/app-connection/app-connection-enums";
+import { enterpriseAppCheck } from "@app/services/app-connection/app-connection-fns";
import { APP_CONNECTION_NAME_MAP } from "@app/services/app-connection/app-connection-maps";
import { TAppConnectionServiceFactory } from "@app/services/app-connection/app-connection-service";
import { TApprovalPolicyDALFactory } from "@app/services/approval-policy/approval-policy-dal";
@@ -36,6 +38,7 @@ type TDelegatedApprovalServiceFactoryDep = {
approvalPolicyDAL: Pick<TApprovalPolicyDALFactory, "findById">;
appConnectionDAL: Pick<TAppConnectionDALFactory, "findById">;
appConnectionService: Pick<TAppConnectionServiceFactory, "validateAppConnectionUsageById">;
+ licenseService: Pick<TLicenseServiceFactory, "getPlan">;
eventEmitter: TEventEmitter;
};
@@ -47,6 +50,7 @@ export const delegatedApprovalServiceFactory = ({
approvalPolicyDAL,
appConnectionDAL,
appConnectionService,
+ licenseService,
eventEmitter
}: TDelegatedApprovalServiceFactoryDep) => {
const $assertConnectionMatches = async (
@@ -84,6 +88,15 @@ export const delegatedApprovalServiceFactory = ({
);
};
+ const assertPlanAllowsPolicyEdit = async (type: DelegatedApprovalPolicyType, orgId: string) => {
+ await enterpriseAppCheck(
+ licenseService,
+ DELEGATED_APPROVAL_CONNECTION_MAP[type],
+ orgId,
+ `Failed to update policy: ${DELEGATED_APPROVAL_NAME_MAP[type]} delegated approval is only available on plans with enterprise app connections. Upgrade your plan, or remove the delegated approver to edit this policy.`
+ );
+ };
+
const createPolicy = async ({ policyId, type, connectionId }: TCreateDelegatedApprovalPolicyDTO, tx?: Knex) => {
const approvalPolicy = await approvalPolicyDAL.findById(policyId, tx);
if (!approvalPolicy) {
@@ -256,6 +269,7 @@ export const delegatedApprovalServiceFactory = ({
return {
listDelegatedApprovalOptions,
validateConnection,
+ assertPlanAllowsPolicyEdit,
createPolicy,
getPolicyByPolicyId,
updatePolicy,
diff --git a/backend/src/services/secret-access-approval-global-policy-bridge/secret-access-approval-global-policy-bridge-service.ts b/backend/src/services/secret-access-approval-global-policy-bridge/secret-access-approval-global-policy-bridge-service.ts
index 3328b54cf1..09fbd02106 100644
--- a/backend/src/services/secret-access-approval-global-policy-bridge/secret-access-approval-global-policy-bridge-service.ts
+++ b/backend/src/services/secret-access-approval-global-policy-bridge/secret-access-approval-global-policy-bridge-service.ts
@@ -616,11 +616,16 @@ export const secretAccessApprovalGlobalPolicyBridgeServiceFactory = ({
(envs.length !== currentEnvSlugs.size || envs.some((env) => !currentEnvSlugs.has(env.slug)));
const scopeChanged = nextSecretPath !== policy.secretPath || environmentsChanged;
- if (delegatedApproval && isDelegatedApprovalChanged(policy.delegatedApproval, delegatedApproval)) {
- await delegatedApprovalService.validateConnection(
- { ...delegatedApproval, projectId: policy.projectId },
- orgActor
- );
+ const nextDelegatedApproval = delegatedApproval === undefined ? policy.delegatedApproval : delegatedApproval;
+ if (nextDelegatedApproval) {
+ // we might need to change this in the future to check a specific permission if this is changed on the license server
+ await delegatedApprovalService.assertPlanAllowsPolicyEdit(nextDelegatedApproval.type, actorOrgId);
+ if (isDelegatedApprovalChanged(policy.delegatedApproval, nextDelegatedApproval)) {
+ await delegatedApprovalService.validateConnection(
+ { ...nextDelegatedApproval, projectId: policy.projectId },
+ orgActor
+ );
+ }
}
return approvalPolicyDAL.transaction(async (tx) => {
diff --git a/backend/src/services/secret-access-approval-global-policy-bridge/secret-access-approval-global-policy-bridge-types.ts b/backend/src/services/secret-access-approval-global-policy-bridge/secret-access-approval-global-policy-bridge-types.ts
index 6e35507065..deab118da0 100644
--- a/backend/src/services/secret-access-approval-global-policy-bridge/secret-access-approval-global-policy-bridge-types.ts
+++ b/backend/src/services/secret-access-approval-global-policy-bridge/secret-access-approval-global-policy-bridge-types.ts
@@ -57,7 +57,7 @@ export type TSecretAccessApprovalGlobalPolicyBridgeServiceFactoryDep = {
>;
delegatedApprovalService: Pick<
TDelegatedApprovalServiceFactory,
- "validateConnection" | "createPolicy" | "updatePolicy" | "deletePolicyByPolicyId"
+ "validateConnection" | "assertPlanAllowsPolicyEdit" | "createPolicy" | "updatePolicy" | "deletePolicyByPolicyId"
>;
};
diff --git a/frontend/src/pages/secret-manager/SecretApprovalsPage/components/AccessApprovalRequest/components/ReviewAccessModal.tsx b/frontend/src/pages/secret-manager/SecretApprovalsPage/components/AccessApprovalRequest/components/ReviewAccessModal.tsx
index 90c655dacd..bba8d6d8ec 100644
--- a/frontend/src/pages/secret-manager/SecretApprovalsPage/components/AccessApprovalRequest/components/ReviewAccessModal.tsx
+++ b/frontend/src/pages/secret-manager/SecretApprovalsPage/components/AccessApprovalRequest/components/ReviewAccessModal.tsx
@@ -538,11 +538,9 @@ export const ReviewAccessRequestModal = ({
request.isApproved &&
new Date() > new Date(request.privilege.temporaryAccessEndTime || ("" as string));
const isReviewedByMe = request.reviewers.find((i) => i.userId === user.id);
- const isDelegatedPending =
- isDelegatedRequest &&
- request.status === ApprovalStatus.PENDING &&
- !hasExpired &&
- !request.policy.deletedAt;
+ const isDelegatedOpen =
+ isDelegatedRequest && request.status === ApprovalStatus.PENDING && !request.policy.deletedAt;
+ const isDelegatedPending = isDelegatedOpen && !hasExpired;
const canRetryDispatch =
!isRetryingDelegatedDispatch &&
@@ -555,7 +553,7 @@ export const ReviewAccessRequestModal = ({
));
const canCancelDelegatedRequest =
- isDelegatedPending &&
+ isDelegatedOpen &&
(request.isRequestedByCurrentUser ||
permission.can(ProjectPermissionActions.Edit, ProjectPermissionSub.SecretApproval));