All Policies

Restrict Ingress Classes

Ingress classes should only be allowed which match up to deployed Ingress controllers in the cluster. Allowing users to define classes which cannot be satisfied by a deployed Ingress controller can result in either no or undesired functionality. This policy checks Ingress resources and only allows those which define `HAProxy` or `nginx` in the respective annotation. This annotation has largely been replaced as of Kubernetes 1.18 with the IngressClass resource.

Policy Definition

/other/restrict-ingress-classes/restrict-ingress-classes.yaml

 1apiVersion: kyverno.io/v1
 2kind: ClusterPolicy
 3metadata:
 4  name: restrict-ingress-classes
 5  annotations:
 6    policies.kyverno.io/title: Restrict Ingress Classes
 7    policies.kyverno.io/category: Sample
 8    policies.kyverno.io/severity: medium
 9    policies.kyverno.io/subject: Ingress
10    policies.kyverno.io/minversion: 1.6.0
11    policies.kyverno.io/description: >-
12      Ingress classes should only be allowed which match up to deployed Ingress controllers
13      in the cluster. Allowing users to define classes which cannot be satisfied by a deployed
14      Ingress controller can result in either no or undesired functionality. This policy checks
15      Ingress resources and only allows those which define `HAProxy` or `nginx` in the respective
16      annotation. This annotation has largely been replaced as of Kubernetes 1.18 with the IngressClass
17      resource.
18spec:
19  validationFailureAction: Audit
20  background: true
21  rules:
22  - name: validate-ingress
23    match:
24      any:
25      - resources:
26          kinds:
27          - Ingress
28    validate:
29      message: "Unknown ingress class."
30      pattern:
31        metadata:
32          annotations:
33            kubernetes.io/ingress.class: "HAProxy | nginx"