Image configuration resources

Use the following procedure to configure image registries.

Image controller configuration parameters

The image.config.openshift.io/cluster resource holds cluster-wide information about how to handle images. The canonical, and only valid name is cluster. Its spec offers the following configuration parameters.

Parameters such as DisableScheduledImport, MaxImagesBulkImportedPerRepository, MaxScheduledImportsPerMinute, ScheduledImageImportMinimumIntervalSeconds, InternalRegistryHostname are not configurable.

ParameterDescription

allowedRegistriesForImport

Limits the container image registries from which normal users can import images. Set this list to the registries that you trust to contain valid images, and that you want applications to be able to import from. Users with permission to create images or ImageStreamMappings from the API are not affected by this policy. Typically only cluster administrators have the appropriate permissions.

Every element of this list contains a location of the registry specified by the registry domain name.

domainName: Specifies a domain name for the registry. If the registry uses a non-standard 80 or 443 port, the port should be included in the domain name as well.

insecure: Insecure indicates whether the registry is secure or insecure. By default, if not otherwise specified, the registry is assumed to be secure.

additionalTrustedCA

A reference to a config map containing additional CAs that should be trusted during image stream import, pod image pull, openshift-image-registry pullthrough, and builds.

The namespace for this config map is openshift-config. The format of the config map is to use the registry hostname as the key, and the PEM-encoded certificate as the value, for each additional registry CA to trust.

externalRegistryHostnames

Provides the hostnames for the default external image registry. The external hostname should be set only when the image registry is exposed externally. The first value is used in publicDockerImageRepository field in image streams. The value must be in hostname[:port] format.

registrySources

Contains configuration that determines how the container runtime should treat individual registries when accessing images for builds and pods. For instance, whether or not to allow insecure access. It does not contain configuration for the internal cluster registry.

insecureRegistries: Registries which do not have a valid TLS certificate or only support HTTP connections. To specify all subdomains, add the asterisk () wildcard character as a prefix to the domain name. For example, .example.com. You can specify an individual repository within a registry. For example: reg1.io/myrepo/myapp:latest.

blockedRegistries: Registries for which image pull and push actions are denied. To specify all subdomains, add the asterisk () wildcard character as a prefix to the domain name. For example, .example.com. You can specify an individual repository within a registry. For example: reg1.io/myrepo/myapp:latest. All other registries are allowed.

allowedRegistries: Registries for which image pull and push actions are allowed. To specify all subdomains, add the asterisk () wildcard character as a prefix to the domain name. For example, .example.com. You can specify an individual repository within a registry. For example: reg1.io/myrepo/myapp:latest. All other registries are blocked.

containerRuntimeSearchRegistries: Registries for which image pull and push actions are allowed using image short names. All other registries are blocked.

Either blockedRegistries or allowedRegistries can be set, but not both.

When the allowedRegistries parameter is defined, all registries, including registry.redhat.io and quay.io registries and the default OpenShift image registry, are blocked unless explicitly listed. When using the parameter, to prevent pod failure, add all registries including the registry.redhat.io and quay.io registries and the internalRegistryHostname to the allowedRegistries list, as they are required by payload images within your environment. For disconnected clusters, mirror registries should also be added.

The status field of the image.config.openshift.io/cluster resource holds observed values from the cluster.

ParameterDescription

internalRegistryHostname

Set by the Image Registry Operator, which controls the internalRegistryHostname. It sets the hostname for the default OpenShift image registry. The value must be in hostname[:port] format. For backward compatibility, you can still use the OPENSHIFT_DEFAULT_REGISTRY environment variable, but this setting overrides the environment variable.

externalRegistryHostnames

Set by the Image Registry Operator, provides the external hostnames for the image registry when it is exposed externally. The first value is used in publicDockerImageRepository field in image streams. The values must be in hostname[:port] format.

Configuring image registry settings

You can configure image registry settings by editing the image.config.openshift.io/cluster custom resource (CR). When changes to the registry are applied to the image.config.openshift.io/cluster CR, the Machine Config Operator (MCO) performs the following sequential actions:

  1. Cordons the node

  2. Applies changes by restarting CRI-O

  3. Uncordons the node

    The MCO does not restart nodes when it detects changes.

