Skip to content

Commit

Permalink
fix(rbac): fix rbac-backend startup (#2463)
Browse files Browse the repository at this point in the history
* fix(rbac): fix rbac-backend startup

Signed-off-by: Oleksandr Andriienko <oandriie@redhat.com>

* fix(rbac): fix rbac-backend startup

Signed-off-by: Oleksandr Andriienko <oandriie@redhat.com>

---------

Signed-off-by: Oleksandr Andriienko <oandriie@redhat.com>
  • Loading branch information
AndrienkoAleksandr authored Oct 31, 2024
1 parent cfc9eb2 commit 0646434
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 2 deletions.
5 changes: 5 additions & 0 deletions .changeset/thirty-pets-buy.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@janus-idp/backstage-plugin-rbac-backend": patch
---

Fix broken plugin startup: don't attempt to store permission policies that are already stored.
22 changes: 22 additions & 0 deletions plugins/rbac-backend/src/admin-permissions/admin-creation.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,28 @@ describe('Admin Creation', () => {
expect(enfPermission).toEqual(permissions);
});

it(`should not assign an admin to the permissions if permissions are already assigned`, async () => {
await expect(async () => {
await setAdminPermissions(enfDelegate, auditLoggerMock);
}).not.toThrow();
});

it(`should assign an admin to the new permission`, async () => {
const newDefaultPermission = [
adminRole,
'something-new',
'create',
'allow',
];
await enfDelegate.addPolicy(newDefaultPermission);
await setAdminPermissions(enfDelegate, auditLoggerMock);
const enfPermission = await enfDelegate.getFilteredPolicy(
0,
...newDefaultPermission,
);
expect(enfPermission.length).toEqual(1);
});

it('should fail to build the admin permissions, problem with creating role metadata', async () => {
roleMetadataStorageMock.findRoleMetadata = jest
.fn()
Expand Down
8 changes: 7 additions & 1 deletion plugins/rbac-backend/src/admin-permissions/admin-creation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,13 @@ const addAdminPermissions = async (
enf: EnforcerDelegate,
auditLogger: AuditLogger,
) => {
await enf.addPolicies(policies);
const policiesToAdd: string[][] = [];
for (const policy of policies) {
if (!(await enf.hasPolicy(...policy))) {
policiesToAdd.push(policy);
}
}
await enf.addPolicies(policiesToAdd);

await auditLogger.auditLog<PermissionAuditInfo>({
actorId: RBAC_BACKEND,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2093,7 +2093,7 @@ function newConfig(
permission: {
rbac: {
'policies-csv-file': permFile || csvPermFile,
policyFileReload: true,
policyFileReload: false,
admin: {
users: users || testUsers,
superUsers: superUsers,
Expand Down

0 comments on commit 0646434

Please sign in to comment.