Using Operator Lifecycle Manager on restricted networks

For OKD clusters that are installed on restricted networks, also known as disconnected clusters, Operator Lifecycle Manager (OLM) by default cannot access the Red Hat-provided OperatorHub sources hosted on remote registries because those remote sources require full Internet connectivity.

However, as a cluster administrator you can still enable your cluster to use OLM in a restricted network if you have a workstation that has full Internet access. The workstation, which requires full Internet access to pull the remote OperatorHub content, is used to prepare local mirrors of the remote sources, and push the content to a mirror registry.

The mirror registry can be located on a bastion host, which requires connectivity to both your workstation and the disconnected cluster, or a completely disconnected, or airgapped, host, which requires removable media to physically move the mirrored content to the disconnected environment.

This guide describes the following process that is required to enable OLM in restricted networks:

  • Disable the default remote OperatorHub sources for OLM.

  • Use a workstation with full Internet access to create and push local mirrors of the OperatorHub content to a mirror registry.

  • Configure OLM to install and manage Operators from local sources on the mirror registry instead of the default remote sources.

After enabling OLM in a restricted network, you can continue to use your unrestricted workstation to keep your local OperatorHub sources updated as newer versions of Operators are released.

While OLM can manage Operators from local sources, the ability for a given Operator to run successfully in a restricted network still depends on the Operator itself. The Operator must:

  • List any related images, or other container images that the Operator might require to perform their functions, in the relatedImages parameter of its ClusterServiceVersion (CSV) object.

  • Reference all specified images by a digest (SHA) and not by a tag.

See the following Red Hat Knowledgebase Article for a list of Red Hat Operators that support running in disconnected mode:

Additional resources

Prerequisites

  • Log in to your OKD cluster as a user with cluster-admin privileges.

  • If you want to prune the default catalog and selectively mirror only a subset of Operators, install the opm CLI.

If you are using OLM in a restricted network on IBM Z, you must have at least 12 GB allocated to the directory where you place your registry.

Disabling the default OperatorHub sources

Operator catalogs that source content provided by Red Hat and community projects are configured for OperatorHub by default during an OKD installation. In a restricted network environment, you must disable the default catalogs as a cluster administrator. You can then configure OperatorHub to use local catalog sources.

Procedure

  • Disable the sources for the default catalogs by adding disableAllDefaultSources: true to the OperatorHub object:

    1. $ oc patch OperatorHub cluster --type json \
    2. -p '[{"op": "add", "path": "/spec/disableAllDefaultSources", "value": true}]'

Alternatively, you can use the web console to manage catalog sources. From the AdministrationCluster SettingsGlobal ConfigurationOperatorHub page, click the Sources tab, where you can create, delete, disable, and enable individual sources.

Pruning an index image

An index image, based on the Operator Bundle Format, is a containerized snapshot of an Operator catalog. You can prune an index of all but a specified list of packages, which creates a copy of the source index containing only the Operators that you want.

When configuring Operator Lifecycle Manager (OLM) to use mirrored content on restricted network OKD clusters, use this pruning method if you want to only mirror a subset of Operators from the default catalogs.

For the steps in this procedure, the target registry is an existing mirror registry that is accessible by your workstation with unrestricted network access. This example also shows pruning the index image for the default catalog catalog, but the process is the same for any index image.

Prerequisites

  • Workstation with unrestricted network access

  • podman version 1.9.3+

  • grpcurl

  • opm version 1.12.3+

  • Access to a registry that supports Docker v2-2