Procedure

  1. Edit the image.config.openshift.io/cluster custom resource:

    1. $ oc edit image.config.openshift.io/cluster

    The following is an example image.config.openshift.io/cluster CR:

    1. apiVersion: config.openshift.io/v1
    2. kind: Image (1)
    3. metadata:
    4. annotations:
    5. release.openshift.io/create-only: "true"
    6. creationTimestamp: "2019-05-17T13:44:26Z"
    7. generation: 1
    8. name: cluster
    9. resourceVersion: "8302"
    10. selfLink: /apis/config.openshift.io/v1/images/cluster
    11. uid: e34555da-78a9-11e9-b92b-06d6c7da38dc
    12. spec:
    13. allowedRegistriesForImport: (2)
    14. - domainName: quay.io
    15. insecure: false
    16. additionalTrustedCA: (3)
    17. name: myconfigmap
    18. registrySources: (4)
    19. allowedRegistries:
    20. - example.com
    21. - quay.io
    22. - registry.redhat.io
    23. - image-registry.openshift-image-registry.svc:5000
    24. - reg1.io/myrepo/myapp:latest
    25. insecureRegistries:
    26. - insecure.com
    27. status:
    28. internalRegistryHostname: image-registry.openshift-image-registry.svc:5000
    1Image: Holds cluster-wide information about how to handle images. The canonical, and only valid name is cluster.
    2allowedRegistriesForImport: Limits the container image registries from which normal users may import images. Set this list to the registries that you trust to contain valid images, and that you want applications to be able to import from. Users with permission to create images or ImageStreamMappings from the API are not affected by this policy. Typically only cluster administrators have the appropriate permissions.
    3additionalTrustedCA: A reference to a config map containing additional certificate authorities (CA) that are trusted during image stream import, pod image pull, openshift-image-registry pullthrough, and builds. The namespace for this config map is openshift-config. The format of the config map is to use the registry hostname as the key, and the PEM certificate as the value, for each additional registry CA to trust.
    4registrySources: Contains configuration that determines whether the container runtime allows or blocks individual registries when accessing images for builds and pods. Either the allowedRegistries parameter or the blockedRegistries parameter can be set, but not both. You can also define whether or not to allow access to insecure registries or registries that allow registries that use image short names. This example uses the allowedRegistries parameter, which defines the registries that are allowed to be used. The insecure registry insecure.com is also allowed. The registrySources parameter does not contain configuration for the internal cluster registry.

    When the allowedRegistries parameter is defined, all registries, including the registry.redhat.io and quay.io registries and the default OpenShift image registry, are blocked unless explicitly listed. If you use the parameter, to prevent pod failure, you must add the registry.redhat.io and quay.io registries and the internalRegistryHostname to the allowedRegistries list, as they are required by payload images within your environment. Do not add the registry.redhat.io and quay.io registries to the blockedRegistries list.

    When using the allowedRegistries, blockedRegistries, or insecureRegistries parameter, you can specify an individual repository within a registry. For example: reg1.io/myrepo/myapp:latest.

    Insecure external registries should be avoided to reduce possible security risks.

  2. To check that the changes are applied, list your nodes:

    1. $ oc get nodes

    Example output

    1. NAME STATUS ROLES AGE VERSION
    2. ip-10-0-137-182.us-east-2.compute.internal Ready,SchedulingDisabled worker 65m v1.28.5
    3. ip-10-0-139-120.us-east-2.compute.internal Ready,SchedulingDisabled control-plane 74m v1.28.5
    4. ip-10-0-176-102.us-east-2.compute.internal Ready control-plane 75m v1.28.5
    5. ip-10-0-188-96.us-east-2.compute.internal Ready worker 65m v1.28.5
    6. ip-10-0-200-59.us-east-2.compute.internal Ready worker 63m v1.28.5
    7. ip-10-0-223-123.us-east-2.compute.internal Ready control-plane 73m v1.28.5

Adding specific registries

You can add a list of registries, and optionally an individual repository within a registry, that are permitted for image pull and push actions by editing the image.config.openshift.io/cluster custom resource (CR). OKD applies the changes to this CR to all nodes in the cluster.

When pulling or pushing images, the container runtime searches the registries listed under the registrySources parameter in the image.config.openshift.io/cluster CR. If you created a list of registries under the allowedRegistries parameter, the container runtime searches only those registries. Registries not in the list are blocked.

When the allowedRegistries parameter is defined, all registries, including the registry.redhat.io and quay.io registries and the default OpenShift image registry, are blocked unless explicitly listed. If you use the parameter, to prevent pod failure, add the registry.redhat.io and quay.io registries and the internalRegistryHostname to the allowedRegistries list, as they are required by payload images within your environment. For disconnected clusters, mirror registries should also be added.

Procedure

  • Edit the image.config.openshift.io/cluster custom resource:

    1. $ oc edit image.config.openshift.io/cluster

    The following is an example image.config.openshift.io/cluster CR with an allowed list:

    1. apiVersion: config.openshift.io/v1
    2. kind: Image
    3. metadata:
    4. annotations:
    5. release.openshift.io/create-only: "true"
    6. creationTimestamp: "2019-05-17T13:44:26Z"
    7. generation: 1
    8. name: cluster
    9. resourceVersion: "8302"
    10. selfLink: /apis/config.openshift.io/v1/images/cluster
    11. uid: e34555da-78a9-11e9-b92b-06d6c7da38dc
    12. spec:
    13. registrySources: (1)
    14. allowedRegistries: (2)
    15. - example.com
    16. - quay.io
    17. - registry.redhat.io
    18. - reg1.io/myrepo/myapp:latest
    19. - image-registry.openshift-image-registry.svc:5000
    20. status:
    21. internalRegistryHostname: image-registry.openshift-image-registry.svc:5000
    1Contains configurations that determine how the container runtime should treat individual registries when accessing images for builds and pods. It does not contain configuration for the internal cluster registry.
    2Specify registries, and optionally a repository in that registry, to use for image pull and push actions. All other registries are blocked.

    Either the allowedRegistries parameter or the blockedRegistries parameter can be set, but not both.

    The Machine Config Operator (MCO) watches the image.config.openshift.io/cluster resource for any changes to the registries. When the MCO detects a change, it drains the nodes, applies the change, and uncordons the nodes. After the nodes return to the Ready state, the allowed registries list is used to update the image signature policy in the /etc/containers/policy.json file on each node.

