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/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.6.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: true
19  rules:
20  - name: block-flux-v1
21    match:
22      any:
23      - resources:
24          kinds:
25          - Deployment
26          - CronJob
27          - Job
28          - StatefulSet
29          - DaemonSet
30          - Pod
31    validate:
32      message: Cannot use Flux v1 annotation.
33      pattern:
34        metadata:
35          =(annotations):
36            X(fluxcd.io/*): "*?"