Rather than creating a deny list of annotations, it may be more useful to invert that list and create an allow list which then denies any others. This policy demonstrates how to allow two annotations with a specific key name of fluxcd.io/ while denying others that do not meet the pattern.
apiVersion: kyverno.io/v1kind: ClusterPolicymetadata:name: allowed-annotationsannotations:policies.kyverno.io/title: Allowed Annotationspolicies.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: Pod, Annotationpolicies.kyverno.io/description: Rather than creating a deny list of annotations, it may be more useful to invert that list and create an allow list which then denies any others. This policy demonstrates how to allow two annotations with a specific key name of fluxcd.io/ while denying others that do not meet the pattern.spec:validationFailureAction: Auditbackground: truerules:- name: allowed-fluxcd-annotationsmatch:any:- resources:kinds:- Podvalidate:message: The only approved FluxCD annotations are `fluxcd.io/cow` and `fluxcd.io/dog`.deny:conditions:all:- key: "{{ request.object.metadata.annotations.keys(@)[?contains(@, 'fluxcd.io/')] }}"operator: AnyNotInvalue:- fluxcd.io/cow- fluxcd.io/dog
This policy performs some best practices validation on Application fields. Path or chart must be specified but never both. And destination.name or destination.server must be specified but never both.
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.