Verification

  • Enter the following command to obtain a list of your nodes:

    1. $ oc get nodes

    Example output

    1. NAME STATUS ROLES AGE VERSION
    2. <node_name> Ready control-plane,master 37m v1.27.8+4fab27b
    1. Run the following command to enter debug mode on the node:

      1. $ oc debug node/<node_name>
    2. When prompted, enter chroot /host into the terminal:

      1. sh-4.4# chroot /host
    3. Enter the following command to check that the registries have been added to the policy file:

      1. sh-5.1# cat /etc/containers/policy.json | jq '.'

      The following policy indicates that only images from the example.com, quay.io, and registry.redhat.io registries are permitted for image pulls and pushes:

      Example image signature policy file

      1. {
      2. "default":[
      3. {
      4. "type":"reject"
      5. }
      6. ],
      7. "transports":{
      8. "atomic":{
      9. "example.com":[
      10. {
      11. "type":"insecureAcceptAnything"
      12. }
      13. ],
      14. "image-registry.openshift-image-registry.svc:5000":[
      15. {
      16. "type":"insecureAcceptAnything"
      17. }
      18. ],
      19. "insecure.com":[
      20. {
      21. "type":"insecureAcceptAnything"
      22. }
      23. ],
      24. "quay.io":[
      25. {
      26. "type":"insecureAcceptAnything"
      27. }
      28. ],
      29. "reg4.io/myrepo/myapp:latest":[
      30. {
      31. "type":"insecureAcceptAnything"
      32. }
      33. ],
      34. "registry.redhat.io":[
      35. {
      36. "type":"insecureAcceptAnything"
      37. }
      38. ]
      39. },
      40. "docker":{
      41. "example.com":[
      42. {
      43. "type":"insecureAcceptAnything"
      44. }
      45. ],
      46. "image-registry.openshift-image-registry.svc:5000":[
      47. {
      48. "type":"insecureAcceptAnything"
      49. }
      50. ],
      51. "insecure.com":[
      52. {
      53. "type":"insecureAcceptAnything"
      54. }
      55. ],
      56. "quay.io":[
      57. {
      58. "type":"insecureAcceptAnything"
      59. }
      60. ],
      61. "reg4.io/myrepo/myapp:latest":[
      62. {
      63. "type":"insecureAcceptAnything"
      64. }
      65. ],
      66. "registry.redhat.io":[
      67. {
      68. "type":"insecureAcceptAnything"
      69. }
      70. ]
      71. },
      72. "docker-daemon":{
      73. "":[
      74. {
      75. "type":"insecureAcceptAnything"
      76. }
      77. ]
      78. }
      79. }
      80. }

If your cluster uses the registrySources.insecureRegistries parameter, ensure that any insecure registries are included in the allowed list.

For example:

  1. spec:
  2. registrySources:
  3. insecureRegistries:
  4. - insecure.com
  5. allowedRegistries:
  6. - example.com
  7. - quay.io
  8. - registry.redhat.io
  9. - insecure.com
  10. - image-registry.openshift-image-registry.svc:5000

Blocking specific registries

You can block any registry, and optionally an individual repository within a registry, by editing the image.config.openshift.io/cluster custom resource (CR). OKD applies the changes to this CR to all nodes in the cluster.

When pulling or pushing images, the container runtime searches the registries listed under the registrySources parameter in the image.config.openshift.io/cluster CR. If you created a list of registries under the blockedRegistries parameter, the container runtime does not search those registries. All other registries are allowed.

To prevent pod failure, do not add the registry.redhat.io and quay.io registries to the blockedRegistries list, as they are required by payload images within your environment.

Procedure

  • Edit the image.config.openshift.io/cluster custom resource:

    1. $ oc edit image.config.openshift.io/cluster

    The following is an example image.config.openshift.io/cluster CR with a blocked list:

    1. apiVersion: config.openshift.io/v1
    2. kind: Image
    3. metadata:
    4. annotations:
    5. release.openshift.io/create-only: "true"
    6. creationTimestamp: "2019-05-17T13:44:26Z"
    7. generation: 1
    8. name: cluster
    9. resourceVersion: "8302"
    10. selfLink: /apis/config.openshift.io/v1/images/cluster
    11. uid: e34555da-78a9-11e9-b92b-06d6c7da38dc
    12. spec:
    13. registrySources: (1)
    14. blockedRegistries: (2)
    15. - untrusted.com
    16. - reg1.io/myrepo/myapp:latest
    17. status:
    18. internalRegistryHostname: image-registry.openshift-image-registry.svc:5000
    1Contains configurations that determine how the container runtime should treat individual registries when accessing images for builds and pods. It does not contain configuration for the internal cluster registry.
    2Specify registries, and optionally a repository in that registry, that should not be used for image pull and push actions. All other registries are allowed.

    Either the blockedRegistries registry or the allowedRegistries registry can be set, but not both.

    The Machine Config Operator (MCO) watches the image.config.openshift.io/cluster resource for any changes to the registries. When the MCO detects a change, it drains the nodes, applies the change, and uncordons the nodes. After the nodes return to the Ready state, changes to the blocked registries appear in the /etc/containers/registries.conf file on each node.

