Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: update deprecated fields in disallow-latest-tag policy (#1130) #1213

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -6,36 +6,62 @@ metadata:
name: disallow-latest-tag
spec:
steps:
- name: step-01
try:
- apply:
file: ../disallow-latest-tag.yaml
- patch:
resource:
apiVersion: kyverno.io/v1
kind: ClusterPolicy
metadata:
name: disallow-latest-tag
spec:
validationFailureAction: Enforce
- assert:
file: policy-ready.yaml
- name: step-02
try:
- apply:
file: good-pod.yaml
- apply:
expect:
- check:
($error != null): true
file: bad-pod-latest-fail-first.yaml
- apply:
expect:
- check:
($error != null): true
file: bad-pod-latest-success-first.yaml
- apply:
expect:
- check:
($error != null): true
file: bad-pod-no-tag.yaml
- name: step-01
try:
- apply:
file: ../disallow-latest-tag.yaml
- patch:
resource:
apiVersion: kyverno.io/v1
kind: ClusterPolicy
metadata:
name: disallow-latest-tag
spec:
rules:
- name: require-image-tag
match:
any:
- resources:
kinds:
- Pod
validate:
failureAction: Enforce
message: "Container images must have a tag specified"
pattern:
spec:
containers:
- image: "!*:latest"
- name: validate-image-tag
match:
any:
- resources:
kinds:
- Pod
validate:
failureAction: Enforce
message: "Images must have a specific tag"
pattern:
spec:
containers:
- image: "!*:latest"
- assert:
file: policy-ready.yaml
- name: step-02
try:
- apply:
file: good-pod.yaml
- apply:
expect:
- check:
($error != null): true
file: bad-pod-latest-fail-first.yaml
- apply:
expect:
- check:
($error != null): true
file: bad-pod-latest-success-first.yaml
- apply:
expect:
- check:
($error != null): true
file: bad-pod-no-tag.yaml
76 changes: 39 additions & 37 deletions best-practices/disallow-latest-tag/disallow-latest-tag.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,42 +14,44 @@ metadata:
a specific version of an application Pod. This policy validates that the image
specifies a tag and that it is not called `latest`.
spec:
validationFailureAction: Audit
background: true
rules:
- name: require-image-tag
match:
any:
- resources:
kinds:
- Pod
validate:
message: "An image tag is required."
foreach:
- list: "request.object.spec.containers"
pattern:
image: "*:*"
- list: "request.object.spec.initContainers"
pattern:
image: "*:*"
- list: "request.object.spec.ephemeralContainers"
pattern:
image: "*:*"
- name: validate-image-tag
match:
any:
- resources:
kinds:
- Pod
validate:
message: "Using a mutable image tag e.g. 'latest' is not allowed."
foreach:
- list: "request.object.spec.containers"
pattern:
image: "!*:latest"
- list: "request.object.spec.initContainers"
pattern:
image: "!*:latest"
- list: "request.object.spec.ephemeralContainers"
pattern:
image: "!*:latest"
- name: require-image-tag
match:
any:
- resources:
kinds:
- Pod
validate:
failureAction: Audit
message: "An image tag is required."
foreach:
- list: "request.object.spec.containers"
pattern:
image: "*:*"
- list: "request.object.spec.initContainers"
pattern:
image: "*:*"
- list: "request.object.spec.ephemeralContainers"
pattern:
image: "*:*"

- name: validate-image-tag
match:
any:
- resources:
kinds:
- Pod
validate:
failureAction: Audit
message: "Using a mutable image tag e.g. 'latest' is not allowed."
foreach:
- list: "request.object.spec.containers"
pattern:
image: "!*:latest"
- list: "request.object.spec.initContainers"
pattern:
image: "!*:latest"
- list: "request.object.spec.ephemeralContainers"
pattern:
image: "!*:latest"