1
0
Fork 0
mirror of https://github.com/kyverno/kyverno.git synced 2025-03-05 15:37:19 +00:00
kyverno/samples/RestrictImageRegistries.md

32 lines
1.1 KiB
Markdown
Raw Normal View History

2019-10-23 14:06:03 -07:00
# Disallow unknown image registries
Images from unknown registries may not be scanned and secured. Requiring the use of trusted registries helps reduce threat exposure and is considered a common Kubernetes best practice.
2019-10-23 15:36:37 -07:00
This sample policy requires that all images come from either `k8s.gcr.io` or `gcr.io`. You can customize this policy to allow other or different image registries that you trust. Alternatively, you can invert the check to allow images from all other registries except one (or a list) by changing the `image` field to `image: "!k8s.gcr.io"`.
2019-10-23 14:06:03 -07:00
2020-11-11 15:55:02 -05:00
## Policy YAML
2019-10-23 14:06:03 -07:00
2020-11-11 15:55:02 -05:00
[restrict_image_registries.yaml](more/restrict_image_registries.yaml)
2019-10-23 14:06:03 -07:00
````yaml
2019-11-13 13:56:20 -08:00
apiVersion : kyverno.io/v1
2019-10-23 14:06:03 -07:00
kind: ClusterPolicy
metadata:
2019-11-10 18:13:01 -08:00
name: restrict-image-registries
2019-10-23 14:06:03 -07:00
spec:
validationFailureAction: audit
2019-10-23 14:06:03 -07:00
rules:
2019-11-10 18:13:01 -08:00
- name: validate-registries
2019-10-23 14:06:03 -07:00
match:
resources:
kinds:
- Pod
validate:
message: "Unknown image registry."
2019-10-23 14:06:03 -07:00
pattern:
spec:
containers:
# Allows images from either k8s.gcr.io or gcr.io.
2019-10-23 14:06:03 -07:00
- image: "k8s.gcr.io/* | gcr.io/*"
````