Rego graph.reachable not printing leaf nodes #661
-
I'm not totally certain if this is a bug or "working as designed". I'm having a lot of trouble getting The problem seems to be that
results with just However I can't find a way to get Trivial ExampleGoalI want to evaluate the set of all permissions in a role Data{
"relations": {
"roles": {
"role:admin": {
"grants": ["permission:edit", "role:viewer"]
},
"role:viewer": {
"organizations": "organization:acme",
"grants": ["permission:view", "role:other"]
}
}
}
} Policypackage foo
# In the real world examples I have many similar rules for: inherits_from[] contains if
inherits_from[role_id] contains other if {
some role_id, role_details in data.relations.roles
some other in role_details.grants
}
effective_permissions = graph.reachable(inherits_from, {"role:admin"}) Actual result{
"effective_subjects": [
"role:admin",
"role:viewer"
],
"inherits_from": {
"role:admin": [
"permission:edit",
"role:viewer"
],
"role:viewer": [
"permission:view",
"role:other"
]
}
} Desired result "effective_subjects": [
"role:admin",
"role:viewer",
"permission:edit",
"permission:view"
], ... |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 5 replies
-
Hey, thanks for the clear question. This is a good one. Graphs passed to graph.reachable need to be a list of all nodes and the other nodes they have edges to. This list of edges might be an empty list. I would set it up more like this: package foo
# nodes is a set of unique roles and grant names
nodes contains node if {
some role, role_data in data.relations.roles
grant_names := {n | some n in role_data.grants}
# a node is both the role itself and all the grant names
some node in (grant_names | {role})
}
inherits_from_graph[node] := edges if {
some node in nodes
edges := {e | some e in data.relations.roles[node].grants}
}
effective_permissions := graph.reachable(inherits_from_graph, {"role:admin"}) I think the desired output is:
Since, |
Beta Was this translation helpful? Give feedback.
Hey, thanks for the clear question. This is a good one.
Graphs passed to graph.reachable need to be a list of all nodes and the other nodes they have edges to. This list of edges might be an empty list.
I would set it up more like this: