All Policies

Restrict node label creation

Node labels are critical pieces of metadata upon which many other applications and logic may depend and should not be altered or removed by regular users. Many cloud providers also use Node labels to signal specific functions to applications. This policy prevents setting of a new label called `foo` on cluster Nodes. Use of this policy requires removal of the Node resource filter in the Kyverno ConfigMap ([Node,*,*]). Due to Kubernetes CVE-2021-25735, this policy requires, at minimum, one of the following versions of Kubernetes: v1.18.18, v1.19.10, v1.20.6, or v1.21.0.

Policy Definition

/other/restrict_node_label_creation.yaml

 1apiVersion: kyverno.io/v1
 2kind: ClusterPolicy
 3metadata:
 4  name: restrict-node-label-creation
 5  annotations:
 6    policies.kyverno.io/title: Restrict node label creation
 7    policies.kyverno.io/category: Sample
 8    policies.kyverno.io/subject: Node, Label
 9    policies.kyverno.io/description: >-
10      Node labels are critical pieces of metadata upon which many other applications and
11      logic may depend and should not be altered or removed by regular users. Many cloud
12      providers also use Node labels to signal specific functions to applications.
13      This policy prevents setting of a new label called `foo` on
14      cluster Nodes. Use of this policy requires removal of the Node resource filter
15      in the Kyverno ConfigMap ([Node,*,*]). Due to Kubernetes CVE-2021-25735, this policy
16      requires, at minimum, one of the following versions of Kubernetes:
17      v1.18.18, v1.19.10, v1.20.6, or v1.21.0.      
18spec:
19  validationFailureAction: enforce
20  background: false
21  rules:
22  - name: prevent-label-set
23    match:
24      resources:
25        kinds:
26        - Node
27    preconditions:
28      all:
29      - key: "{{request.operation}}"
30        operator: Equals
31        value: UPDATE
32      - key: "{{request.object.metadata.labels.foo}}"
33        operator: Equals
34        value: "*"
35    validate:
36      message: "Setting the `foo` label on a Node is not allowed."
37      deny: {}
38