diff --git a/plugins/rbac-backend/src/audit-log/audit-logger.ts b/plugins/rbac-backend/src/audit-log/audit-logger.ts index d947778ae7..8770155d58 100644 --- a/plugins/rbac-backend/src/audit-log/audit-logger.ts +++ b/plugins/rbac-backend/src/audit-log/audit-logger.ts @@ -17,6 +17,7 @@ export const RoleEvents = { CREATE_ROLE: 'CreateRole', UPDATE_ROLE: 'UpdateRole', DELETE_ROLE: 'DeleteRole', + CREATE_OR_UPDATE_ROLE: 'CreateOrUpdateRole', GET_ROLE: 'GetRole', CREATE_ROLE_ERROR: 'CreateRoleError', diff --git a/plugins/rbac-backend/src/service/permission-policy.ts b/plugins/rbac-backend/src/service/permission-policy.ts index c434d85d73..ad86b2afda 100644 --- a/plugins/rbac-backend/src/service/permission-policy.ts +++ b/plugins/rbac-backend/src/service/permission-policy.ts @@ -73,12 +73,17 @@ const useAdminsFromConfig = async ( knex: Knex, ) => { const addedGroupPolicies = new Map(); + const newGroupPolicies = new Map(); for (const admin of admins) { const entityRef = admin.getString('name'); validateEntityReference(entityRef); addedGroupPolicies.set(entityRef, ADMIN_ROLE_NAME); + + if (!(await enf.hasGroupingPolicy(...[entityRef, ADMIN_ROLE_NAME]))) { + newGroupPolicies.set(entityRef, ADMIN_ROLE_NAME); + } } const adminRoleMeta = @@ -102,13 +107,13 @@ const useAdminsFromConfig = async ( throw error; } - const addedRoleMembers = Array.from(addedGroupPolicies.entries()); + const addedRoleMembers = Array.from(newGroupPolicies.entries()); await enf.addGroupingPolicies(addedRoleMembers, getAdminRoleMetadata()); await auditLogger.auditLog({ actorId: RBAC_BACKEND, message: `Created or updated role`, - eventName: RoleEvents.CREATE_ROLE, + eventName: RoleEvents.CREATE_OR_UPDATE_ROLE, metadata: { ...getAdminRoleMetadata(), members: addedRoleMembers.map(gp => gp[0]),