Procedure

  1. Authenticate with your target registry:

    1. $ podman login <target_registry>
  2. Determine the list of packages you want to include in your pruned index.

    1. Run the source index image that you want to prune in a container. For example:

      1. $ podman run -p50051:50051 \
      2. -it quay.io/operatorhubio/catalog:latest

      Example output

      1. Trying to pull quay.io/operatorhubio/catalog:latest...
      2. Getting image source signatures
      3. Copying blob ae8a0c23f5b1 done
      4. ...
      5. INFO[0000] serving registry database=/database/index.db port=50051
    2. In a separate terminal session, use the grpcurl command to get a list of the packages provided by the index:

      1. $ grpcurl -plaintext localhost:50051 api.Registry/ListPackages > packages.out
    3. Inspect the packages.out file and identify which package names from this list you want to keep in your pruned index. For example:

      Example snippets of packages list

      1. ...
      2. {
      3. "name": "couchdb-operator"
      4. }
      5. ...
      6. {
      7. "name": "eclipse-che"
      8. }
      9. ...
      10. {
      11. {
      12. "name": "etcd"
      13. }
      14. ...
    4. In the terminal session where you executed the podman run command, press Ctrl and C to stop the container process.

  3. Run the following command to prune the source index of all but the specified packages:

    1. $ opm index prune \
    2. -f quay.io/operatorhubio/catalog:latest \(1)
    3. -p couchdb-operator,eclipse-che,etcd \(2)
    4. [-i quay.io/openshift/origin-operator-registry:4.6.0] \(3)
    5. -t <target_registry>:<port>/<namespace>/catalog:latest (4)
    1Index to prune.
    2Comma-separated list of packages to keep.
    3Required only for IBM Power Systems and IBM Z images: Operator Registry base image with the tag that matches the target OKD cluster major and minor version.
    4Custom tag for new index image being built.
  4. Run the following command to push the new index image to your target registry:

    1. $ podman push <target_registry>:<port>/<namespace>/catalog:latest

    where <namespace> is any existing namespace on the registry. For example, you might create an olm-mirror namespace to push all mirrored content to.

Mirroring an Operator catalog

You can mirror the Operator content of a Red Hat-provided catalog, or a custom catalog, into a container image registry using the oc adm catalog mirror command. The target registry must support Docker v2-2. For a cluster on a restricted network, this registry can be one that the cluster has network access to, such as a mirror registry created during a restricted network cluster installation.

The oc adm catalog mirror command also automatically mirrors the index image that is specified during the mirroring process, whether it be a Red Hat-provided index image or your own custom-built index image, to the target registry. You can then use the mirrored index image to create a catalog source that allows Operator Lifecycle Manager (OLM) to load the mirrored catalog onto your OKD cluster.

Prerequisites

  • Workstation with unrestricted network access.

  • podman version 1.9.3 or later.

  • Access to mirror registry that supports Docker v2-2.

  • Decide which namespace on your mirror registry you will use to store the mirrored Operator content. For example, you might create an olm-mirror namespace.

  • If your mirror registry does not have Internet access, connect removable media to your workstation with unrestricted network access.

  • If you are working with private registries, set the REG_CREDS environment variable to the file path of your registry credentials for use in later steps. For example, for the podman CLI:

    1. $ REG_CREDS=${XDG_RUNTIME_DIR}/containers/auth.json

Procedure

  1. The oc adm catalog mirror command extracts the contents of an index image to generate the manifests required for mirroring. The default behavior of the command generates manifests, then automatically mirrors all of the image content from the index image, as well as the index image itself, to your mirror registry. Alternatively, if your mirror registry is on a completely disconnected, or airgapped, host, you can first mirror the content to removable media, move the media to the disconnected environment, then mirror the content from the media to the registry.

    • Option A: If your mirror registry is on the same network as your workstation with unrestricted network access, take the following actions on your workstation:

      1. If your mirror registry requires authentication, run the following command to log in to the registry:

        1. $ podman login <mirror_registry>
      2. Run the following command to mirror the content:

        1. $ oc adm catalog mirror \
        2. <index_image> \(1)
        3. <mirror_registry>:<port>/<namespace> \(2)
        4. [-a ${REG_CREDS}] \(3)
        5. [--insecure] \(4)
        6. [--index-filter-by-os='<platform>/<arch>'] \(5)
        7. [--manifests-only] (6)
        1Specify the index image for the catalog you want to mirror. For example, this might be a pruned index image that you created previously, or one of the source index images for the default catalogs, such as quay.io/operatorhubio/catalog:latest.
        2Specify the target registry and namespace to mirror the Operator content to, where <namespace> is any existing namespace on the registry. For example, you might create an olm-mirror namespace to push all mirrored content to.
        3Optional: If required, specify the location of your registry credentials file.
        4Optional: If you do not want to configure trust for the target registry, add the —insecure flag.
        5Optional: Specify which platform and architecture of the index image to select when multiple variants are available. Images are passed as ‘<platform>/<arch>[/<variant>]’. This does not apply to images referenced by the index. Valid values are linux/amd64, linux/ppc64le, and linux/s390x.
        6Optional: Generate only the manifests required for mirroring, and do not actually mirror the image content to a registry. This option can be useful for reviewing what will be mirrored, and it allows you to make any changes to the mapping list if you require only a subset of packages. You can then use the mapping.txt file with the oc image mirror command to mirror the modified list of images in a later step. This flag is intended for only advanced selective mirroring of content from the catalog; the opm index prune command, if you used it previously to prune the index image, is suitable for most catalog management use cases.

        Example output

        1. src image has index label for database path: /database/index.db
        2. using database path mapping: /database/index.db:/tmp/153048078
        3. wrote database to /tmp/153048078 (1)
        4. ...
        5. wrote mirroring manifests to manifests-catalog-1614211642 (2)
        1Directory for the temporary index.db database generated by the command.
        2Record the manifests directory name that is generated. This directory name is used in a later step.
    • Option B: If your mirror registry is on a disconnected host, take the following actions.

      1. Run the following command on your workstation with unrestricted network access to mirror the content to local files:

        1. $ oc adm catalog mirror \
        2. <index_image> \(1)
        3. file:///local/index \(2)
        4. [-a ${REG_CREDS}] \
        5. [--insecure]
        1Specify the index image for the catalog you want to mirror. For example, this might be a pruned index image that you created previously, or one of the source index images for the default catalogs, such as quay.io/operatorhubio/catalog:latest.
        2Mirrors content to local files in your current directory.

        Example output

        1. ...
        2. info: Mirroring completed in 5.93s (5.915MB/s)
        3. wrote mirroring manifests to manifests-my-index-1614985528 (1)
        4. To upload local images to a registry, run:
        5. oc adm catalog mirror file://local/index/myrepo/my-index:v1 REGISTRY/REPOSITORY (2)
        1Record the manifests directory name that is generated. This directory name is used in a later step.
        2Record the expanded file:// path that based on your provided index image. This path is used in a later step.
      2. Copy the v2/ directory that is generated in your current directory to removable media.

      3. Physically remove the media and attach it to a host in the disconnected environment that has access to the mirror registry.

      4. If your mirror registry requires authentication, run the following command on your host in the disconnected environment to log in to the registry:

        1. $ podman login <mirror_registry>
      5. Run the following command from the parent directory containing the v2/ directory to upload the images from local files to the mirror registry:

        1. $ oc adm catalog mirror \
        2. file://local/index/<repo>/<index_image>:<tag> \(1)
        3. <mirror_registry>:<port>/<namespace> \(2)
        4. [-a ${REG_CREDS}] \
        5. [--insecure]
        1Specify the file:// path from the previous command output.
        2Specify the target registry and namespace to mirror the Operator content to, where <namespace> is any existing namespace on the registry. For example, you might create an olm-mirror namespace to push all mirrored content to.
  1. After mirroring the content to your registry, inspect the manifests directory that is generated in your current directory.

    The manifests directory name is used in a later step.

    If you mirrored content to a registry on the same network in the previous step, the directory name takes the following form:

    1. manifests-<index_image_name>-<random_number>

    If you mirrored content to a registry on a disconnected host in the previous step, the directory name takes the following form:

    1. manifests-index/<namespace>/<index_image_name>-<random_number>

    The manifests directory contains the following files, some of which might require further modification:

    • The catalogSource.yaml file is a basic definition for a CatalogSource object that is pre-populated with your index image tag and other relevant metadata. This file can be used as is or modified to add the catalog source to your cluster.

      If you mirrored the content to local files, you must modify your catalogSource.yaml file to remove any backslash (/) characters from the metadata.name field. Otherwise, when you attempt to create the object, it fails with an “invalid resource name” error.

    • The imageContentSourcePolicy.yaml file defines an ImageContentSourcePolicy object that can configure nodes to translate between the image references stored in Operator manifests and the mirrored registry.

      If your cluster uses an ImageContentSourcePolicy 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 mapping.txt file contains all of the source images and where to map them in the target registry. This file is compatible with the oc image mirror command and can be used to further customize the mirroring configuration.

      If you used the —manifests-only flag during the mirroring process and want to further trim the subset of packages to be mirrored, see the steps in the “Mirroring a Package Manifest Format catalog image” procedure about modifying your mapping.txt file and using the file with the oc image mirror command. After following those further actions, you can continue this procedure.

  2. On a host with access to the disconnected cluster, create the ImageContentSourcePolicy object by running the following command to specify the imageContentSourcePolicy.yaml file in your manifests directory:

    1. $ oc create -f <path/to/manifests/dir>/imageContentSourcePolicy.yaml

    where <path/to/manifests/dir> is the path to the manifests directory for your mirrored content.

You can now create a CatalogSource object to reference your mirrored index image and Operator content.

Additional resources

Creating a catalog from an index image

You can create an Operator catalog from an index image and apply it to an OKD cluster for use with Operator Lifecycle Manager (OLM).

Prerequisites

  • An index image built and pushed to a registry.

Procedure

  1. Create a CatalogSource object that references your index image. If you used the oc adm catalog mirror command to mirror your catalog to a target registry, you can use the generated catalogSource.yaml file as a starting point.

    1. Modify the following to your specifications and save it as a catalogSource.yaml file:

      1. apiVersion: operators.coreos.com/v1alpha1
      2. kind: CatalogSource
      3. metadata:
      4. name: my-operator-catalog (1)
      5. namespace: olm (2)
      6. spec:
      7. sourceType: grpc
      8. image: <registry>:<port>/<namespace>/catalog:latest (3)
      9. displayName: My Operator Catalog
      10. publisher: <publisher_name> (4)
      11. updateStrategy:
      12. registryPoll: (5)
      13. interval: 30m
      1If you want the catalog source to be available globally to users in all namespaces, specify the olm namespace. Otherwise, you can specify a different namespace for the catalog to be scoped and available only for that namespace.
      2If you mirrored content to local files before uploading to a registry, remove any backslash (/) characters from the metadata.name field to avoid an “invalid resource name” error when you create the object.
      3Specify your index image.
      4Specify your name or an organization name publishing the catalog.
      5Catalog sources can automatically check for new versions to keep up to date.
    2. Use the file to create the CatalogSource object:

      1. $ oc apply -f catalogSource.yaml
  2. Verify the following resources are created successfully.

    1. Check the pods:

      1. $ oc get pods -n olm

      Example output

      1. NAME READY STATUS RESTARTS AGE
      2. my-operator-catalog-6njx6 1/1 Running 0 28s
      3. marketplace-operator-d9f549946-96sgr 1/1 Running 0 26h
    2. Check the catalog source:

      1. $ oc get catalogsource -n olm

      Example output

      1. NAME DISPLAY TYPE PUBLISHER AGE
      2. my-operator-catalog My Operator Catalog grpc 5s
    3. Check the package manifest:

      1. $ oc get packagemanifest -n olm

      Example output

      1. NAME CATALOG AGE
      2. jaeger-product My Operator Catalog 93s

You can now install the Operators from the OperatorHub page on your OKD web console.

Updating an index image

After configuring OperatorHub to use a catalog source that references a custom index image, cluster administrators can keep the available Operators on their cluster up to date by adding bundle images to the index image.

You can update an existing index image using the opm index add command. For restricted networks, the updated content must also be mirrored again to the cluster.

Prerequisites

  • opm version 1.12.3+

  • podman version 1.9.3+

  • An index image built and pushed to a registry.

  • An existing catalog source referencing the index image.

Procedure

  1. Update the existing index by adding bundle images:

    1. $ opm index add \
    2. --bundles <registry>/<namespace>/<new_bundle_image>:<tag> \(1)
    3. --from-index <registry>/<namespace>/<existing_index_image>:<tag> \(2)
    4. --tag <registry>/<namespace>/<existing_index_image>:<tag> (3)
    1A comma-separated list of additional bundle images to add to the index.
    2The existing index that was previously pushed.
    3The image tag that you want the updated index image to have.
  2. Push the updated index image:

    1. $ podman push <registry>/<namespace>/<existing_index_image>:<tag>
  3. Follow the steps in the Mirroring an Operator catalog procedure again to mirror the updated content. However, when you get to the step about creating the ImageContentSourcePolicy (ICSP) object, use the oc replace command instead of the oc create command. For example:

    1. $ oc replace -f ./manifests-catalog-<random_number>/imageContentSourcePolicy.yaml

    This change is required because the object already exists and must be updated.

    Normally, the oc apply command can be used to update existing objects that were previously created using oc apply. However, due to a known issue regarding the size of the metadata.annotations field in ICSP objects, the oc replace command must be used for this step currently.

  4. After Operator Lifecycle Manager (OLM) automatically polls the index image referenced in the catalog source at its regular interval, verify that the new packages are successfully added:

    1. $ oc get packagemanifests -n openshift-marketplace

Additional resources