Closed imbgar closed 2 months ago
any traction here?
@imbgar Can you try the same with below constaint to see if it works?
apiVersion: constraints.gatekeeper.sh/v1beta1
kind: UserPriorityClassBoundsTest
metadata:
name: userpriorityclassboundstest
spec:
enforcementAction: deny
match:
kinds:
- apiGroups:
- "scheduling.k8s.io"
kinds:
- PriorityClass
In both the provided examples of Constraints
, apiGroups
for PriorityClass
is not used correctly.
In my testing I was able to use below constraint for required_label policy to deny PriorityClass
that does not have the required label.
apiVersion: constraints.gatekeeper.sh/v1beta1
kind: K8sRequiredLabels
metadata:
name: pod-must-have-gk
spec:
match:
kinds:
- apiGroups:
- "scheduling.k8s.io"
kinds:
- PriorityClass
parameters:
message: "All namespaces must have an `owner` label that points to your company username"
labels:
- key: owner
allowedRegex: "^[a-zA-Z]+.agilebank.demo$"
based on the investigation, issue might be something else then "Gatekeeper constraints not correctly evaluating PriorityClass objects". Most likey the issue is misconfiguration of constraint. If not there might be bug in the rego code. I am removing the bug label for now.
@imbgar let me know if the constraint
suggested in above comment does not work, we can investigate further.
cc: @msarfaty
In both the provided examples of Constraints, apiGroups for PriorityClass is not used correctly.
Hi @JaydipGabani. Thanks for taking the time to debug this. I verified that the constraint is misconfigured.
Specifically, the value of apiGroups
in spec.match.kinds
is incorrect. Upon setting this to scheduling.k8s.io
, the constraint starts getting applied to all PriorityClass
resources.
I believe we can close this issue.
What steps did you take and what happened: I have a gatekeeper deployment that correctly evaluates policies for other kinds, but not
PriorityClass
.gatekeeper
via Argo with a manifest like this(slightly modified for obscurity):ValidatingWebhookConfiguration
ConstraintTemplate
based on this manifest withkubectl apply -f
Constraint
withkubectl apply -f
also tried with the following
match
condition in theConstraint
PriorityClass
object withkubectl apply -f
Describe the constraint
What did you expect to happen: I expect the violation to be caught,
AdmissionReview
denied, and themsg
to be logged back to the me when I runkubectl apply -f
What am I doing wrong? Why is Gatekeeper not evaluating
PriorityClass
objects? My policies for namespaced objects likeDeployment
,StatefulSet
,Pod
, etc work fine.Environment:
v3.16.3
kubectl version
):