In instances where a ClusterPolicy defines all the approved image registries is insufficient, more granular control may be needed to set permitted registries, especially in multi-tenant use cases where some registries may be based on the Namespace. This policy shows an advanced version of the Restrict Image Registries policy which gets a global approved registry from a ConfigMap and, based upon an annotation at the Namespace level, gets the registry approved for that Namespace.
apiVersion: kyverno.io/v1kind: ClusterPolicymetadata:name: advanced-restrict-image-registriesannotations:policies.kyverno.io/title: Advanced Restrict Image Registriespolicies.kyverno.io/category: Otherpolicies.kyverno.io/severity: mediumkyverno.io/kyverno-version: 1.6.0policies.kyverno.io/minversion: 1.6.0kyverno.io/kubernetes-version: "1.23"policies.kyverno.io/subject: Podpolicies.kyverno.io/description: In instances where a ClusterPolicy defines all the approved image registries is insufficient, more granular control may be needed to set permitted registries, especially in multi-tenant use cases where some registries may be based on the Namespace. This policy shows an advanced version of the Restrict Image Registries policy which gets a global approved registry from a ConfigMap and, based upon an annotation at the Namespace level, gets the registry approved for that Namespace.spec:validationFailureAction: Auditbackground: falserules:- name: validate-corp-registriesmatch:any:- resources:kinds:- Podcontext:- name: nsregistriesapiCall:urlPath: /api/v1/namespaces/{{request.namespace}}jmesPath: metadata.annotations."corp.com/allowed-registries" || ''- name: clusterregistriesconfigMap:name: clusterregistriesnamespace: defaultpreconditions:any:- key: "{{request.operation || 'BACKGROUND'}}"operator: AnyInvalue:- CREATE- UPDATEvalidate:message: This Pod names an image that is not from an approved registry.foreach:- list: request.object.spec.[initContainers, ephemeralContainers, containers][]deny:conditions:all:- key: "{{element.image}}"operator: NotEqualsvalue: "{{nsregistries}}"- key: "{{element.image}}"operator: NotEqualsvalue: "{{clusterregistries.data.registries}}"
This policy prevents the use of the default project in an Application.
Services of type LoadBalancer when deployed inside AWS have support for transport encryption if it is enabled via an annotation. This policy requires that Services of type LoadBalancer contain the annotation service.beta.kubernetes.io/aws-load-balancer-ssl-cert with some value.
This policy prevents updates to the project field after an Application is created.