inbar dor
07/07/2024, 6:27 AMDennis (Cerbos)
I’m wondering if there is a way to save the policy in multiple files by roles…You can create a derived role for each of your custom roles.
inbar dor
07/08/2024, 1:49 PMapiVersion: api.cerbos.dev/v1
resourcePolicy:
version: default
resource: call
rules:
- actions:
- "view"
effect: EFFECT_ALLOW
roles:
- GLOBAL_ADMIN
- CUSTOMER_ADMIN
- CUSTOM_ROLE_1
condition:
match:
all:
of:
- any:
of:
- expr: R.attr.groups.hasIntersection(P.attr.scoped_roles["GLOBAL_ADMIN"].groups)
- expr: R.attr.groups.hasIntersection(P.attr.scoped_roles["CUSTOM_ROLE_1"].groups)
Dennis (Cerbos)
R.attr.groups.hasIntersection(P.attr.scoped_roles["CUSTOM_ROLE_1"].groups)
R.attr.groups.hasIntersection(P.attr.scoped_roles["CUSTOM_ROLE_2"].groups)
....
R.attr.groups.hasIntersection(P.attr.scoped_roles["CUSTOM_ROLE_N"].groups)
then you can write this expression once: R.attr.groups.hasIntersection(P.attr.scoped_roles[P.attr.custom_role].groups)
and pass the custom role in P.attr.custom_role
. You don’t need to add custom roles to the resourcePolicy -> rules -> roles
list either.
If a user might have many custom roles, you can pass them in P.attr.custom_roles
and use the following expression:
P.attr.custom_roles.exists(custom_role, R.attr.groups.hasIntersection(P.attr.scoped_roles[custom_role].groups))
inbar dor
07/09/2024, 6:50 AM