Verification

  • Enter the following command to obtain a list of your nodes:

    1. $ oc get nodes

    Example output

    1. NAME STATUS ROLES AGE VERSION
    2. <node_name> Ready control-plane,master 37m v1.27.8+4fab27b
    1. Run the following command to enter debug mode on the node:

      1. $ oc debug node/<node_name>
    2. When prompted, enter chroot /host into the terminal:

      1. sh-4.4# chroot /host
    3. Enter the following command to check that the registries have been added to the policy file:

      1. sh-5.1# cat etc/containers/registries.conf

      The following example indicates that images from the untrusted.com registry are prevented for image pulls and pushes:

      Example output

      1. unqualified-search-registries = ["registry.access.redhat.com", "docker.io"]
      2. [[registry]]
      3. prefix = ""
      4. location = "untrusted.com"
      5. blocked = true

Blocking a payload registry

In a mirroring configuration, you can block upstream payload registries in a disconnected environment using a ImageContentSourcePolicy (ICSP) object. The following example procedure demonstrates how to block the quay.io/openshift-payload payload registry.

Procedure

  1. Create the mirror configuration using an ImageContentSourcePolicy (ICSP) object to mirror the payload to a registry in your instance. The following example ICSP file mirrors the payload internal-mirror.io/openshift-payload:

    1. apiVersion: operator.openshift.io/v1alpha1
    2. kind: ImageContentSourcePolicy
    3. metadata:
    4. name: my-icsp
    5. spec:
    6. repositoryDigestMirrors:
    7. - mirrors:
    8. - internal-mirror.io/openshift-payload
    9. source: quay.io/openshift-payload
  2. After the object deploys onto your nodes, verify that the mirror configuration is set by checking the /etc/containers/registries.conf file:

    Example output

    1. [[registry]]
    2. prefix = ""
    3. location = "quay.io/openshift-payload"
    4. mirror-by-digest-only = true
    5. [[registry.mirror]]
    6. location = "internal-mirror.io/openshift-payload"
  3. Use the following command to edit the image.config.openshift.io custom resource file:

    1. $ oc edit image.config.openshift.io cluster
  4. To block the payload registry, add the following configuration to the image.config.openshift.io custom resource file:

    1. spec:
    2. registrySource:
    3. blockedRegistries:
    4. - quay.io/openshift-payload

Verification

  • Verify that the upstream payload registry is blocked by checking the /etc/containers/registries.conf file on the node.

    Example output

    1. [[registry]]
    2. prefix = ""
    3. location = "quay.io/openshift-payload"
    4. blocked = true
    5. mirror-by-digest-only = true
    6. [[registry.mirror]]
    7. location = "internal-mirror.io/openshift-payload"

Allowing insecure registries

You can add insecure registries, and optionally an individual repository within a registry, by editing the image.config.openshift.io/cluster custom resource (CR). OKD applies the changes to this CR to all nodes in the cluster.

Registries that do not use valid SSL certificates or do not require HTTPS connections are considered insecure.

Insecure external registries should be avoided to reduce possible security risks.

Procedure

  • Edit the image.config.openshift.io/cluster custom resource:

    1. $ oc edit image.config.openshift.io/cluster

    The following is an example image.config.openshift.io/cluster CR with an insecure registries list:

    1. apiVersion: config.openshift.io/v1
    2. kind: Image
    3. metadata:
    4. annotations:
    5. release.openshift.io/create-only: "true"
    6. creationTimestamp: "2019-05-17T13:44:26Z"
    7. generation: 1
    8. name: cluster
    9. resourceVersion: "8302"
    10. selfLink: /apis/config.openshift.io/v1/images/cluster
    11. uid: e34555da-78a9-11e9-b92b-06d6c7da38dc
    12. spec:
    13. registrySources: (1)
    14. insecureRegistries: (2)
    15. - insecure.com
    16. - reg4.io/myrepo/myapp:latest
    17. allowedRegistries:
    18. - example.com
    19. - quay.io
    20. - registry.redhat.io
    21. - insecure.com (3)
    22. - reg4.io/myrepo/myapp:latest
    23. - image-registry.openshift-image-registry.svc:5000
    24. status:
    25. internalRegistryHostname: image-registry.openshift-image-registry.svc:5000
    1Contains configurations that determine how the container runtime should treat individual registries when accessing images for builds and pods. It does not contain configuration for the internal cluster registry.
    2Specify an insecure registry. You can specify a repository in that registry.
    3Ensure that any insecure registries are included in the allowedRegistries list.

    When the allowedRegistries parameter is defined, all registries, including the registry.redhat.io and quay.io registries and the default OpenShift image registry, are blocked unless explicitly listed. If you use the parameter, to prevent pod failure, add all registries including the registry.redhat.io and quay.io registries and the internalRegistryHostname to the allowedRegistries list, as they are required by payload images within your environment. For disconnected clusters, mirror registries should also be added.

    The Machine Config Operator (MCO) watches the image.config.openshift.io/cluster CR for any changes to the registries, then drains and uncordons the nodes when it detects changes. After the nodes return to the Ready state, changes to the insecure and blocked registries appear in the /etc/containers/registries.conf file on each node.

