More generally, Rego does not allow OR-ing statements in the same function. Using any()
works well for simple cases, but can become unwieldy for complex ones so it is considered an antipattern.
Instead, Rego uses incremental rules, where every statement within each Rule is AND-ed together, and rules of the same name are OR-ed together.
Consider the following deny
rule. In short, it says that we will deny the request if at least one of:
- The user is not an admin, or
- Today is Sunday.
deny {
input.role != "admin"
}
deny {
time.weekday(time.now_ns()) == "Sunday"
}
This would only allow requests to the admin
role on days other than Sunday. If instead we said:
deny {
input.role != "admin"
time.weekday(time.now_ns()) == "Sunday"
}
We would then only deny requests from non-admin
roles on Sunday. Requests from admin
would always be allowed.