Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(rbac): don't start transaction if there no group policies #1923

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions plugins/rbac-backend/src/service/enforcer-delegate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -156,12 +156,12 @@ export class EnforcerDelegate {
roleMetadata: RoleMetadataDao,
externalTrx?: Knex.Transaction,
): Promise<void> {
const trx = externalTrx ?? (await this.knex.transaction());

if (policies.length === 0) {
return;
}

const trx = externalTrx ?? (await this.knex.transaction());

try {
const currentRoleMetadata =
await this.roleMetadataStorage.findRoleMetadata(
Expand Down
12 changes: 9 additions & 3 deletions plugins/rbac-backend/src/service/permission-policy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ const useAdminsFromConfig = async (
await roleMetadataStorage.findRoleMetadata(ADMIN_ROLE_NAME);

const trx = await knex.transaction();
let addedRoleMembers;
try {
if (!adminRoleMeta) {
// even if there are no user, we still create default role metadata for admins
Expand All @@ -101,15 +102,20 @@ const useAdminsFromConfig = async (
trx,
);
}

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

await trx.commit();
} catch (error) {
await trx.rollback(error);
throw error;
}

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

await auditLogger.auditLog<RoleAuditInfo>({
actorId: RBAC_BACKEND,
message: `Created or updated role`,
Expand Down
Loading