Verification

  • To check that the registries have been added to the policy file, use the following command on a node:

    1. $ cat /etc/containers/registries.conf

    The following example indicates that images from the insecure.com registry is insecure and is allowed for image pulls and pushes.

    Example output

    1. unqualified-search-registries = ["registry.access.redhat.com", "docker.io"]
    2. [[registry]]
    3. prefix = ""
    4. location = "insecure.com"
    5. insecure = true

Adding registries that allow image short names

You can add registries to search for an image short name by editing the image.config.openshift.io/cluster custom resource (CR). OKD applies the changes to this CR to all nodes in the cluster.

An image short name enables you to search for images without including the fully qualified domain name in the pull spec. For example, you could use rhel7/etcd instead of registry.access.redhat.com/rhe7/etcd.

You might use short names in situations where using the full path is not practical. For example, if your cluster references multiple internal registries whose DNS changes frequently, you would need to update the fully qualified domain names in your pull specs with each change. In this case, using an image short name might be beneficial.

When pulling or pushing images, the container runtime searches the registries listed under the registrySources parameter in the image.config.openshift.io/cluster CR. If you created a list of registries under the containerRuntimeSearchRegistries parameter, when pulling an image with a short name, the container runtime searches those registries.

Using image short names with public registries is strongly discouraged because the image might not deploy if the public registry requires authentication. Use fully-qualified image names with public registries.

Red Hat internal or private registries typically support the use of image short names.

If you list public registries under the containerRuntimeSearchRegistries parameter, you expose your credentials to all the registries on the list and you risk network and registry attacks.

You cannot list multiple public registries under the containerRuntimeSearchRegistries parameter if each public registry requires different credentials and a cluster does not list the public registry in the global pull secret.

For a public registry that requires authentication, you can use an image short name only if the registry has its credentials stored in the global pull secret.

The Machine Config Operator (MCO) watches the image.config.openshift.io/cluster resource for any changes to the registries. When the MCO detects a change, it drains the nodes, applies the change, and uncordons the nodes. After the nodes return to the Ready state, if the containerRuntimeSearchRegistries parameter is added, the MCO creates a file in the /etc/containers/registries.conf.d directory on each node with the listed registries. The file overrides the default list of unqualified search registries in the /etc/containers/registries.conf file. There is no way to fall back to the default list of unqualified search registries.

The containerRuntimeSearchRegistries parameter works only with the Podman and CRI-O container engines. The registries in the list can be used only in pod specs, not in builds and image streams.

Procedure

  • Edit the image.config.openshift.io/cluster custom resource:

    1. $ oc edit image.config.openshift.io/cluster

    The following is an example image.config.openshift.io/cluster CR:

    1. apiVersion: config.openshift.io/v1
    2. kind: Image
    3. metadata:
    4. annotations:
    5. release.openshift.io/create-only: "true"
    6. creationTimestamp: "2019-05-17T13:44:26Z"
    7. generation: 1
    8. name: cluster
    9. resourceVersion: "8302"
    10. selfLink: /apis/config.openshift.io/v1/images/cluster
    11. uid: e34555da-78a9-11e9-b92b-06d6c7da38dc
    12. spec:
    13. allowedRegistriesForImport:
    14. - domainName: quay.io
    15. insecure: false
    16. additionalTrustedCA:
    17. name: myconfigmap
    18. registrySources:
    19. containerRuntimeSearchRegistries: (1)
    20. - reg1.io
    21. - reg2.io
    22. - reg3.io
    23. allowedRegistries: (2)
    24. - example.com
    25. - quay.io
    26. - registry.redhat.io
    27. - reg1.io
    28. - reg2.io
    29. - reg3.io
    30. - image-registry.openshift-image-registry.svc:5000
    31. ...
    32. status:
    33. internalRegistryHostname: image-registry.openshift-image-registry.svc:5000
    1Specify registries to use with image short names. You should use image short names with only internal or private registries to reduce possible security risks.
    2Ensure that any registries listed under containerRuntimeSearchRegistries are included in the allowedRegistries list.

    When the allowedRegistries parameter is defined, all registries, including the registry.redhat.io and quay.io registries and the default OpenShift image registry, are blocked unless explicitly listed. If you use this parameter, to prevent pod failure, add all registries including the registry.redhat.io and quay.io registries and the internalRegistryHostname to the allowedRegistries list, as they are required by payload images within your environment. For disconnected clusters, mirror registries should also be added.

Verification

  • Enter the following command to obtain a list of your nodes:

    1. $ oc get nodes

    Example output

    1. NAME STATUS ROLES AGE VERSION
    2. <node_name> Ready control-plane,master 37m v1.27.8+4fab27b
    1. Run the following command to enter debug mode on the node:

      1. $ oc debug node/<node_name>
    2. When prompted, enter chroot /host into the terminal:

      1. sh-4.4# chroot /host
    3. Enter the following command to check that the registries have been added to the policy file:

      1. sh-5.1# cat /etc/containers/registries.conf.d/01-image-searchRegistries.conf

      Example output

      1. unqualified-search-registries = ['reg1.io', 'reg2.io', 'reg3.io']

