forked from kyverno/kyverno
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
new samples around image practices (kyverno#1302)
- Loading branch information
1 parent
d8062eb
commit f5d4872
Showing
5 changed files
with
108 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
# Require `imagePullPolicy` is set to `Always` for images not using `latest` tags | ||
|
||
By default, Kubernetes sets the `imagePullPolicy` for images which specify a tag to be `IfNotPresent`. In some cases, this may not be desired where the image could be rebuilt upstream. This sample policy ensures that all containers have their `imagePullPolicy` set to `Always`. | ||
|
||
## Policy YAML | ||
|
||
[imagepullpolicy-always.yaml](misc/imagepullpolicy-always.yaml) | ||
|
||
```yaml | ||
apiVersion : kyverno.io/v1 | ||
kind: ClusterPolicy | ||
metadata: | ||
name: imagepullpolicy-always | ||
spec: | ||
validationFailureAction: audit | ||
background: false | ||
rules: | ||
- name: imagepullpolicy-always | ||
match: | ||
resources: | ||
kinds: | ||
- Pod | ||
validate: | ||
message: "The imagePullPolicy must be set to `Always` for all containers when a tag other than `latest` is used." | ||
pattern: | ||
spec: | ||
containers: | ||
- imagePullPolicy: Always | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
# Require images using `latest` tag set `imagePullPolicy` to not `Always` | ||
|
||
When using the `latest` tag for images, although generally [not a best practice](DisallowLatestTag.md), Kubernetes defaults its `imagePullPolicy` to `Always`. Since Docker Hub has instituted a [rate-limiting policy](https://www.docker.com/blog/what-you-need-to-know-about-upcoming-docker-hub-rate-limiting/), this could result in reaching that limit faster than anticipated, which could mean errors for other Pods in the cluster or across the enterprise. Ensuring those `latest`-tagged images do not use the default of `Always` is one way to ensure pulls are only when needed. | ||
|
||
This sample policy checks the `image` value and ensures that if `:latest` is defined that the `imagePullPolicy` must use something other than the value of `Always`. Note that if no tag is defined, Kyverno will not see that as a violation of the policy. | ||
|
||
## Policy YAML | ||
|
||
[latestimage-notalways.yaml](misc/latestimage-notalways.yaml) | ||
|
||
```yaml | ||
apiVersion : kyverno.io/v1 | ||
kind: ClusterPolicy | ||
metadata: | ||
name: latestimage-notalways | ||
spec: | ||
validationFailureAction: audit | ||
background: false | ||
rules: | ||
- name: latestimage-notalways | ||
match: | ||
resources: | ||
kinds: | ||
- Pod | ||
validate: | ||
message: "When using the `latest` tag, the `imagePullPolicy` must not use `Always`." | ||
pattern: | ||
spec: | ||
containers: | ||
- (image): "*:latest" | ||
imagePullPolicy: "!Always" | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
apiVersion : kyverno.io/v1 | ||
kind: ClusterPolicy | ||
metadata: | ||
name: imagepullpolicy-always | ||
spec: | ||
validationFailureAction: audit | ||
background: false | ||
rules: | ||
- name: imagepullpolicy-always | ||
match: | ||
resources: | ||
kinds: | ||
- Pod | ||
validate: | ||
message: "The imagePullPolicy must be set to `Always` for all containers when a tag other than `latest` is used." | ||
pattern: | ||
spec: | ||
containers: | ||
- imagePullPolicy: Always |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
apiVersion : kyverno.io/v1 | ||
kind: ClusterPolicy | ||
metadata: | ||
name: latestimage-notalways | ||
spec: | ||
validationFailureAction: audit | ||
background: false | ||
rules: | ||
- name: latestimage-notalways | ||
match: | ||
resources: | ||
kinds: | ||
- Pod | ||
validate: | ||
message: "When using the `latest` tag, the `imagePullPolicy` must not use `Always`." | ||
pattern: | ||
spec: | ||
containers: | ||
- (image): "*:latest" | ||
imagePullPolicy: "!Always" |