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
fix for group deletion
Thiago Araujo da Silvaa4110d09730e
diff --git a/backend/src/ee/services/group/group-service.ts b/backend/src/ee/services/group/group-service.tsindex 90493733fc..e4587e6a3a 100644--- a/backend/src/ee/services/group/group-service.ts+++ b/backend/src/ee/services/group/group-service.ts@@ -723,6 +723,25 @@ export const groupServiceFactory = ({}const { group } = groupMembership;+ const targetRoles = resolveMembershipRoleSlugs(groupMembership.roles);+ if (targetRoles.length) {+ const targetPermissions = await permissionService.getOrgPermissionByRoles(targetRoles, actorOrgId, {+ ignoreUnresolvedRoles: true+ });+ const { shouldUseNewPrivilegeSystem } = await requestMemoize(requestMemoKeys.orgFindById(actorOrgId), () =>+ orgDAL.findById(actorOrgId)+ );++ assertRoleSetBoundary({+ shouldUseNewPrivilegeSystem,+ opActions: OrgPermissionGroupActions.Delete,+ opSubject: OrgPermissionSubjects.Groups,+ actorPermission: permission,+ targetPermissions,+ baseMessage: "Failed to delete a more privileged group"+ });+ }+const isLinkedGroup = group.orgId !== actorOrgId;if (isLinkedGroup) {diff --git a/backend/src/ee/services/group/group-update-boundary.test.ts b/backend/src/ee/services/group/group-update-boundary.test.tsindex 1f534fd6f6..422531ff20 100644--- a/backend/src/ee/services/group/group-update-boundary.test.ts+++ b/backend/src/ee/services/group/group-update-boundary.test.ts@@ -33,6 +33,19 @@ const groupEditorOnly = createMongoAbility<MongoAbility>([}]);+// deleteGroup's own throwUnlessCan demands Delete, which the editor ability above deliberately lacks.+const groupDeleterOnly = createMongoAbility<MongoAbility>([+ {+ action: [+ OrgPermissionGroupActions.Read,+ OrgPermissionGroupActions.Edit,+ OrgPermissionGroupActions.Delete,+ OrgPermissionGroupActions.GrantPrivileges+ ],+ subject: OrgPermissionSubjects.Groups+ }+]);+const createUpdate = ({actorPermission,shouldUseNewPrivilegeSystem,@@ -74,17 +87,20 @@ const createUpdate = ({membershipRoleDAL: membershipRoleDAL as never} as never);- const run = () =>- service.updateGroup({- id: GROUP_ID,- role: incomingRole,- actor: "user",- actorId: "actor-id",- actorAuthMethod: "email",- actorOrgId: ORG_ID- } as never);-- return { run, membershipRoleDAL };+ const actor = { actor: "user", actorId: "actor-id", actorAuthMethod: "email", actorOrgId: ORG_ID };++ const run = () => service.updateGroup({ id: GROUP_ID, role: incomingRole, ...actor } as never);+ const remove = () => service.deleteGroup({ id: GROUP_ID, ...actor } as never);++ return { run, remove, membershipRoleDAL };+};++// deleteGroup runs on past the boundary into the teardown this harness does not stand up, so the+// pass-through cases assert only that the boundary is not what stopped them.+const expectNoBoundaryError = async (fn: () => Promise<unknown>) => {+ await fn().catch((err: unknown) => {+ expect(err).not.toBeInstanceOf(PermissionBoundaryError);+ });};describe("updateGroup privilege boundary", () => {@@ -121,6 +137,28 @@ describe("updateGroup privilege boundary", () => {);});+ test("on the legacy system, a weaker actor cannot delete an Admin-role group", async () => {+ const { remove } = createUpdate({ actorPermission: groupDeleterOnly, shouldUseNewPrivilegeSystem: false });++ await expect(remove()).rejects.toThrow(PermissionBoundaryError);+ });++ test("deleting a group nothing outranks the actor on clears the boundary", async () => {+ const { remove } = createUpdate({+ actorPermission: groupDeleterOnly,+ shouldUseNewPrivilegeSystem: false,+ currentRole: OrgMembershipRole.NoAccess+ });++ await expectNoBoundaryError(remove);+ });++ test("an admin actor clears the delete boundary", async () => {+ const { remove } = createUpdate({ actorPermission: admin, shouldUseNewPrivilegeSystem: false });++ await expectNoBoundaryError(remove);+ });+test("nothing outranks the actor, so an ordinary no-access group is let through", async () => {const { run } = createUpdate({actorPermission: groupEditorOnly,