Skip to content

Commit

Permalink
fix(rbac): fix bug with restart instance
Browse files Browse the repository at this point in the history
Signed-off-by: Oleksandr Andriienko <[email protected]>
  • Loading branch information
AndrienkoAleksandr committed Jul 5, 2024
1 parent 77edf3a commit cbc15b3
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
1 change: 1 addition & 0 deletions plugins/rbac-backend/src/audit-log/audit-logger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
9 changes: 7 additions & 2 deletions plugins/rbac-backend/src/service/permission-policy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,12 +73,17 @@ const useAdminsFromConfig = async (
knex: Knex,
) => {
const addedGroupPolicies = new Map<string, string>();
const newGroupPolicies = new Map<string, string>();

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 =
Expand All @@ -102,13 +107,13 @@ const useAdminsFromConfig = async (
throw error;
}

const addedRoleMembers = Array.from<string[]>(addedGroupPolicies.entries());
const addedRoleMembers = Array.from<string[]>(newGroupPolicies.entries());
await enf.addGroupingPolicies(addedRoleMembers, getAdminRoleMetadata());

await auditLogger.auditLog<RoleAuditInfo>({
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]),
Expand Down

0 comments on commit cbc15b3

Please sign in to comment.