Bulk authorize multiple requests in a single OPA call #539
Replies: 4 comments 17 replies
-
Something like this perhaps? https://play.openpolicyagent.org/p/JihmhhAuhg |
Beta Was this translation helpful? Give feedback.
-
I finally got around to tinkering with the profiler and I'm not seeing the results I expected. For the following policy and input: The profiler shows lines 17, 18, and 27 being evaluated 20, 30, and 30 times respectively. Also, if I increase the number of items in the input.requests array by 1, the number of evaluations increase to 24, 36, and 36 respectively. While the input is changing as bulk_decisions iterates over input.requests the token being passed in isn't changing. Is there a way to further optimize the policy so that the number of evaluations for these lines does not increase as the number of items in the input.requests array grows? profile output:
|
Beta Was this translation helpful? Give feedback.
-
Thanks @anderseknert! I was actually wondering if "with" was more meant for testing purposes. I finally got around to taking the Open Policy Authoring and OPA Performance online courses from Styra. Great content in both courses and I thought they were very helpful in understanding some features of OPA. I'll work on creating a function to see if it helps with the number of evaluations. |
Beta Was this translation helpful? Give feedback.
-
I just noticed that the behavior of using an array of sets is different than what I was expecting. For instance, if two rules defined in the array of sets are evaluated and one of the rules evaluates to true and the other to false it seems OPA returns a value of undefined for the function. For example, for the following policy if lines 66-71 are included, the value of function_test is undefined. If those lines are commented out, the value of function_test is [true]. https://play.openpolicyagent.org/p/NINPG1WC3i Is this the correct way to iterate over an array of sets containing rules to receive the same behavior as if the rules were defined outside of the function in the root of policy? The earlier example shared by @charlieegan3 only included a single rule so I am looking to modify the syntax to support multiple rules. |
Beta Was this translation helpful? Give feedback.
-
We currently define rego rules and input in the following format to perform authorization for our REST API.
Rules:
...
Input:
Response:
We would also like to be able to bulk authorize an array of requests (i.e permission & uri) using the existing rego rules and possibly some additional rules in a single call to OPA using the following input:
Input:
And receive a response that looks something like the following:
Is this possible in OPA? If so, can you point me to an example that I can refer to?
Thanks in advance!
Beta Was this translation helpful? Give feedback.
All reactions