Skip to content
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

Update the Rego validation when functions are imported in a policy #105

Open
santoshkal opened this issue Jun 13, 2024 · 0 comments
Open

Comments

@santoshkal
Copy link
Collaborator

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 Deployment

package 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 policies

package k8s.common  # Package definition that needs to be imported in other policies

import future.keywords 

valid_key(obj, key) {
	_ = obj[key]
	not is_null(obj[key])
} else = false {
	true
}
@santoshkal 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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Backlog
Development

No branches or pull requests

1 participant