-
Notifications
You must be signed in to change notification settings - Fork 0
/
rebac.rego
50 lines (37 loc) · 1.19 KB
/
rebac.rego
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
package permit.rebac
import data.permit.rbac
import data.permit.utils
import future.keywords.in
__rebac_data := {
"role_assignments": data.role_assignments,
"relationships": data.relationships,
"resource_types": data.resource_types,
}
default rebac_roles := []
rebac_roles_result := {
"roles": [],
"debugger": {
"error": "Connected PDPs do not not support ReBAC, try to update your pdp version"
}
}
rebac_roles := rebac_roles_result.roles
rebac_roles_debugger := rebac_roles_result.debugger
scoped_users_obj := result {
roles_path = sprintf("/%s/roleAssignments/%s", [input.user.key, input.resource.tenant])
result := json.patch(data.users, [{"op": "add", "path": roles_path, "value": rebac_roles}])
}
default allow := false
allow {
rbac.allow with data.users as scoped_users_obj
with data.roles_resource as input.resource.type
}
grants[grant] {
rbac.grants[grant] with data.users as scoped_users_obj with data.roles_resource as input.resource.type
}
allowing_roles[role_key] {
rbac.allowing_roles[role_key] with data.users as scoped_users_obj with data.roles_resource as input.resource.type
}
default activated := false
activated {
count(utils.object_keys(data.relationships)) > 0
}