Skip to content

Commit dbc9a0b

Browse files
fix(rbac): implement conditional aliases (#1847)
* fix(rbac): implement conditional aliases Signed-off-by: Oleksandr Andriienko <[email protected]> * fix(rbac): fix build Signed-off-by: Oleksandr Andriienko <[email protected]> * fix(rbac): rework currentUser alias to cover ownershipEntityRefs Signed-off-by: Oleksandr Andriienko <[email protected]> * fix(rbac): add more unit tests Signed-off-by: Oleksandr Andriienko <[email protected]> * feat(rbac): make feature working after backstage update to 1.29.2 Signed-off-by: Oleksandr Andriienko <[email protected]> * feat(rbac): fix compilation and tests Signed-off-by: Oleksandr Andriienko <[email protected]> * feat(rbac): Support two aliases: currentUser and ownerRefs Signed-off-by: Oleksandr Andriienko <[email protected]> * feat(rbac): add doc about conditional policies aliases Signed-off-by: Oleksandr Andriienko <[email protected]> * feat(rbac): clean up unit test Signed-off-by: Oleksandr Andriienko <[email protected]> * feat(rbac): clean up Signed-off-by: Oleksandr Andriienko <[email protected]> * feat(rbac): clean up Signed-off-by: Oleksandr Andriienko <[email protected]> * feat(rbac): fix dependencies Signed-off-by: Oleksandr Andriienko <[email protected]> * feat(rbac): update yarn.lock Signed-off-by: Oleksandr Andriienko <[email protected]> --------- Signed-off-by: Oleksandr Andriienko <[email protected]>
1 parent bd74b1b commit dbc9a0b

File tree

11 files changed

+876
-75
lines changed

11 files changed

+876
-75
lines changed

plugins/rbac-backend/docs/conditions.md

Lines changed: 38 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -274,13 +274,49 @@ To utilize this condition to the RBAC REST api you need to wrap it with more inf
274274
}
275275
```
276276

277+
## Conditional Policy Aliases
278+
279+
The RBAC-backend plugin allows for the use of aliases in the conditional policy rule parameters. These aliases are dynamically replaced with corresponding values during the policy evaluation process. Each alias is prefixed with a `$` sign to denote its special function.
280+
281+
### Supported Aliases
282+
283+
1. **`$currentUser`**:
284+
285+
- **Description**: This alias is replaced with the user entity reference for the user currently requesting access to the resource.
286+
- **Example**: If the user "Tom" from the "default" namespace is requesting access, `$currentUser` will be replaced with `user:default/tom`.
287+
288+
2. **`$ownerRefs`**:
289+
- **Description**: This alias is replaced with ownership references, typically in the form of an array. The array usually contains the user entity reference and the user's parent group entity reference.
290+
- **Example**: For a user "Tom" who belongs to "team-a", `$ownerRefs` will be replaced with `['user:default/tom', 'group:default/team-a']`.
291+
292+
### Example of a Conditional Policy Object with Alias
293+
294+
This condition should allow members of the `role:default/developer` to delete only their own catalogs and no others:
295+
296+
```json
297+
{
298+
"result": "CONDITIONAL",
299+
"roleEntityRef": "role:default/developer",
300+
"pluginId": "catalog",
301+
"resourceType": "catalog-entity",
302+
"permissionMapping": ["delete"],
303+
"conditions": {
304+
"rule": "IS_ENTITY_OWNER",
305+
"resourceType": "catalog-entity",
306+
"params": {
307+
"claims": ["$currentUser"]
308+
}
309+
}
310+
}
311+
```
312+
277313
## Examples of Conditional Policies
278314

279315
Below are a few examples that can be used on some of the Janus IDP plugins. These can help in determining how based to define conditional policies
280316

281317
### Keycloak plugin
282318

283-
```JSON
319+
```json
284320
{
285321
"result": "CONDITIONAL",
286322
"roleEntityRef": "role:default/developer",
@@ -303,7 +339,7 @@ Notice the use of the annotation `keycloak.org/realm` requires the value of `<YO
303339

304340
### Quay Actions
305341

306-
```JSON
342+
```json
307343
{
308344
"result": "CONDITIONAL",
309345
"roleEntityRef": "role:default/developer",

plugins/rbac-backend/package.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,10 +42,11 @@
4242
"@backstage/plugin-permission-backend": "^0.5.46",
4343
"@backstage/plugin-permission-common": "^0.8.0",
4444
"@backstage/plugin-permission-node": "^0.8.0",
45+
"@backstage/types": "^1.1.1",
4546
"@dagrejs/graphlib": "^2.1.13",
47+
"@janus-idp/backstage-plugin-audit-log-node": "1.4.0",
4648
"@janus-idp/backstage-plugin-rbac-common": "1.8.1",
4749
"@janus-idp/backstage-plugin-rbac-node": "1.4.0",
48-
"@janus-idp/backstage-plugin-audit-log-node": "1.4.0",
4950
"casbin": "^5.27.1",
5051
"chokidar": "^3.6.0",
5152
"csv-parse": "^5.5.5",
@@ -58,8 +59,8 @@
5859
"yn": "^4.0.0"
5960
},
6061
"devDependencies": {
61-
"@backstage/cli": "0.26.11",
6262
"@backstage/backend-test-utils": "0.4.4",
63+
"@backstage/cli": "0.26.11",
6364
"@types/express": "4.17.21",
6465
"@types/node": "18.19.34",
6566
"@types/supertest": "2.0.16",

0 commit comments

Comments
 (0)