Reputation: 21
package kubernetes.admission
import data.kubernetes.namespaces
deny[msg] {
input.request.kind.kind == "Pod"
input.request.operation == "CREATE"
container := input.request.object.spec.containers[_]
[image_name, image_tag] := split(container.image, ":")
image_tag == "latest"
msg := sprintf("Invalid image tag")
}
kubectl create configmap registry-whitelist --from-file image-checker.rego
The default namespace in my current context is
opa
.
Pods with latest tags are created successfully and they are not rejected.
I followed these tips https://www.openpolicyagent.org/docs/latest/kubernetes-debugging/ .
So, it's expected that the created configmap registry-whitelist
has openpolicyagent.org/policy-status
as annotations, however it has <none>
as value, also I have checked logs of kube-mgmt
container however they didn't help me. The only interesting log i get is when i try to delete the configmap registry-whitelist
I can see the following log :
level=error msg="Failed to delete policy opa/registry-whitelist/image-checker.rego: code resource_not_found: storage_not_found_error: policy id "opa/registry-whitelist/image-checker.rego""
Upvotes: 1
Views: 467
Reputation: 21
Problem solved: actually my policy which is writen in rego had some errors this is why kube-mgmt took some time before adding the annotations to the new created configmap. After a while I found an annotation saying that my policy had errors .
Upvotes: 1