Skip to content

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

add pam cleanup resources

Thiago Araujo da Silva8e48c71a5a1a
diff --git a/backend/src/services/approval-policy/approval-policy-dal.ts b/backend/src/services/approval-policy/approval-policy-dal.ts
index ff408243c9..4560a2f176 100644
--- a/backend/src/services/approval-policy/approval-policy-dal.ts
+++ b/backend/src/services/approval-policy/approval-policy-dal.ts
@@ -586,6 +586,29 @@ export const approvalPolicyDALFactory = (db: TDbClient) => {
}
};
+ const deleteUserBypassersInProjects = async (
+ args: { projectIds: string[]; userIds: string[]; scopeTypes: string[] },
+ tx?: Knex
+ ): Promise<void> => {
+ try {
+ if (!args.projectIds.length || !args.userIds.length || !args.scopeTypes.length) return;
+
+ const conn = tx || db;
+
+ const policyIds = conn(TableName.ApprovalPolicies)
+ .whereIn("projectId", args.projectIds)
+ .whereIn("scopeType", args.scopeTypes)
+ .select("id");
+
+ await conn(TableName.ApprovalPolicyBypassers)
+ .whereIn("policyId", policyIds)
+ .whereIn("userId", args.userIds)
+ .delete();
+ } catch (error) {
+ throw new DatabaseError({ error, name: "Delete user bypassers in projects" });
+ }
+ };
+
return {
...orm,
findByIdForUpdate,
@@ -600,7 +623,8 @@ export const approvalPolicyDALFactory = (db: TDbClient) => {
findRequestableScopes,
deleteStepApproversBySubject,
deleteBypassersBySubject,
- deleteUserStepApproversInProjects
+ deleteUserStepApproversInProjects,
+ deleteUserBypassersInProjects
};
};
diff --git a/backend/src/services/membership/application-membership-cleanup-service.ts b/backend/src/services/membership/application-membership-cleanup-service.ts
index af0482e62c..6a51b5c042 100644
--- a/backend/src/services/membership/application-membership-cleanup-service.ts
+++ b/backend/src/services/membership/application-membership-cleanup-service.ts
@@ -11,13 +11,14 @@ type TApplicationMembershipCleanupServiceFactoryDep = {
membershipDAL: Pick<TMembershipDALFactory, "delete">;
approvalPolicyDAL: Pick<
TApprovalPolicyDALFactory,
- "deleteStepApproversBySubject" | "deleteUserStepApproversInProjects"
+ "deleteStepApproversBySubject" | "deleteUserStepApproversInProjects" | "deleteUserBypassersInProjects"
>;
};
export type TApplicationMembershipCleanupServiceFactory = ReturnType<typeof applicationMembershipCleanupServiceFactory>;
const APPLICATION_APPROVAL_SCOPES = [ApprovalPolicyScope.PkiApplication, ApprovalPolicyScope.Signer];
+const ORG_EXIT_APPROVAL_SCOPES = [...APPLICATION_APPROVAL_SCOPES, ApprovalPolicyScope.PamFolder];
export const applicationMembershipCleanupServiceFactory = ({
membershipDAL,
@@ -89,7 +90,11 @@ export const applicationMembershipCleanupServiceFactory = ({
if (userIds.length) {
await approvalPolicyDAL.deleteUserStepApproversInProjects(
- { projectIds, userIds, scopeTypes: APPLICATION_APPROVAL_SCOPES },
+ { projectIds, userIds, scopeTypes: ORG_EXIT_APPROVAL_SCOPES },
+ tx
+ );
+ await approvalPolicyDAL.deleteUserBypassersInProjects(
+ { projectIds, userIds, scopeTypes: ORG_EXIT_APPROVAL_SCOPES },
tx
);
}