1
0
Fork 0
mirror of https://github.com/kyverno/kyverno.git synced 2024-12-14 11:57:48 +00:00

fix: allow empty image (#6767)

Signed-off-by: Charles-Edouard Brétéché <charles.edouard@nirmata.com>
This commit is contained in:
Charles-Edouard Brétéché 2023-04-03 19:01:35 +02:00 committed by GitHub
parent 89928e286a
commit 4cf5903545
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 87 additions and 1 deletions

View file

@ -88,7 +88,7 @@ func extract(obj interface{}, path []string, keyPath, valuePath string, fields [
}
}
value, ok := output[valuePath].(string)
if !ok {
if !ok || strings.TrimSpace(value) == "" {
// the image may not be present
logging.V(4).Info("image information is not present", "pointer", pointer)
return nil

View file

@ -0,0 +1,6 @@
apiVersion: kuttl.dev/v1beta1
kind: TestStep
apply:
- policy.yaml
assert:
- policy-assert.yaml

View file

@ -0,0 +1,4 @@
apiVersion: kuttl.dev/v1beta1
kind: TestStep
apply:
- file: resource.yaml

View file

@ -0,0 +1,8 @@
## Description
This test creates a policy to verify images signature.
It then creates a `Deployment` that references an image with an empty string.
## Expected Behavior
The deployment should be created without error.

View file

@ -0,0 +1,9 @@
apiVersion: kyverno.io/v1
kind: ClusterPolicy
metadata:
name: keyed-basic-policy
status:
conditions:
- reason: Succeeded
status: "True"
type: Ready

View file

@ -0,0 +1,27 @@
apiVersion: kyverno.io/v1
kind: ClusterPolicy
metadata:
name: keyed-basic-policy
spec:
validationFailureAction: enforce
background: false
webhookTimeoutSeconds: 30
failurePolicy: Fail
rules:
- name: keyed-basic-rule
match:
any:
- resources:
kinds:
- Pod
verifyImages:
- imageReferences:
- '*'
attestors:
- entries:
- keys:
publicKeys: |-
-----BEGIN PUBLIC KEY-----
MFkwEwYHKoZIzj0CAQYIKoZIzj0DAQcDQgAE8nXRh950IZbRj8Ra/N9sbqOPZrfM
5/KAQN0/KjHcorm/J5yctVd7iEcnessRQjU917hmKO6JWVGHpDguIyakZA==
-----END PUBLIC KEY-----

View file

@ -0,0 +1,32 @@
apiVersion: apps/v1
kind: Deployment
metadata:
annotations:
image.openshift.io/triggers: '[{"from":{"kind":"ImageStreamTag","name":"httpd:latest","namespace":"example-namespace"},"fieldPath":"spec.template.spec.containers[?(@.name==\"httpd\")].image"}]'
openshift.io/generated-by: OpenShiftNewApp
labels:
app: httpd
app.kubernetes.io/component: httpd
app.kubernetes.io/instance: httpd
name: httpd
spec:
replicas: 1
selector:
matchLabels:
deployment: httpd
strategy: {}
template:
metadata:
annotations:
openshift.io/generated-by: OpenShiftNewApp
labels:
deployment: httpd
spec:
containers:
- image: ' '
name: httpd
ports:
- containerPort: 8080
protocol: TCP
- containerPort: 8443
protocol: TCP