You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Update the Rego validation logic to parse the .rego policy file which has imported another .rego function from different packages.
Example:
# ./rego/k8s/check_cpu_limits.rego# policy to check if resource limits are defined in Deploymentpackage validate_k8s
import rego.v1
import data.k8s.common as lib # importing a .rego function from different package
check_cpu_limits[msg]{
input.kind =="Deployment"
c:= input.spec.template.spec.containers[i]
not lib.valid_key(c.resources.limits,"cpu") # using the `valid_key` func from `lib` package
msg:="CPU Limits are set for Deployment"
}
Now package is defined in different package:
# ./rego/common.rego# rego function to be used in other policiespackage k8s.common # Package definition that needs to be imported in other policiesimport future.keywords
valid_key(obj, key) {
_ = obj[key]
not is_null(obj[key])
} else =false {
true
}
The text was updated successfully, but these errors were encountered:
santoshkal
changed the title
Update the Rdego validation when functions are imported in a policy
Update the Rego validation when functions are imported in a policy
Jun 18, 2024
Update the Rego validation logic to parse the
.rego
policy file which has imported another.rego
function from different packages.Example:
Now package is defined in different package:
The text was updated successfully, but these errors were encountered: