-
Notifications
You must be signed in to change notification settings - Fork 5
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix Evaluate logic #3
Conversation
@@ -20,18 +20,17 @@ import ( | |||
) | |||
|
|||
type EvalRego struct { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
would it make sense to move all structs to a different package?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually, If no complex business logic, putting the structs where they have been used is also a good idea.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
was only thinking to keep all data models in once place. This will help us in future to easy check the correct places instead of searching.
server/handle_policy_eval.go
Outdated
if err != nil { | ||
abortWithError(c, 500, err.Error()) | ||
return | ||
} | ||
|
||
c.JSON(200, gin.H{ | ||
"isAllow": cmd.Rego.IsAllow, | ||
"isSuccessful": decision, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
its better to define a struct for the return type as well.
@@ -32,18 +32,20 @@ Flags: | |||
-p, --port string The port of the HTTP server | |||
``` | |||
|
|||
## Eval a policy | |||
## Evaluate the input by a policy list |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is it possible to make policy-man more generic.. that it simply executes and returns results of all rules. And only in xpanse, we can build a limitation that the rego rules must contain allow/deny rules?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we do it like this, then the response of this API will not be a stable structure. and the Xpanse must deserialize the response and check the allow/deny rules itself.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok. Then we can provide two services. one with specific allow and deny.. and one with a generic one.
server/handle_policy_eval.go
Outdated
|
||
policyRegoEx := fmt.Sprintf("package policyman.auth\n\n%v", policyRego) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
do we need to append this? What I thought is, since we are loading the string fully, the rego must contain the package name already.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we let the users define the package name by themselves, we will not be able to be aware of which package to evaluate, or we must extract the package name from the rego files,
actually, this is an one-off policy here, the package name here is useless.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@iskey should we only then control if the package name already exists and overwrite it?
3c373d8
to
787aeff
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
related to eclipse-xpanse/xpanse#896
related to eclipse-xpanse/xpanse#900
Remove the
isAllow
from the request and response.As the opa will try to evaluate all the variables into the
bindings
, we just need to care about theallow
and thedeny
variables in the rego. If no such variables, this rego will be ignored.