All Policies

Disallow Latest Tag

The ':latest' tag is mutable and can lead to unexpected errors if the image changes. A best practice is to use an immutable tag that maps to a specific version of an application Pod. This policy validates that the image specifies a tag and that it is not called `latest`.

Policy Definition

/best-practices/disallow_latest_tag/disallow_latest_tag.yaml

 1apiVersion: kyverno.io/v1
 2kind: ClusterPolicy
 3metadata:
 4  name: disallow-latest-tag
 5  annotations:
 6    policies.kyverno.io/title: Disallow Latest Tag
 7    policies.kyverno.io/category: Best Practices
 8    policies.kyverno.io/severity: medium
 9    policies.kyverno.io/subject: Pod
10    policies.kyverno.io/description: >-
11      The ':latest' tag is mutable and can lead to unexpected errors if the
12      image changes. A best practice is to use an immutable tag that maps to
13      a specific version of an application Pod. This policy validates that the image
14      specifies a tag and that it is not called `latest`.      
15spec:
16  validationFailureAction: audit
17  background: true
18  rules:
19  - name: require-image-tag
20    match:
21      resources:
22        kinds:
23        - Pod
24    validate:
25      message: "An image tag is required."
26      pattern:
27        spec:
28          containers:
29          - image: "*:*"
30  - name: validate-image-tag
31    match:
32      resources:
33        kinds:
34        - Pod
35    validate:
36      message: "Using a mutable image tag e.g. 'latest' is not allowed."
37      pattern:
38        spec:
39          containers:
40          - image: "!*:latest"