Open josephlim75 opened 2 months ago
@josephlim75 I think there is a bug in rego in the template. Try below template -
apiVersion: templates.gatekeeper.sh/v1beta1
kind: ConstraintTemplate
metadata:
name: k8sdenynamespacedeletion
spec:
crd:
spec:
names:
kind: K8sDenyNamespaceDeletion
targets:
- target: admission.k8s.gatekeeper.sh
rego: |
package k8sdenynamespacedeletion
violation[{"msg": msg, "details": {}}] {
input.review.kind.kind == "Namespace"
input.review.operation == "DELETE"
msg := "Deletion of namespace is not allowed. It is in the list of prohibited namespaces."
}
To enable validation of DELETE
requests, just set enableDeleteOperations
to true
.
What steps did you take and what happened: Not able to prevent namespace deletion. Below are my OPA Gatekeeper version and constrainttemplate.
What did you expect to happen: I expect when trying to delete a namespace, the constraint should prevent me from deleting.
Rego Template
Policy enforcement
Test Scenario
Scenario 1
Resuilt
Scenario 2
Resuilt
Error from server (InternalError): Internal error occurred: failed calling webhook "check-ignore-label.gatekeeper.sh": failed to call webhook: Post "https://gatekeeper-webhook-service.gatekeeper-system.svc:443/v1/admitlabel?timeout=3s": context deadline exceeded
Client Version: v1.28.7 Kustomize Version: v5.0.4-0.20230601165947-6ce0bf390ce3 Server Version: v1.27.16-eks-2f46c53