This documentation is for a release that is no longer maintained
See documentation for the latest supported version 3 or the latest supported version 4.Chapter 11. Image Policy
11.1. Overview
You can control which images are allowed to run on your cluster using the ImagePolicy admission plug-in (currently considered beta). It allows you to control:
- The source of images: which registries can be used to pull images
- Image resolution: force pods to run with immutable digests to ensure the image does not change due to a re-tag
- Container image label restrictions: force an image to have or not have particular labels
- Image annotation restrictions: force an image in the integrated container registry to have or not have particular annotations
11.2. Configuring the ImagePolicy Admission Plug-in
				To configure which images can run on your cluster, configure the ImagePolicy Admission plug-in in the master-config.yaml file. You can set one or more rules as required.
			
- Reject images with a particular annotation: - Use this rule to reject all images that have a specific annotation set on them. The following rejects all images using the - images.openshift.io/deny-executionannotation:- Copy to Clipboard Copied! - Toggle word wrap Toggle overflow - 1
- If a particular image has been deemed harmful, administrators can set this annotation to flag those images.
 
- Enable user to run images from Docker Hub: - Use this rule to allow users to use images from Docker Hub: - Copy to Clipboard Copied! - Toggle word wrap Toggle overflow 
				Following is an example configuration for setting multiple ImagePolicy addmission plugin rules in the master-config.yaml file:
			
Annotated Example File
- 1
- Try to resolve images to an immutable image digest and update the image pull specification in the pod.
- 2
- Array of rules to evaluate against incoming resources. If you only havereject: truerules, the default is allow all. If you have any accept rule, that isreject: falsein any of the rules, the default behaviour of the ImagePolicy switches to deny-all.
- 3
- Indicates which resources to enforce rules upon. If nothing is specified, the default is pods.
- 4
- Indicates that if this rule matches, the pod should be rejected.
- 5
- List of annotations to match on the image object’s metadata.
- 6
- If you are not able to resolve the image, do not fail the pod.
- 7
- Array of rules allowing use of image streams in Kubernetes resources. The default configuration allows pods, replicationcontrollers, replicasets, statefulsets, daemonsets, deployments, and jobs to use same-project image stream tag references in their image fields.
- 8
- Identifies the group and resource to which this rule applies. If resource is*, this rule will apply to all resources in that group.
- 9
- LocalNameswill allow single segment names (for example,- ruby:2.4) to be interpreted as namespace-local image stream tags, but only if the resource or target image stream has- local name resolutionenabled.
					If you normally rely on infrastructure images being pulled using a default registry prefix (such as docker.io or registry.access.redhat.com), those images will not match to any matchRegistries value since they will have no registry prefix. To ensure infrastructure images have a registry prefix that can match your image policy, set the imageConfig.format value in your master-config.yaml file.
				
11.3. Testing the ImagePolicy Admission Plug-in
- Use the - openshift/image-policy-checkto test your configuration.- For example, use the information above, then test like this: - oc import-image openshift/image-policy-check:latest --confirm - oc import-image openshift/image-policy-check:latest --confirm- Copy to Clipboard Copied! - Toggle word wrap Toggle overflow 
- Create a pod using this YAML. The pod should be created. - Copy to Clipboard Copied! - Toggle word wrap Toggle overflow 
- Create another pod pointing to a different registry. The pod should be rejected. - Copy to Clipboard Copied! - Toggle word wrap Toggle overflow 
- Create a pod pointing to the internal registry using the imported image. The pod should be created and if you look at the image specification, you should see a digest in place of the tag. - Copy to Clipboard Copied! - Toggle word wrap Toggle overflow 
- Create a pod pointing to the internal registry using the imported image. The pod should be created and if you look at the image specification, you should see the tag unmodified. - Copy to Clipboard Copied! - Toggle word wrap Toggle overflow 
- Get the digest from - oc get istag/image-policy-check:latestand use it for- oc annotate images/<digest> images.openshift.io/deny-execution=true. For example:- oc annotate images/sha256:09ce3d8b5b63595ffca6636c7daefb1a615a7c0e3f8ea68e5db044a9340d6ba8 images.openshift.io/deny-execution=true - $ oc annotate images/sha256:09ce3d8b5b63595ffca6636c7daefb1a615a7c0e3f8ea68e5db044a9340d6ba8 images.openshift.io/deny-execution=true- Copy to Clipboard Copied! - Toggle word wrap Toggle overflow 
- Create this pod again, and you should see the pod rejected: - Copy to Clipboard Copied! - Toggle word wrap Toggle overflow