Configuring additional trust stores for image registry access

The image.config.openshift.io/cluster custom resource can contain a reference to a config map that contains additional certificate authorities to be trusted during image registry access.

Prerequisites

  • The certificate authorities (CA) must be PEM-encoded.

Procedure

You can create a config map in the openshift-config namespace and use its name in AdditionalTrustedCA in the image.config.openshift.io custom resource to provide additional CAs that should be trusted when contacting external registries.

The config map key is the hostname of a registry with the port for which this CA is to be trusted, and the PEM certificate content is the value, for each additional registry CA to trust.

Image registry CA config map example

  1. apiVersion: v1
  2. kind: ConfigMap
  3. metadata:
  4. name: my-registry-ca
  5. data:
  6. registry.example.com: |
  7. -----BEGIN CERTIFICATE-----
  8. ...
  9. -----END CERTIFICATE-----
  10. registry-with-port.example.com..5000: | (1)
  11. -----BEGIN CERTIFICATE-----
  12. ...
  13. -----END CERTIFICATE-----
1If the registry has the port, such as registry-with-port.example.com:5000, : should be replaced with ...

You can configure additional CAs with the following procedure.

  • To configure an additional CA:

    1. $ oc create configmap registry-config --from-file=<external_registry_address>=ca.crt -n openshift-config
    1. $ oc edit image.config.openshift.io cluster
    1. spec:
    2. additionalTrustedCA:
    3. name: registry-config

Configuring image registry repository mirroring

Setting up container registry repository mirroring enables you to perform the following tasks:

  • Configure your OKD cluster to redirect requests to pull images from a repository on a source image registry and have it resolved by a repository on a mirrored image registry.

  • Identify multiple mirrored repositories for each target repository, to make sure that if one mirror is down, another can be used.

Repository mirroring in OKD includes the following attributes:

  • Image pulls are resilient to registry downtimes.

  • Clusters in disconnected environments can pull images from critical locations, such as quay.io, and have registries behind a company firewall provide the requested images.

  • A particular order of registries is tried when an image pull request is made, with the permanent registry typically being the last one tried.

  • The mirror information you enter is added to the /etc/containers/registries.conf file on every node in the OKD cluster.

  • When a node makes a request for an image from the source repository, it tries each mirrored repository in turn until it finds the requested content. If all mirrors fail, the cluster tries the source repository. If successful, the image is pulled to the node.

Setting up repository mirroring can be done in the following ways:

  • At OKD installation:

    By pulling container images needed by OKD and then bringing those images behind your company’s firewall, you can install OKD into a datacenter that is in a disconnected environment.

  • After OKD installation:

    If you did not configure mirroring during OKD installation, you can do so postinstallation by using one of the following custom resource (CR) objects:

    • ImageDigestMirrorSet. This CR allows you to pull images from a mirrored registry by using digest specifications.

    • ImageTagMirrorSet. This CR allows you to pull images from a mirrored registry by using image tags.

    Using an ImageContentSourcePolicy (ICSP) object to configure repository mirroring is a deprecated feature. Deprecated functionality is still included in OKD and continues to be supported; however, it will be removed in a future release of this product and is not recommended for new deployments. If you have existing YAML files that you used to create ImageContentSourcePolicy objects, you can use the oc adm migrate icsp command to convert those files to an ImageDigestMirrorSet YAML file. For more information, see “Converting ImageContentSourcePolicy (ICSP) files for image registry repository mirroring” in the following section.

Both of these custom resource objects identify the following information:

  • The source of the container image repository you want to mirror.

  • A separate entry for each mirror repository you want to offer the content requested from the source repository.

If your cluster uses an ImageDigestMirrorSet or ImageTagMirrorSet object to configure repository mirroring, you can use only global pull secrets for mirrored registries. You cannot add a pull secret to a project.

The following procedure creates a postinstallation mirror configuration, where you create an ImageDigestMirrorSet object.

Prerequisites

  • Access to the cluster as a user with the cluster-admin role.

  • Ensure that there are no ImageContentSourcePolicy objects on your cluster. For example, you can use the following command:

    1. $ oc get ImageContentSourcePolicy

    Example output

    1. No resources found

