All Policies
Disallow empty Ingress host
An ingress resource needs to define an actual host name in order to be valid. This policy ensures that there is a hostname for each rule defined.
Policy Definition
/best-practices/disallow-empty-ingress-host/disallow_empty_ingress_host.yaml
1apiVersion: kyverno.io/v1
2kind: ClusterPolicy
3metadata:
4 name: disallow-empty-ingress-host
5 annotations:
6 policies.kyverno.io/title: Disallow empty Ingress host
7 policies.kyverno.io/category: Best Practices
8 policies.kyverno.io/severity: medium
9 policies.kyverno.io/subject: Ingress
10 policies.kyverno.io/description: >-
11 An ingress resource needs to define an actual host name
12 in order to be valid. This policy ensures that there is a
13 hostname for each rule defined.
14spec:
15 validationFailureAction: enforce
16 background: false
17 rules:
18 - name: disallow-empty-ingress-host
19 match:
20 resources:
21 kinds:
22 - Ingress
23 validate:
24 message: "The Ingress host name must be defined, not empty."
25 deny:
26 conditions:
27 - key: "{{ request.object.spec.rules[].host || `[]` | length(@) }}"
28 operator: NotEquals
29 value: "{{ request.object.spec.rules[].http || `[]` | length(@) }}"