mirror of
https://github.com/kyverno/kyverno.git
synced 2025-03-31 03:45:17 +00:00
update format
This commit is contained in:
parent
443619757e
commit
a30b8a604d
16 changed files with 21 additions and 21 deletions
|
@ -87,8 +87,8 @@ func validatePatterns(resource unstructured.Unstructured, rule kyverno.Rule) (re
|
||||||
// rule application failed
|
// rule application failed
|
||||||
glog.V(4).Infof("Validation rule '%s' failed at '%s' for resource %s/%s/%s. %s: %v", rule.Name, path, resource.GetKind(), resource.GetNamespace(), resource.GetName(), rule.Validation.Message, err)
|
glog.V(4).Infof("Validation rule '%s' failed at '%s' for resource %s/%s/%s. %s: %v", rule.Name, path, resource.GetKind(), resource.GetNamespace(), resource.GetName(), rule.Validation.Message, err)
|
||||||
response.Success = false
|
response.Success = false
|
||||||
response.Message = fmt.Sprintf("Validation error: %s\nValidation rule '%s' failed at path '%s' for %s/%s/%s.",
|
response.Message = fmt.Sprintf("Validation error for %s/%s/%s: %s\nValidation rule '%s' failed at path '%s'.",
|
||||||
rule.Validation.Message, rule.Name, path, resource.GetKind(), resource.GetNamespace(), resource.GetName())
|
resource.GetKind(), resource.GetNamespace(), resource.GetName(), rule.Validation.Message, rule.Name, path)
|
||||||
return response
|
return response
|
||||||
}
|
}
|
||||||
// rule application succesful
|
// rule application succesful
|
||||||
|
|
|
@ -1818,7 +1818,7 @@ func TestValidate_image_tag_fail(t *testing.T) {
|
||||||
assert.NilError(t, err)
|
assert.NilError(t, err)
|
||||||
msgs := []string{
|
msgs := []string{
|
||||||
"Validation rule 'validate-tag' succeeded.",
|
"Validation rule 'validate-tag' succeeded.",
|
||||||
"Validation error: imagePullPolicy 'Always' required with tag 'latest'\nValidation rule 'validate-latest' failed at path '/spec/containers/0/imagePullPolicy/' for Pod//myapp-pod.",
|
"Validation error for Pod//myapp-pod: imagePullPolicy 'Always' required with tag 'latest'\nValidation rule 'validate-latest' failed at path '/spec/containers/0/imagePullPolicy/'.",
|
||||||
}
|
}
|
||||||
er := Validate(policy, *resourceUnstructured)
|
er := Validate(policy, *resourceUnstructured)
|
||||||
for index, r := range er.PolicyResponse.Rules {
|
for index, r := range er.PolicyResponse.Rules {
|
||||||
|
@ -2073,7 +2073,7 @@ func TestValidate_host_network_port(t *testing.T) {
|
||||||
resourceUnstructured, err := ConvertToUnstructured(rawResource)
|
resourceUnstructured, err := ConvertToUnstructured(rawResource)
|
||||||
assert.NilError(t, err)
|
assert.NilError(t, err)
|
||||||
er := Validate(policy, *resourceUnstructured)
|
er := Validate(policy, *resourceUnstructured)
|
||||||
msgs := []string{"Validation error: Host network and port are not allowed\nValidation rule 'validate-host-network-port' failed at path '/spec/containers/0/ports/0/hostPort/' for Pod//nginx-host-network."}
|
msgs := []string{"Validation error for Pod//nginx-host-network: Host network and port are not allowed\nValidation rule 'validate-host-network-port' failed at path '/spec/containers/0/ports/0/hostPort/'."}
|
||||||
|
|
||||||
for index, r := range er.PolicyResponse.Rules {
|
for index, r := range er.PolicyResponse.Rules {
|
||||||
assert.Equal(t, r.Message, msgs[index])
|
assert.Equal(t, r.Message, msgs[index])
|
||||||
|
@ -2250,7 +2250,7 @@ func TestValidate_anchor_arraymap_fail(t *testing.T) {
|
||||||
resourceUnstructured, err := ConvertToUnstructured(rawResource)
|
resourceUnstructured, err := ConvertToUnstructured(rawResource)
|
||||||
assert.NilError(t, err)
|
assert.NilError(t, err)
|
||||||
er := Validate(policy, *resourceUnstructured)
|
er := Validate(policy, *resourceUnstructured)
|
||||||
msgs := []string{"Validation error: Host path '/var/lib/' is not allowed\nValidation rule 'validate-host-path' failed at path '/spec/volumes/0/hostPath/path/' for Pod//image-with-hostpath."}
|
msgs := []string{"Validation error for Pod//image-with-hostpath: Host path '/var/lib/' is not allowed\nValidation rule 'validate-host-path' failed at path '/spec/volumes/0/hostPath/path/'."}
|
||||||
|
|
||||||
for index, r := range er.PolicyResponse.Rules {
|
for index, r := range er.PolicyResponse.Rules {
|
||||||
assert.Equal(t, r.Message, msgs[index])
|
assert.Equal(t, r.Message, msgs[index])
|
||||||
|
@ -2463,7 +2463,7 @@ func TestValidate_anchor_map_found_invalid(t *testing.T) {
|
||||||
resourceUnstructured, err := ConvertToUnstructured(rawResource)
|
resourceUnstructured, err := ConvertToUnstructured(rawResource)
|
||||||
assert.NilError(t, err)
|
assert.NilError(t, err)
|
||||||
er := Validate(policy, *resourceUnstructured)
|
er := Validate(policy, *resourceUnstructured)
|
||||||
msgs := []string{"Validation error: pod: validate run as non root user\nValidation rule 'pod rule 2' failed at path '/spec/securityContext/runAsNonRoot/' for Pod//myapp-pod."}
|
msgs := []string{"Validation error for Pod//myapp-pod: pod: validate run as non root user\nValidation rule 'pod rule 2' failed at path '/spec/securityContext/runAsNonRoot/'."}
|
||||||
|
|
||||||
for index, r := range er.PolicyResponse.Rules {
|
for index, r := range er.PolicyResponse.Rules {
|
||||||
assert.Equal(t, r.Message, msgs[index])
|
assert.Equal(t, r.Message, msgs[index])
|
||||||
|
@ -2847,7 +2847,7 @@ func TestValidate_negationAnchor_deny(t *testing.T) {
|
||||||
resourceUnstructured, err := ConvertToUnstructured(rawResource)
|
resourceUnstructured, err := ConvertToUnstructured(rawResource)
|
||||||
assert.NilError(t, err)
|
assert.NilError(t, err)
|
||||||
er := Validate(policy, *resourceUnstructured)
|
er := Validate(policy, *resourceUnstructured)
|
||||||
msgs := []string{"Validation error: Host path is not allowed\nValidation rule 'validate-host-path' failed at path '/spec/volumes/0/hostPath/' for Pod//image-with-hostpath."}
|
msgs := []string{"Validation error for Pod//image-with-hostpath: Host path is not allowed\nValidation rule 'validate-host-path' failed at path '/spec/volumes/0/hostPath/'."}
|
||||||
|
|
||||||
for index, r := range er.PolicyResponse.Rules {
|
for index, r := range er.PolicyResponse.Rules {
|
||||||
assert.Equal(t, r.Message, msgs[index])
|
assert.Equal(t, r.Message, msgs[index])
|
||||||
|
|
|
@ -14,5 +14,5 @@ expected:
|
||||||
rules:
|
rules:
|
||||||
- name: prevent-mounting-default-serviceaccount
|
- name: prevent-mounting-default-serviceaccount
|
||||||
type: Validation
|
type: Validation
|
||||||
message: "Validation error: Prevent mounting of default service account\nValidation rule 'prevent-mounting-default-serviceaccount' failed at path '/spec/serviceAccountName/' for Pod//pod-with-default-sa."
|
message: "Validation error for Pod//pod-with-default-sa: Prevent mounting of default service account\nValidation rule 'prevent-mounting-default-serviceaccount' failed at path '/spec/serviceAccountName/'."
|
||||||
success: false
|
success: false
|
|
@ -15,5 +15,5 @@ expected:
|
||||||
rules:
|
rules:
|
||||||
- name: validate-selinux-options
|
- name: validate-selinux-options
|
||||||
type: Validation
|
type: Validation
|
||||||
message: "Validation error: SELinux level is required\nValidation rule 'validate-selinux-options' failed at path '/spec/containers/0/securityContext/seLinuxOptions/' for Pod/default/busybox-selinux."
|
message: "Validation error for Pod/default/busybox-selinux: SELinux level is required\nValidation rule 'validate-selinux-options' failed at path '/spec/containers/0/securityContext/seLinuxOptions/'."
|
||||||
success: false
|
success: false
|
|
@ -18,5 +18,5 @@ expected:
|
||||||
success: true
|
success: true
|
||||||
- name: image-tag-not-latest
|
- name: image-tag-not-latest
|
||||||
type: Validation
|
type: Validation
|
||||||
message: "Validation error: Using 'latest' image tag is restricted. Set image tag to a specific version\nValidation rule 'image-tag-not-latest' failed at path '/spec/containers/0/image/' for Pod//myapp-pod."
|
message: "Validation error for Pod//myapp-pod: Using 'latest' image tag is restricted. Set image tag to a specific version\nValidation rule 'image-tag-not-latest' failed at path '/spec/containers/0/image/'."
|
||||||
success: false
|
success: false
|
||||||
|
|
|
@ -16,7 +16,7 @@ expected:
|
||||||
rules:
|
rules:
|
||||||
- name: check-default-namespace
|
- name: check-default-namespace
|
||||||
type: Validation
|
type: Validation
|
||||||
message: "Validation error: Using 'default' namespace is restricted\nValidation rule 'check-default-namespace' failed at path '/metadata/namespace/' for Pod/default/myapp-pod."
|
message: "Validation error for Pod/default/myapp-pod: Using 'default' namespace is restricted\nValidation rule 'check-default-namespace' failed at path '/metadata/namespace/'."
|
||||||
success: false
|
success: false
|
||||||
- name: check-namespace-exist
|
- name: check-namespace-exist
|
||||||
type: Validation
|
type: Validation
|
||||||
|
|
|
@ -14,5 +14,5 @@ expected:
|
||||||
rules:
|
rules:
|
||||||
- name: validate-docker-sock-mount
|
- name: validate-docker-sock-mount
|
||||||
type: Validation
|
type: Validation
|
||||||
message: "Validation error: Use of the Docker Unix socket is not allowed\nValidation rule 'validate-docker-sock-mount' failed at path '/spec/volumes/' for Pod//pod-with-docker-sock-mount."
|
message: "Validation error for Pod//pod-with-docker-sock-mount: Use of the Docker Unix socket is not allowed\nValidation rule 'validate-docker-sock-mount' failed at path '/spec/volumes/'."
|
||||||
success: false
|
success: false
|
|
@ -14,5 +14,5 @@ expected:
|
||||||
rules:
|
rules:
|
||||||
- name: deny-use-of-host-fs
|
- name: deny-use-of-host-fs
|
||||||
type: Validation
|
type: Validation
|
||||||
message: "Validation error: Host path is not allowed\nValidation rule 'deny-use-of-host-fs' failed at path '/spec/volumes/0/hostPath/' for Pod//image-with-hostpath."
|
message: "Validation error for Pod//image-with-hostpath: Host path is not allowed\nValidation rule 'deny-use-of-host-fs' failed at path '/spec/volumes/0/hostPath/'."
|
||||||
success: false
|
success: false
|
|
@ -14,5 +14,5 @@ expected:
|
||||||
rules:
|
rules:
|
||||||
- name: validate-host-network-hostport
|
- name: validate-host-network-hostport
|
||||||
type: Validation
|
type: Validation
|
||||||
message: "Validation error: Defining hostNetwork and hostPort are not allowed\nValidation rule 'validate-host-network-hostport' failed at path '/spec/containers/0/ports/0/hostPort/' for Pod//nginx-host-network."
|
message: "Validation error for Pod//nginx-host-network: Defining hostNetwork and hostPort are not allowed\nValidation rule 'validate-host-network-hostport' failed at path '/spec/containers/0/ports/0/hostPort/'."
|
||||||
success: false
|
success: false
|
|
@ -14,5 +14,5 @@ expected:
|
||||||
rules:
|
rules:
|
||||||
- name: validate-hostpid-hostipc
|
- name: validate-hostpid-hostipc
|
||||||
type: Validation
|
type: Validation
|
||||||
message: "Validation error: Disallow use of host's pid namespace and host's ipc namespace\nValidation rule 'validate-hostpid-hostipc' failed at path '/spec/hostIPC/' for Pod//nginx-with-hostpid."
|
message: "Validation error for Pod//nginx-with-hostpid: Disallow use of host's pid namespace and host's ipc namespace\nValidation rule 'validate-hostpid-hostipc' failed at path '/spec/hostIPC/'."
|
||||||
success: false
|
success: false
|
|
@ -13,5 +13,5 @@ expected:
|
||||||
rules:
|
rules:
|
||||||
- name: disallow-node-port
|
- name: disallow-node-port
|
||||||
type: Validation
|
type: Validation
|
||||||
message: "Validation error: Disallow service of type NodePort\nValidation rule 'disallow-node-port' failed at path '/spec/type/' for Service//my-service."
|
message: "Validation error for Service//my-service: Disallow service of type NodePort\nValidation rule 'disallow-node-port' failed at path '/spec/type/'."
|
||||||
success: false
|
success: false
|
|
@ -14,5 +14,5 @@ expected:
|
||||||
rules:
|
rules:
|
||||||
- name: check-probes
|
- name: check-probes
|
||||||
type: Validation
|
type: Validation
|
||||||
message: "Validation error: Liveness and readiness probes are required\nValidation rule 'check-probes' failed at path '/spec/containers/0/livenessProbe/' for Pod//myapp-pod."
|
message: "Validation error for Pod//myapp-pod: Liveness and readiness probes are required\nValidation rule 'check-probes' failed at path '/spec/containers/0/livenessProbe/'."
|
||||||
success: false
|
success: false
|
||||||
|
|
|
@ -14,5 +14,5 @@ expected:
|
||||||
rules:
|
rules:
|
||||||
- name: check-resource-request-limit
|
- name: check-resource-request-limit
|
||||||
type: Validation
|
type: Validation
|
||||||
message: "Validation error: CPU and memory resource requests and limits are required\nValidation rule 'check-resource-request-limit' failed at path '/spec/containers/0/resources/limits/cpu/' for Pod//myapp-pod."
|
message: "Validation error for Pod//myapp-pod: CPU and memory resource requests and limits are required\nValidation rule 'check-resource-request-limit' failed at path '/spec/containers/0/resources/limits/cpu/'."
|
||||||
success: false
|
success: false
|
||||||
|
|
|
@ -14,5 +14,5 @@ expected:
|
||||||
rules:
|
rules:
|
||||||
- name: validate-readonly-rootfilesystem
|
- name: validate-readonly-rootfilesystem
|
||||||
type: Validation
|
type: Validation
|
||||||
message: "Validation error: Container require read-only rootfilesystem\nValidation rule 'validate-readonly-rootfilesystem' failed at path '/spec/containers/0/securityContext/readOnlyRootFilesystem/' for Pod//ghost-with-readonly-rootfilesystem."
|
message: "Validation error for Pod//ghost-with-readonly-rootfilesystem: Container require read-only rootfilesystem\nValidation rule 'validate-readonly-rootfilesystem' failed at path '/spec/containers/0/securityContext/readOnlyRootFilesystem/'."
|
||||||
success: false
|
success: false
|
|
@ -15,5 +15,5 @@ expected:
|
||||||
rules:
|
rules:
|
||||||
- name: validate-container-capablities
|
- name: validate-container-capablities
|
||||||
type: Validation
|
type: Validation
|
||||||
message: "Validation error: Allow certain linux capability\nValidation rule 'validate-container-capablities' failed at path '/spec/containers/0/securityContext/capabilities/add/0/' for Pod//add-capabilities."
|
message: "Validation error for Pod//add-capabilities: Allow certain linux capability\nValidation rule 'validate-container-capablities' failed at path '/spec/containers/0/securityContext/capabilities/add/0/'."
|
||||||
success: false
|
success: false
|
|
@ -15,5 +15,5 @@ expected:
|
||||||
rules:
|
rules:
|
||||||
- name: allow-portrange-with-sysctl
|
- name: allow-portrange-with-sysctl
|
||||||
type: Validation
|
type: Validation
|
||||||
message: "Validation error: Allowed port range is from 1024 to 65535\nValidation rule 'allow-portrange-with-sysctl' failed at path '/spec/securityContext/sysctls/0/value/' for Pod//nginx."
|
message: "Validation error for Pod//nginx: Allowed port range is from 1024 to 65535\nValidation rule 'allow-portrange-with-sysctl' failed at path '/spec/securityContext/sysctls/0/value/'."
|
||||||
success: false
|
success: false
|
Loading…
Add table
Reference in a new issue