Detect if rule exists and run it #597
-
I'm in the process of trying to create an RBAC policy interpreter. Part of this is that a permission can have an additional assertion attached to it. In the rule processing I want to be able to detect if a rule that is named in the policy definition exists, and if it does, then evaluate it. Some code for context: rbac00005roles.json
rbac00005permissions.json
rbac00005rules.rego
the
Is this possible in OPA? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 3 replies
-
You can use dynamic policy composition, as explained here to dynamically refer to rules in your policy.
Playground link |
Beta Was this translation helpful? Give feedback.
There is no
assertion
attribute on the admin role. This makes theassertions[p.assertion]
statement fail, asp.assertion
is undefined. You can solve this a number of ways; like adding an assertion to the admin role that is always true, or by wrapping theassertions[*]
call in a function that handles this scenario.E.g.;
and then call
assert(p)
in your allow rule.https://play.openpolicyagent.org/p/E0WY4deUGc