1
0
Fork 0
mirror of https://github.com/kyverno/kyverno.git synced 2025-04-18 02:06:52 +00:00

feat: skip schema validation for CRD ()

Signed-off-by: ShutingZhao <shuting@nirmata.com>
This commit is contained in:
shuting 2023-07-21 06:02:27 +08:00 committed by GitHub
parent f905f90422
commit 69cb254e53
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 73 additions and 2 deletions
pkg/openapi
test/conformance/kuttl/policy-validation/cluster-policy/schema-validation-crd

View file

@ -133,11 +133,20 @@ func (o *manager) ValidatePolicyMutation(policy kyvernov1.PolicyInterface) error
}
for kind, rules := range kindToRules {
if kind == "CustomResourceDefinition" {
continue
}
newPolicy := policy.CreateDeepCopy()
spec := newPolicy.GetSpec()
spec.SetRules(rules)
k, _ := o.gvkToDefinitionName.Get(kind)
d, _ := o.definitions.Get(k)
k, ok := o.gvkToDefinitionName.Get(kind)
if !ok {
continue
}
d, ok := o.definitions.Get(k)
if !ok {
continue
}
resource, _ := o.generateEmptyResource(d).(map[string]interface{})
if len(resource) == 0 {
o.logger.V(2).Info("unable to validate resource. OpenApi definition not found", "kind", kind)

View file

@ -0,0 +1,42 @@
apiVersion: kyverno.io/v1
kind: ClusterPolicy
metadata:
annotations:
policies.kyverno.io/category: Security
policies.kyverno.io/description: 'This policy mutates any namespace-scoped Custom
Resource Definition created by the subjects in the xteam Azure AD group
and adds the label "createdByXteam: true".'
policies.kyverno.io/subject: RBAC
policies.kyverno.io/title: Mutate Namespace-Scoped CRDs for xteam aad
group
policy.reporter.kyverno.io/minimal: minimal
generation: 1
labels:
aws.cdk.eks/prune-c8b5941ff5f4fe911c5ee96472fda3d1f9866734a7: ""
name: mutate-xteam-namespace-scoped-crds
spec:
background: false
rules:
- match:
all:
- resources:
kinds:
- CustomResourceDefinition
subjects:
- kind: Group
name: aad:9b9had99-6k66-2222-9999-8aadb888e888
mutate:
patchStrategicMerge:
metadata:
labels:
createdByXteam: "true"
name: mutate-xteams-crd-creation
preconditions:
all:
- key: '{{request.operation}}'
operator: Equals
value: CREATE
- key: '{{ request.object.spec.scope }}'
operator: Equals
value: Namespaced
validationFailureAction: audit

View file

@ -0,0 +1,11 @@
## Description
This test ensures the schema validation is skipped for CustomResourceDefinition.
## Expected Behavior
The Pod creation should be allowed.
## Reference Issue(s)
https://github.com/kyverno/kyverno/issues/7844

View file

@ -0,0 +1,9 @@
apiVersion: kyverno.io/v1
kind: ClusterPolicy
metadata:
name: mutate-xteam-namespace-scoped-crds
status:
conditions:
- reason: Succeeded
status: "True"
type: Ready