All Policies

Restrict Annotations

Some annotations control functionality driven by other cluster-wide tools and are not normally set by some class of users. This policy prevents the use of an annotation beginning with `fluxcd.io/`. This can be useful to ensure users either don't set reserved annotations or to force them to use a newer version of an annotation.

Policy Definition

/other/restrict_annotations.yaml

 1apiVersion: kyverno.io/v1
 2kind: ClusterPolicy
 3metadata:
 4  name: restrict-annotations
 5  annotations:
 6    policies.kyverno.io/title: Restrict Annotations
 7    policies.kyverno.io/category: Sample
 8    policies.kyverno.io/minversion: 1.3.0
 9    policies.kyverno.io/subject: Pod, Annotation
10    policies.kyverno.io/description: >-
11      Some annotations control functionality driven by other cluster-wide tools and are not
12      normally set by some class of users. This policy prevents the use of an annotation beginning
13      with `fluxcd.io/`. This can be useful to ensure users either
14      don't set reserved annotations or to force them to use a newer version of an annotation.      
15    pod-policies.kyverno.io/autogen-controllers: None
16spec:
17  validationFailureAction: audit
18  background: false
19  rules:
20  - name: block-flux-v1
21    match:
22      resources:
23        kinds:
24        - Deployment
25        - CronJob
26        - Job
27        - StatefulSet
28        - DaemonSet
29        - Pod
30    validate:
31      message: Cannot use Flux v1 annotation.
32      pattern:
33        metadata:
34          =(annotations):
35            X(fluxcd.io/*): "*?"