Procedure

  1. Configure mirrored repositories, by either:

    • Setting up a mirrored repository with Red Hat Quay, as described in Red Hat Quay Repository Mirroring. Using Red Hat Quay allows you to copy images from one repository to another and also automatically sync those repositories repeatedly over time.

    • Using a tool such as skopeo to copy images manually from the source directory to the mirrored repository.

      For example, after installing the skopeo RPM package on a Red Hat Enterprise Linux (RHEL) 7 or RHEL 8 system, use the skopeo command as shown in this example:

      1. $ skopeo copy \
      2. docker://registry.access.redhat.com/ubi9/ubi-minimal:latest@sha256:5cf... \
      3. docker://example.io/example/ubi-minimal

      In this example, you have a container image registry that is named example.io with an image repository named example to which you want to copy the ubi9/ubi-minimal image from registry.access.redhat.com. After you create the registry, you can configure your OKD cluster to redirect requests made of the source repository to the mirrored repository.

  2. Log in to your OKD cluster.

  3. Create an ImageDigestMirrorSet or ImageTagMirrorSet CR, as needed, replacing the source and mirrors with your own registry and repository pairs and images:

    1. apiVersion: config.openshift.io/v1 (1)
    2. kind: ImageDigestMirrorSet (2)
    3. metadata:
    4. name: ubi9repo
    5. spec:
    6. imageDigestMirrors: (3)
    7. - mirrors:
    8. - example.io/example/ubi-minimal (4)
    9. - example.com/example/ubi-minimal (5)
    10. source: registry.access.redhat.com/ubi9/ubi-minimal (6)
    11. mirrorSourcePolicy: AllowContactingSource (7)
    12. - mirrors:
    13. - mirror.example.com/redhat
    14. source: registry.redhat.io/openshift4 (8)
    15. mirrorSourcePolicy: AllowContactingSource
    16. - mirrors:
    17. - mirror.example.com
    18. source: registry.redhat.io (9)
    19. mirrorSourcePolicy: AllowContactingSource
    20. - mirrors:
    21. - mirror.example.net/image
    22. source: registry.example.com/example/myimage (10)
    23. mirrorSourcePolicy: AllowContactingSource
    24. - mirrors:
    25. - mirror.example.net
    26. source: registry.example.com/example (11)
    27. mirrorSourcePolicy: AllowContactingSource
    28. - mirrors:
    29. - mirror.example.net/registry-example-com
    30. source: registry.example.com (12)
    31. mirrorSourcePolicy: AllowContactingSource
    1Indicates the API to use with this CR. This must be config.openshift.io/v1.
    2Indicates the kind of object according to the pull type:
    • ImageDigestMirrorSet: Pulls a digest reference image.

    • ImageTagMirrorSet: Pulls a tag reference image.

    3Indicates the type of image pull method, either:
    • imageDigestMirrors: Use for an ImageDigestMirrorSet CR.

    • imageTagMirrors: Use for an ImageTagMirrorSet CR.

    4Indicates the name of the mirrored image registry and repository.
    5Optional: Indicates a secondary mirror repository for each target repository. If one mirror is down, the target repository can use another mirror.
    6Indicates the registry and repository source, which is the repository that is referred to in image pull specifications.
    7Optional: Indicates the fallback policy if the image pull fails:
    • AllowContactingSource: Allows continued attempts to pull the image from the source repository. This is the default.

    • NeverContactSource: Prevents continued attempts to pull the image from the source repository.

    8Optional: Indicates a namespace inside a registry, which allows you to use any image in that namespace. If you use a registry domain as a source, the object is applied to all repositories from the registry.
    9Optional: Indicates a registry, which allows you to use any image in that registry. If you specify a registry name, the object is applied to all repositories from a source registry to a mirror registry.
    10Pulls the image registry.example.com/example/myimage@sha256:…​ from the mirror mirror.example.net/image@sha256:...
    11Pulls the image registry.example.com/example/image@sha256:…​ in the source registry namespace from the mirror mirror.example.net/image@sha256:…​.
    12Pulls the image registry.example.com/myimage@sha256 from the mirror registry example.net/registry-example-com/myimage@sha256:…​. The ImageContentSourcePolicy resource is applied to all repositories from a source registry to a mirror registry mirror.example.net/registry-example-com.
  4. Create the new object:

    1. $ oc create -f registryrepomirror.yaml

    After the object is created, the Machine Config Operator (MCO) cordons the nodes as the new settings are deployed to each node. The MCO restarts the nodes for an ImageTagMirrorSet object only. The MCO does not restart the nodes for ImageDigestMirrorSet objects. When the nodes are uncordoned, the cluster starts using the mirrored repository for requests to the source repository.

  5. To check that the mirrored configuration settings are applied, do the following on one of the nodes.

    1. List your nodes:

      1. $ oc get node

      Example output

      1. NAME STATUS ROLES AGE VERSION
      2. ip-10-0-137-44.ec2.internal Ready worker 7m v1.28.5
      3. ip-10-0-138-148.ec2.internal Ready master 11m v1.28.5
      4. ip-10-0-139-122.ec2.internal Ready master 11m v1.28.5
      5. ip-10-0-147-35.ec2.internal Ready worker 7m v1.28.5
      6. ip-10-0-153-12.ec2.internal Ready worker 7m v1.28.5
      7. ip-10-0-154-10.ec2.internal Ready master 11m v1.28.5
    2. Start the debugging process to access the node:

      1. $ oc debug node/ip-10-0-147-35.ec2.internal

      Example output

      1. Starting pod/ip-10-0-147-35ec2internal-debug ...
      2. To use host binaries, run `chroot /host`
    3. Change your root directory to /host:

      1. sh-4.2# chroot /host
    4. Check the /etc/containers/registries.conf file to make sure the changes were made:

      1. sh-4.2# cat /etc/containers/registries.conf

      The following output represents a registries.conf file where an ImageDigestMirrorSet object and an ImageTagMirrorSet object were applied. The final two entries are marked digest-only and tag-only respectively.

      Example output

      1. unqualified-search-registries = ["registry.access.redhat.com", "docker.io"]
      2. short-name-mode = ""
      3. [[registry]]
      4. prefix = ""
      5. location = "registry.access.redhat.com/ubi9/ubi-minimal" (1)
      6. [[registry.mirror]]
      7. location = "example.io/example/ubi-minimal" (2)
      8. pull-from-mirror = "digest-only" (3)
      9. [[registry.mirror]]
      10. location = "example.com/example/ubi-minimal"
      11. pull-from-mirror = "digest-only"
      12. [[registry]]
      13. prefix = ""
      14. location = "registry.example.com"
      15. [[registry.mirror]]
      16. location = "mirror.example.net/registry-example-com"
      17. pull-from-mirror = "digest-only"
      18. [[registry]]
      19. prefix = ""
      20. location = "registry.example.com/example"
      21. [[registry.mirror]]
      22. location = "mirror.example.net"
      23. pull-from-mirror = "digest-only"
      24. [[registry]]
      25. prefix = ""
      26. location = "registry.example.com/example/myimage"
      27. [[registry.mirror]]
      28. location = "mirror.example.net/image"
      29. pull-from-mirror = "digest-only"
      30. [[registry]]
      31. prefix = ""
      32. location = "registry.redhat.io"
      33. [[registry.mirror]]
      34. location = "mirror.example.com"
      35. pull-from-mirror = "digest-only"
      36. [[registry]]
      37. prefix = ""
      38. location = "registry.redhat.io/openshift4"
      39. [[registry.mirror]]
      40. location = "mirror.example.com/redhat"
      41. pull-from-mirror = "digest-only"
      42. [[registry]]
      43. prefix = ""
      44. location = "registry.access.redhat.com/ubi9/ubi-minimal"
      45. blocked = true (4)
      46. [[registry.mirror]]
      47. location = "example.io/example/ubi-minimal-tag"
      48. pull-from-mirror = "tag-only" (5)
      1Indicates the repository that is referred to in a pull spec.
      2Indicates the mirror for that repository.
      3Indicates that the image pull from the mirror is a digest reference image.
      4Indicates that the NeverContactSource parameter is set for this repository.
      5Indicates that the image pull from the mirror is a tag reference image.
    5. Pull an image to the node from the source and check if it is resolved by the mirror.

      1. sh-4.2# podman pull --log-level=debug registry.access.redhat.com/ubi9/ubi-minimal@sha256:5cf...

