-
Notifications
You must be signed in to change notification settings - Fork 153
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(rbac): prevent policy creation when rbac plugin is disabled (#2407)
* fix(rbac): prevent policy creation when rbac plugin is disabled * fix(rbac): move permission-policy.ts to policies directory * fix(rbac): clean up some options for policy server * fix(rbac): include changeset for rbac backend plugin * fix(rbac): fix some broken imports after rebase
- Loading branch information
1 parent
412e8ba
commit e6ef910
Showing
10 changed files
with
164 additions
and
69 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"@janus-idp/backstage-plugin-rbac-backend": patch | ||
--- | ||
|
||
Refactors the rbac backend plugin to prevent the creation of permission policies and roles whenever the plugin and permission framework is disabled |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
67 changes: 67 additions & 0 deletions
67
plugins/rbac-backend/src/policies/allow-all-policy.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
import { | ||
AuthorizeResult, | ||
createPermission, | ||
} from '@backstage/plugin-permission-common'; | ||
import { | ||
PermissionPolicy, | ||
PolicyQuery, | ||
PolicyQueryUser, | ||
} from '@backstage/plugin-permission-node'; | ||
|
||
import { AllowAllPolicy } from './allow-all-policy'; | ||
|
||
describe('Allow All Policy', () => { | ||
describe('Allow all policy should allow all', () => { | ||
let policy: PermissionPolicy; | ||
beforeEach(() => { | ||
policy = new AllowAllPolicy(); | ||
}); | ||
|
||
it('should be able to create an allow all permission policy', () => { | ||
expect(policy).not.toBeNull(); | ||
}); | ||
|
||
it('should allow all when handle is called', async () => { | ||
const result = await policy.handle( | ||
newPolicyQueryWithBasicPermission('catalog.entity.create'), | ||
newPolicyQueryUser('user:default/guest'), | ||
); | ||
|
||
expect(result).toStrictEqual({ result: AuthorizeResult.ALLOW }); | ||
}); | ||
}); | ||
}); | ||
|
||
function newPolicyQueryWithBasicPermission(name: string): PolicyQuery { | ||
const mockPermission = createPermission({ | ||
name: name, | ||
attributes: {}, | ||
}); | ||
return { permission: mockPermission }; | ||
} | ||
|
||
function newPolicyQueryUser( | ||
user?: string, | ||
ownershipEntityRefs?: string[], | ||
): PolicyQueryUser | undefined { | ||
if (user) { | ||
return { | ||
identity: { | ||
ownershipEntityRefs: ownershipEntityRefs ?? [], | ||
type: 'user', | ||
userEntityRef: user, | ||
}, | ||
credentials: { | ||
$$type: '@backstage/BackstageCredentials', | ||
principal: true, | ||
expiresAt: new Date('2021-01-01T00:00:00Z'), | ||
}, | ||
info: { | ||
userEntityRef: user, | ||
ownershipEntityRefs: ownershipEntityRefs ?? [], | ||
}, | ||
token: 'token', | ||
}; | ||
} | ||
return undefined; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import { | ||
AuthorizeResult, | ||
PolicyDecision, | ||
} from '@backstage/plugin-permission-common'; | ||
import { | ||
PermissionPolicy, | ||
PolicyQuery, | ||
PolicyQueryUser, | ||
} from '@backstage/plugin-permission-node'; | ||
|
||
export class AllowAllPolicy implements PermissionPolicy { | ||
async handle( | ||
_request: PolicyQuery, | ||
_user?: PolicyQueryUser, | ||
): Promise<PolicyDecision> { | ||
return { result: AuthorizeResult.ALLOW }; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.