define rego rule which can check authorization on another REST endpoint #542
Replies: 5 comments 9 replies
-
From the policy looks like you're recursively calling the |
Beta Was this translation helpful? Give feedback.
-
Here is a simplified draft of the policy I am trying to write. |
Beta Was this translation helpful? Give feedback.
-
Thanks for sharing this. The input OPA gets is {
"request": {
"permission": "read",
"uri": "/files/files/456",
"user": "user1"
}
} Now given this input, OPA would need two more pieces of information 1) What is the parent of file Is there some way to expose this mapping? Assume it's a map for example, I would imagine graph builtins OPA has would be useful. |
Beta Was this translation helpful? Give feedback.
-
Hi @anderseknert , Yes, a file will have a single parent resource. However the parent resource may not be the root of the file hieararchy and may also have a parent resource associated with it, and so on. Our existing authorization service supports providing the parent resource in couple ways.
For example, we have a condition in one of our rules that looks like this: (case 1) And another condition which looks like this: (case 2) So far I've been trying to model the first case as I think it is the easier of the two to start with. In general, the file hierarchy is just one example of how the "isAuthorized" function is used in our existing authorization service. The function is used in other parts of our system to effectively delegate part of the authorization decision for a particular rule to another resource which the user may or may not have access to. |
Beta Was this translation helpful? Give feedback.
-
Circling back around here to add an example of how I propose to implement support for this functionality in Rego for completeness. https://play.openpolicyagent.org/p/7gQBVK0Ve4 There are comments in the policy that explain the approach. |
Beta Was this translation helpful? Give feedback.
-
Our existing authorization service supports defining a rule for a particular REST endpoint which can check if the requesting identity has access to another REST endpoint with a condition like the following:
isAuthorized('update', '/analyticsGateway/projects/0fd53308-1add-4e4a-805a-49b7766fb7d0')
I've attempted to port this functionality into rego in the following manner:
grant if { data.request.permission in ["update", "remove", "add", "read"] regex.match(
^/folders/folders/0f0a367a-2c26-4e38-8630-8708e8ff0b29/, data.request.uri) authenticated_user = true g := grant with data.request as { "request" : { "permission" : "update", "uri" : "/analyticsGateway/projects/0fd53308-1add-4e4a-805a-49b7766fb7d0" } } d := deny with data.request as { "request" : { "permission" : "update", "uri" : "/analyticsGateway/projects/0fd53308-1add-4e4a-805a-49b7766fb7d0" } } not d g }
However, this results in the following recursion error.
1 error occurred: policy.rego:6376: rego_recursion_error: rule data.sas.types.authz.grant is recursive: data.sas.types.authz.grant -> data.sas.types.authz.grant
Is there an alternative way to model this type of behavior in rego?
Beta Was this translation helpful? Give feedback.
All reactions