Troubleshooting repository mirroring

If the repository mirroring procedure does not work as described, use the following information about how repository mirroring works to help troubleshoot the problem.

  • The first working mirror is used to supply the pulled image.

  • The main registry is only used if no other mirror works.

  • From the system context, the Insecure flags are used as fallback.

  • The format of the /etc/containers/registries.conf file has changed recently. It is now version 2 and in TOML format.

  • You cannot add the same repository to both an ImageDigestMirrorSet and an ImageTagMirrorSet object.

Additional resources

Converting ImageContentSourcePolicy (ICSP) files for image registry repository mirroring

Using an ImageContentSourcePolicy (ICSP) object to configure repository mirroring is a deprecated feature. This functionality is still included in OKD and continues to be supported; however, it will be removed in a future release of this product and is not recommended for new deployments.

ICSP objects are being replaced by ImageDigestMirrorSet and ImageTagMirrorSet objects to configure repository mirroring. If you have existing YAML files that you used to create ImageContentSourcePolicy objects, you can use the oc adm migrate icsp command to convert those files to an ImageDigestMirrorSet YAML file. The command updates the API to the current version, changes the kind value to ImageDigestMirrorSet, and changes spec.repositoryDigestMirrors to spec.imageDigestMirrors. The rest of the file is not changed.

For more information about ImageDigestMirrorSet or ImageTagMirrorSet objects, see “Configuring image registry repository mirroring” in the previous section.

Prerequisites

  • Access to the cluster as a user with the cluster-admin role.

  • Ensure that you have ImageContentSourcePolicy objects on your cluster.

Procedure

  1. Use the following command to convert one or more ImageContentSourcePolicy YAML files to an ImageDigestMirrorSet YAML file:

    1. $ oc adm migrate icsp <file_name>.yaml <file_name>.yaml <file_name>.yaml --dest-dir <path_to_the_directory>

    where:

    <file_name>

    Specifies the name of the source ImageContentSourcePolicy YAML. You can list multiple file names.

    --dest-dir

    Optional: Specifies a directory for the output ImageDigestMirrorSet YAML. If unset, the file is written to the current directory.

    For example, the following command converts the icsp.yaml and icsp-2.yaml file and saves the new YAML files to the idms-files directory.

    1. $ oc adm migrate icsp icsp.yaml icsp-2.yaml --dest-dir idms-files

    Example output

    1. wrote ImageDigestMirrorSet to idms-files/imagedigestmirrorset_ubi8repo.5911620242173376087.yaml
    2. wrote ImageDigestMirrorSet to idms-files/imagedigestmirrorset_ubi9repo.6456931852378115011.yaml
  2. Create the CR object by running the following command:

    1. $ oc create -f <path_to_the_directory>/<file-name>.yaml

    where:

    <path_to_the_directory>

    Specifies the path to the directory, if you used the --dest-dir flag.

    <file_name>

    Specifies the name of the ImageDigestMirrorSet YAML.