mirror of
https://github.com/kyverno/kyverno.git
synced 2025-03-29 02:45:06 +00:00
fix: return engine responses without checking TestResult.rule since it is empty in case of VAPs (#8251)
Signed-off-by: Mariam Fahmy <mariam.fahmy@nirmata.com> Co-authored-by: Charles-Edouard Brétéché <charles.edouard@nirmata.com>
This commit is contained in:
parent
151d0b3298
commit
4da72e3758
4 changed files with 89 additions and 5 deletions
|
@ -211,12 +211,17 @@ func lookupEngineResponses(test api.TestResults, resourceName string, responses
|
|||
|
||||
func lookupRuleResponses(test api.TestResults, responses ...engineapi.RuleResponse) []engineapi.RuleResponse {
|
||||
var matches []engineapi.RuleResponse
|
||||
for _, response := range responses {
|
||||
rule := response.Name()
|
||||
if rule != test.Rule && rule != "autogen-"+test.Rule && rule != "autogen-cronjob-"+test.Rule {
|
||||
continue
|
||||
// Since there are no rules in case of validating admission policies, responses are returned without checking rule names.
|
||||
if test.IsValidatingAdmissionPolicy {
|
||||
matches = responses
|
||||
} else {
|
||||
for _, response := range responses {
|
||||
rule := response.Name()
|
||||
if rule != test.Rule && rule != "autogen-"+test.Rule && rule != "autogen-cronjob-"+test.Rule {
|
||||
continue
|
||||
}
|
||||
matches = append(matches, response)
|
||||
}
|
||||
matches = append(matches, response)
|
||||
}
|
||||
return matches
|
||||
}
|
||||
|
|
|
@ -0,0 +1,48 @@
|
|||
apiVersion: apps/v1
|
||||
kind: Deployment
|
||||
metadata:
|
||||
name: deployment-pass
|
||||
spec:
|
||||
replicas: 1
|
||||
selector:
|
||||
matchLabels:
|
||||
app: nginx
|
||||
template:
|
||||
metadata:
|
||||
labels:
|
||||
app: nginx
|
||||
spec:
|
||||
containers:
|
||||
- name: nginx-server
|
||||
image: nginx
|
||||
volumeMounts:
|
||||
- name: temp
|
||||
mountPath: /scratch
|
||||
volumes:
|
||||
- name: temp
|
||||
emptyDir: {}
|
||||
---
|
||||
apiVersion: apps/v1
|
||||
kind: Deployment
|
||||
metadata:
|
||||
name: deployment-fail
|
||||
spec:
|
||||
replicas: 1
|
||||
selector:
|
||||
matchLabels:
|
||||
app: nginx
|
||||
template:
|
||||
metadata:
|
||||
labels:
|
||||
app: nginx
|
||||
spec:
|
||||
containers:
|
||||
- name: nginx-server
|
||||
image: nginx
|
||||
volumeMounts:
|
||||
- name: udev
|
||||
mountPath: /data
|
||||
volumes:
|
||||
- name: udev
|
||||
hostPath:
|
||||
path: /etc/udev
|
|
@ -0,0 +1,15 @@
|
|||
apiVersion: admissionregistration.k8s.io/v1alpha1
|
||||
kind: ValidatingAdmissionPolicy
|
||||
metadata:
|
||||
name: disallow-host-path
|
||||
spec:
|
||||
failurePolicy: Fail
|
||||
matchConstraints:
|
||||
resourceRules:
|
||||
- apiGroups: ["apps"]
|
||||
apiVersions: ["v1"]
|
||||
operations: ["CREATE", "UPDATE"]
|
||||
resources: ["deployments"]
|
||||
validations:
|
||||
- expression: "!has(object.spec.template.spec.volumes) || object.spec.template.spec.volumes.all(volume, !has(volume.hostPath))"
|
||||
message: "HostPath volumes are forbidden. The field spec.template.spec.volumes[*].hostPath must be unset."
|
|
@ -0,0 +1,16 @@
|
|||
name: disallow-host-path-test
|
||||
policies:
|
||||
- disallow-host-path.yaml
|
||||
resources:
|
||||
- deployments.yaml
|
||||
results:
|
||||
- policy: disallow-host-path
|
||||
resource: deployment-pass
|
||||
isValidatingAdmissionPolicy: true
|
||||
kind: Deployment
|
||||
result: pass
|
||||
- policy: disallow-host-path
|
||||
resource: deployment-fail
|
||||
isValidatingAdmissionPolicy: true
|
||||
kind: Deployment
|
||||
result: fail
|
Loading…
Add table
Reference in a new issue