Gatekeeper Rego for "images must come from our registry" blocks images from `registry.acme.com.evil.io` correctly, but allows `registry.acme.comevil.io/x`
AdvancedTroubleshootingKubernetes admission control and Pod Security
Answer
Likely causes → The policy uses startswith(image, "registry.acme.com") without a trailing /, so lookalike hostnames pass.
Diagnose → Write a unit test with lookalike hostnames: opa test ./policies -v.
Fix →
violation[{"msg": msg}] {
c := input_containers[_]
not startswith(c.image, "registry.acme.com/")
msg := sprintf("image %v not from approved registry", [c.image])
}
Also include initContainers and ephemeralContainers in input_containers.
Prevent → Policy unit tests for bypass cases, reviewed like code.
More on Kubernetes admission control and Pod Security
`Error from server: admission webhook "validate.kyverno.svc-fail" denied the request: policy Deployment/prod/api for resource violation: require-run-as-nonroot`BeginnerPods do not appear, but `kubectl apply` of the Deployment succeededBeginner`pods "api-7d9" is forbidden: violates PodSecurity "restricted:latest": allowPrivilegeEscalation != false, unrestricted capabilities, seccompProfile`BeginnerEnabling `enforce=restricted` on a namespace did not evict the existing non-compliant podsBeginner`Error from server (InternalError): Internal error occurred: failed calling webhook "validation.gatekeeper.sh": ... context deadline exceeded` blocks every deployIntermediateKyverno is down and now the whole cluster, including Kyverno's own namespace, cannot be fixed because writes are rejectedAdvanced