Adding logs on policy failure #132
-
Hello there, I would like to know if there are some ways we can add logs when a policy fails. For instance a simple rule like below
I read about Addding a snippet on what exactly I am looking for from another programming langurage -
Any ideas on how we can have such a functionality? I have tried these -
|
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
The Finally, a pretty common approach is to use partial rules that buid sets, for which you can provide a reason as to why the rule "failed" - i.e. why it was denied. Something like: decision := {
"allow": count(deny) == 0,
"reason": concat(" | ", deny),
}
deny["User must be admin"] {
not "admin" in input.user.roles
}
# more deny rules here |
Beta Was this translation helpful? Give feedback.
The
print
function is included in OPA for debugging purposes only, and it should not be used as a "logger". Use decision logging if you want to log the decisions OPA takes, which includes the input of the request. If you want to drill down to where rule evaluation stopped in a debugging context, you could either look into tracing, or simply move the print event to the validate rule as you did in your last example. That'll give you the opportunity to at least derive where printing "stops" and what is likely the cause of evaluation to fail. In tests, the coverage feature could also be useful for determining what lines are evaluated and not.Finally, a pretty common approach is to use partia…