An Ingress host is a URL at which services may be made available externally. In most cases, these hosts should be unique across the cluster to ensure no routing conflicts occur. This policy checks an incoming Ingress resource to ensure its hosts are unique to the cluster. It also ensures that only a single host may be specified in a given manifest.
apiVersion: kyverno.io/v1kind: ClusterPolicymetadata:name: unique-ingress-hostannotations:policies.kyverno.io/title: Unique Ingress Hostpolicies.kyverno.io/category: Samplepolicies.kyverno.io/severity: mediumpolicies.kyverno.io/subject: Ingresspolicies.kyverno.io/minversion: 1.6.0policies.kyverno.io/description: "An Ingress host is a URL at which services may be made available externally. In most cases, these hosts should be unique across the cluster to ensure no routing conflicts occur. This policy checks an incoming Ingress resource to ensure its hosts are unique to the cluster. It also ensures that only a single host may be specified in a given manifest. "spec:validationFailureAction: Auditbackground: falserules:- name: check-single-host-creatematch:any:- resources:kinds:- Ingresscontext:- name: hostsapiCall:urlPath: /apis/networking.k8s.io/v1/ingressesjmesPath: items[].spec.rules[].hostpreconditions:all:- key: "{{request.operation || 'BACKGROUND'}}"operator: Equalsvalue: CREATEvalidate:message: The Ingress host name must be unique.deny:conditions:all:- key: "{{ request.object.spec.rules[].host }}"operator: AnyInvalue: "{{ hosts }}"- name: check-single-host-updatematch:any:- resources:kinds:- Ingresspreconditions:all:- key: "{{request.operation || 'BACKGROUND'}}"operator: Equalsvalue: UPDATEcontext:- name: allhostsapiCall:urlPath: /apis/networking.k8s.io/v1/ingressesjmesPath: items[?metadata.uid!='{{ request.object.metadata.uid }}'].spec.rules[].hostvalidate:message: The Ingress host name must be unique.deny:conditions:all:- key: "{{ request.object.spec.rules[].host }}"operator: AnyInvalue: "{{ allhosts }}"- name: deny-multiple-hostsmatch:any:- resources:kinds:- Ingresspreconditions:all:- key: "{{request.operation || 'BACKGROUND'}}"operator: AnyInvalue:- CREATE- UPDATE- key: "{{ request.object.spec.rules[].host | length(@)}}"operator: GreaterThanvalue: 1validate:message: An Ingress resource may only contain a single host entry.deny: {}
This policy prevents the use of the default project in an Application.
This policy prevents updates to the project field after an Application is created.
This policy ensures that the name of the ApplicationSet is the same value provided in the project.