Stefan de Kooter
09/26/2024, 10:02 PM# Derive roles from AzureAD Group GUID
- name: device_mgmt_read
parentRoles:
- default
condition:
match:
any:
of:
# all tenants allowed for this guid
- expr: ("9a0d9319b51f1ef4" in P.roles)
# If tenantGUID is used, only allow role derivation when Resource is from the same tenant
- all:
of:
- expr: R.attr.Tenant == "TENANT1"
- expr: ("e25123bf9ca4" in P.roles)
Dennis (Cerbos)
sdktr
09/27/2024, 9:44 AMDennis (Cerbos)
P.attr.tenants
, where the key is the tenant ID (GUID), and the value is the tenant’s name. Then, you can collect all the tenant names.
tenantNames: P.roles.map(id, P.attr.tenants[id])
I assumed there were many names because P.roles
is a list.
Another assumption is that there are entries in P.attr.tenants
for every key from the P.roles
list.Dennis (Cerbos)
sdktr
09/27/2024, 5:20 PMDennis (Cerbos)
Stefan de Kooter
10/01/2024, 3:21 PM{
"apiVersion": "<http://api.cerbos.dev/v1|api.cerbos.dev/v1>",
"exportVariables": {
"name": "tenantmapping",
"definitions": {
"tenantmap": {
"tenant1guid": "tenant1name",
"tenant2guid": "tenant2name"
}
}
}
Dennis (Cerbos)
apiVersion: api.cerbos.dev/v1
exportVariables:
name: tenantmapping
definitions:
tenantmap: >
{"tenant1guid": "tenant1name",
"tenant2guid": "tenant2name"}
Stefan de Kooter
10/02/2024, 2:24 PM- name: device_mgmt_read
parentRoles:
- default
condition:
match:
expr: R.attr.Tenant in V.tenantNames
apiVersion: api.cerbos.dev/v1
exportVariables:
name: tenantmapping
definitions:
tenantmap: >
{"1111-1111": "tenant1",
"2222-2222": "tenant2"}
tenantNames: P.roles.map(id, V.tenantmap[id])
Dennis (Cerbos)
P.roles
list that doesn’t exist in the V.tenantmap
, so the tenantNames
expression fails to evaluate.
You can re-write this expression as P.roles.filter(r, r in V.tenantmap).map(id, V.tenantmap[id])
.
I debug by replacing expressions with the expected value or running cerbos repl
.Stefan de Kooter
10/04/2024, 9:28 PM