Bastion for IBM Cloud Pak on Airgap OpenShift¶
Ravi Ramnarayan
© IBM v3.89 2023-05-22
Goals¶
For IBM clients who operate disconnected (airgap) IT, the bastion host and registry are long term investments. This document provides steps to build and maintain the bastion host and container registry for IBM Cloud Pak for Integration (CP4I) products.
- Build insecure or secure image registries
- Update the registry
- Rebuild the registry
Target Audience¶
- IT Professionals with in depth knowledge of Linux, Kubernetes (k8s) and Openshift (OCP)
The skills to build the bastion host and the private container registry. - Experience with IBM Cloud Paks, API Connect and DataPower
If you wish to install IBM API Connect (APIC) after building the bastion and registry.
Configure Linux Bastion¶
Our focus is Mirroring images with a bastion host. For the larger context, please see Mirroring images for an air-gapped cluster.
Bastion OS & tools¶
- RHEL 8.6, 9.x work okay
root
user
For expedience, it is convenient to run asroot
. Not good practice.- Verify
openssl version >= 1.1.1
- Install
podman
&httpd-tools
dnf install podman
dnf install httpd-tools
Install OCP/CP4I bastion tools¶
-
OpenShift
oc
command
Get it from your OCP installation.
-
Install
Confirmibm-pak
Download the latest version from IBM/ibm-pak/releases.ibm-pak
installation:
oc ibm-pak --help
-
Set color ouptut (optional)
oc ibm-pak config color --enable true
ENV Variables for APIC images¶
-
Environment variables
Mirroring images with a bastion host section Set environment variables and download CASE files specifiesenv
settings. Operator, operand, and CASE versions contains appropriate values for the desired APIC version.
# For APIC export CASE_NAME=ibm-apiconnect export CASE_VERSION=4.0.2 export ARCH=amd64 export TARGET_REGISTRY=`hostname -f`:5000 # File to hold cp.icr.io authentication # *** Do NOT set this env at the start *** # Follow the steps in this document # export REGISTRY_AUTH_FILE=/opt/registry/auth/cp-auth.json
-
Activate & verify environment variables
Private container registry¶
Your enterprise might have an existing private container registry. You could:
- Use the existing corporate registry for IBM Cloud Pak images
- Create a new registry for IBM Cloud Pak images
You can make the private container registry insecure or secure, depending on your corporate standards. The insecure registry is the main flow of the document. Two tables contrast simple steps for Insecure & Secure registries. Complex Secure registry steps are in call out segments.
Create local repositories for authentication, certificates & data¶
Note: instead of
/opt
, choose a base directory which is under your (non-root user) control.
- Generate basic auth credentials
podman run --entrypoint htpasswd \ docker.io/library/httpd:2 -Bbn <user> <paswd> > /opt/registry/auth/htpasswd
- b provides the password via command
- B stores the password using Bcrypt encryption
- n display in standard output
Create an insecure container registry¶
podman run -d --name apic-registry -p 5000:5000 \
-v /opt/registry/data:/var/lib/registry \
-v /opt/registry/auth:/auth \
-e "REGISTRY_AUTH=htpasswd" \
-e "REGISTRY_AUTH_HTPASSWD_REALM=Registry Realm" \
-e REGISTRY_AUTH_HTPASSWD_PATH=/auth/htpasswd \
--restart=always \
docker.io/library/registry:2
Call Out 1: Create a secure container registry¶
Return from Call Out 1¶
Mirror images to your private container registry¶
Setup ibm-pak
¶
-
Configure the plug-in to download CASEs as OCI artifacts from IBM Cloud Container Registry (ICCR).
-
Download the API Connect image inventory
The files will be placed in$HOME/.ibm-pak
. -
Generate mirror manifests
The command creates files to configure OCP in
~/.ibm-pak/data/mirror/$CASE_NAME/$CASE_VERSION
:
catalog-sources.yaml
catalog-sources-linux-<arch>.yaml
(arch specific catalog sources)
image-content-source-policy.yaml
images-mapping.txt
-
Preemptive fix for CASE_NAME
ibm-apiconnect
Apply the fix described in Airgap install failure due tounable to retrieve source image docker.io
to~/.ibm-pak/data/mirror/$CASE_NAME/$CASE_VERSION/images-mapping.txt
. Please use the workaround as long as the link Airgap install failure due to 'unable to retrieve source image docker.io' is active.Note: Include this step in your dev-ops process.
-
Configure credentials for the IBM Entitled Registry on Bastion
- Define
$REGISTRY_AUTH_FILE
file to hold credentials
# File to hold cp.icr.io authentication for APIC export REGISTRY_AUTH_FILE=/opt/registry/auth/cp-auth.json
- Populate
$REGISTRY_AUTH_FILE
with IBM Entitlement Key credentials forcp.icr.io
- Populate
$REGISTRY_AUTH_FILE
withapic-registry
credentials
Insecure Registry Secure Registry # podman login $TARGET_REGISTRY --tls-verify=false
# podman login $TARGET_REGISTRY
Username: <user>
Username: <user>
Password: <password>
Password: <password>
Login Succeeded!
Login Succeeded!
- Confirm $REGISTRY_AUTH_FILE contains both credentials
- Define
Note: Backup specific files and folders from
~/.ibm-pak
, as detailed in Rebuild bastion repository.
Populate bastion with images¶
Fork the job to the background, as it could run for hours.
Redable version of oc image mirror
command¶
Insecure Registry | Secure Registry |
---|---|
nohup oc image mirror \ |
nohup oc image mirror \ |
-f ~/.ibm-pak/data/mirror/$CASE_NAME/$CASE_VERSION/images-mapping.txt \ |
-f ~/.ibm-pak/data/mirror/$CASE_NAME/$CASE_VERSION/images-mapping.txt \ |
-a $REGISTRY_AUTH_FILE \ |
-a $REGISTRY_AUTH_FILE \ |
--insecure \ |
--filter-by-os '.*' \ |
--filter-by-os '.*' \ |
--skip-multiple-scopes \ |
--skip-multiple-scopes \ |
--max-per-registry=1 \ |
--max-per-registry=1 \ |
--continue-on-error=true > my-mirror-progress.txt 2>&1 & |
--continue-on-error=true > my-mirror-progress.txt 2>&1 & |
Copy/paste friendly version of oc image mirror
command¶
Insecure Registry | Secure Registry |
---|---|
nohup oc image mirror -f ~/.ibm-pak/data/mirror/$CASE_NAME/$CASE_VERSION/images-mapping.txt -a $REGISTRY_AUTH_FILE --insecure --filter-by-os '.*' --skip-multiple-scopes --max-per-registry=1 --continue-on-error=true > my-mirror-progress.txt 2>&1 & |
nohup oc image mirror -f ~/.ibm-pak/data/mirror/$CASE_NAME/$CASE_VERSION/images-mapping.txt -a $REGISTRY_AUTH_FILE --filter-by-os '.*' --skip-multiple-scopes --max-per-registry=1 --continue-on-error=true > my-mirror-progress.txt 2>&1 & |
Rinse & repeat¶
Observe progress with ps <pid>
, top
and tail my-mirror-progress.txt
. When the job completes, search my-mirror-progress.txt
for "error
".
- If the job fails with "
too many requests
", run it again.
Rinse & repeat until it completes with "info: Mirroring completed in 8m33.3s (12.65MB/s)
". - If you see "
unable to retrieve source image docker.io/ibmcom/
":
Apply the fix described in Airgap install failure due to 'unable to retrieve source image docker.io' to~/.ibm-pak/data/mirror/$CASE_NAME/$CASE_VERSION/images-mapping.txt
. And run theoc image mirror
command again.
Configure the OCP cluster¶
Login to OCP CLI
oc login --token=sha256~ejwjQ79...nvFbQYYyOc --server=https://api.rr4.cp.myco.com:6443
Logged into "https://api.rr4.cp.myco.com:6443" as "kube:admin" using the token provided.
You have access to 63 projects, the list has been suppressed. You can list all projects with 'oc projects'
Using project "default".
Configure the OCP pull-secret for the APIC registry¶
Steps are from Updating the global cluster pull secret
You may use the steps below or use OCP GUI.
- Download the OCP
pull-secret
-
Append your registry credentials to $PULL_SECRET_LOCATION
The command will NOT change existing credentials. -
Update the OCP
pull-secret
Note: The command will replace the pull-secret with the file's contents.
-
Verify the OCP
pull-secret
using the OCP GUI
Create the OCP ImageContentSourcePolicy (ICSP)¶
- Is ImageContentSourcePolicy defined for $CASE_NAME in OCP?
- Examine the file generated in Mirror images to your private container registry
The settings should be appropriate, unless you have special reasons to modify ImageContentSourcePolicy foribm-apiconnct
.
Connect your registry to OCP¶
Insecure Registry¶
Recommend defining insecure registries manually in OCP. Edit the image.config.openshift.io/cluster
and insert the bastion docker registry. You might find more than one insecure docker registries in use. For example, the client might use a different registry for OCP images. Slide the current registry into the mix.
-
Examine existing insecure registries in OCP
In this case, there is an insecure registry. Edit the YAML manually on the OCP GUI, the interactive CLIoc get image.config.openshift.io/cluster -o yaml | grep -i -B2 -A4 insecureRegistries spec: registrySources: insecureRegistries: - already-here.myco.com:5000 status: internalRegistryHostname: image-registry.openshift-image-registry.svc:5000
oc edit
or by downloading the YAML file. Alternatively, you could useoc patch
with carefully composed JSON which specifies current and additonal registries. -
The following command will result in a single insecure registry, even if there were others in the list.
For lab use only:
Call Out 2 Secure Registry¶
Return from Call Out 2¶
Install Catalog Sources¶
Note: Ensure all Nodes & MachineConfigPools are Ready.
Adding catalog sources to a cluster, section Adding specific catalog sources for each operator:
-
Apply catalog sources
-
Apply \$ARCH specific catalog sources, if such files exist:
- List catalog sources defined in OCP:
# oc get catalogsource -n openshift-marketplace NAME DISPLAY TYPE PUBLISHER AGE certified-operators Certified Operators grpc Red Hat 5h39m cloud-native-postgresql-catalog ibm-cloud-native-postgresql-4.8.0+20221102.113620 grpc IBM 2m48s community-operators Community Operators grpc Red Hat 5h39m ibm-apiconnect-catalog ibm-apiconnect-4.0.2 grpc IBM 2m48s ibm-datapower-operator-catalog ibm-datapower-operator-1.6.5-linux-amd64 grpc IBM 70s opencloud-operators ibm-cp-common-services-1.17.0 grpc IBM 2m48s redhat-marketplace Red Hat Marketplace grpc Red Hat 5h39m redhat-operators Red Hat Operators grpc Red Hat 5h39m
Install Operators & API Connect¶
You can proceed to create a namespace, storage classes, install the IBM API Connect operator in the desired namespace and create an instance of APIC.
Update APIC with new release¶
When there is new release of APIC, you can update the existing registry. For example, the registry was built with CASE_NAME=ibm-apiconnect
& CASE_VERSION=4.0.2
.
-
Tweak the environment variables Set
CASE_VERSION=4.0.3
. The other environment variables stay the same. Verify values with:
-
Download the API Connect image inventory
-
Generate mirror manifests
-
Mirror images to the TARGET_REGISTRY
Note: We presume that credentials and entitlement keys have not changed.
Use the
nohup oc image mirror
command appropriate for your insecure or secure bastion registry from Populate bastion with images -
Image Content Source Policy (ICSP)
Apply the new ICSP (might not have changed). -
Install Catalog Sources
Note: Examine
~/.ibm-pak/data/mirror/${CASE_NAME}/${CASE_VERSION}
to determine if there any \$ARCH specificcatalog-sources
files.-
Apply catalog sources
-
Apply \$ARCH specific catalog sources
- List catalog sources defined in OCP:
-
-
Update APIC on OCP web console
Subscribe to APIC Operator Channel v3.2 and Operator Version 3.2.1, which corresponds to CASE_VERSION 4.0.3. Reference: Operator, operand, and CASE versions. - Follow upgrade steps in the IBM API Connect document
Rebuild bastion repository¶
In case you need to rebuild the bastion repository, follow the steps below to build a replica of the images in the old registry.
Prerequisites¶
- Setup OS & OCP/CP4I bastion tools
Configure Linux Bastion - Use the same values for:
CASE_NAME
CASE_VERSION
ARCH -
Files from the old bastion
Assuming the old bastion was built withibm-pak
:- Config
Transfer the file.ibm-pak/config/config.yaml
to the same path in the new bastion. - CASE files
Transfer files in~/.ibm-pak/data/cases
to the new bastion using the same directory path.
Note: Backup
~/.ibm-pak
as safety net. - Config
Build the new bastion¶
- Create the podman registry
Follow the recipe in Create your private container registry. - Mirror images to your private container registry
- Section Setup ibm-pak
Start at Generate mirror manifests .Note: The prior steps, especially
oc ibm-pak get $CASE_NAME --version $CASE_VERSION
will create a new manifest which is likely to lead to a different set of images, not a replica of the old bastion. - Section Populate bastion with images
Run all steps. - Section Configure the OCP cluster
Run all steps.
- Section Setup ibm-pak
- Verify installation
IBM API Connect, DataPower & Common (Foundational) Services should be unaffected as the podman registry contains the same imagess as the old bastion.
Call Outs for Secure Registry¶
Create a secure container registry¶
If your enterprise requires secure communications, you should obtain TLS .crt & .key files appropriate for the bastion host. Self signed certificates do not result in secure registries unless you define trusts on the bastion server and on OCP. This document provides steps to create and use self signed TLS. For corporate TLS, you might not need to prime trust settings on the bastion server.
Please see How to implement a simple personal/private Linux container image registry for internal use section Start the registry for details. This document details steps to create and use self signed TLS.
If you really wish to use self signed certificates, see Setting up additional trusted certificate authorities for builds .
MyCA Authority¶
- Generate the private key
openssl genrsa -out my-ca-privkey.pem 2048
- Create MyCA certificate
The subject parameters are in ca-cert.conf
- Make MyCA a trusted authority on bastion server
- Verify #1
- Verify #2
Bastion TLS key & cert¶
- Generate the private key & certificate signing request
The subject parameters are in bastion.conf:
- Create the bastion certificate
openssl x509 -req -in bastion.csr -CA my-ca-cert.pem -CAkey my-ca-privkey.pem \ -out bastion-cert.pem -CAcreateserial -days 265 -sha256 \ -extensions v3_req -extfile bastion.conf
-
Examine the bastion certificate
An alternate approach to examine Subject Alternate Name (SAN):
-
Place the files in
/opt/registry/certs/
Start the secure registry¶
podman run -d --name apic-registry -p 5000:5000 \
-v /opt/registry/data:/var/lib/registry \
-v /opt/registry/auth:/auth \
-e "REGISTRY_AUTH=htpasswd" \
-e "REGISTRY_AUTH_HTPASSWD_REALM=Registry Realm" \
-e REGISTRY_AUTH_HTPASSWD_PATH=/auth/htpasswd \
-v /opt/registry/certs:/certs:z \
-e "REGISTRY_HTTP_TLS_CERTIFICATE=/certs/bastion-cert.pem" \
-e "REGISTRY_HTTP_TLS_KEY=/certs/bastion-privkey.pem" \
--restart=always \
docker.io/library/registry:2
Verify the registry's certificate¶
# echo | openssl s_client -connect $TARGET_REGISTRY -servername `hostname -f` \
| grep -B6 "Verification"
depth=1 C = US, ST = NY, L = Ether, O = MyCA, OU = MyCAOrg, CN = Ravi CA
verify return:1
depth=0 C = US, ST = FL, L = Gainesville, O = MyCo, OU = APIC, CN = onyx1.myco.com
verify return:1
No client certificate CA names sent
Peer signing digest: SHA256
Peer signature type: RSA-PSS
Server Temp Key: X25519, 253 bits
SSL handshake has read 1391 bytes and written 386 bytes
DONE
Verification: OK
Verify access to secure registry¶
Note: Do not use the
-k
option to bypass TLS.
Connect your secure registry to OCP¶
Secure Registry¶
You need to provide OCP with TLS credentials to trust the bastion image registry. Setting up additional trusted certificate authorities for builds provides the steps.
- Create a ConfigMap in the
openshift-config
namespace containing the trusted certificates for the registries that use self-signed certificates. For each CA file, ensure the key in the ConfigMap is the hostname of the registry in thehostname[..port]
format:
If you have multiple registries, place them all in registry-cas
with multiple --from-file
entries.
-
Modify in the cluster image configuration in
image.config.openshift.io/cluster
:
Recommend editing theimage.config.openshift.io/cluster
manually through the OCP GUI or CLI:
oc edit image.config.openshift.io/cluster
Define additionalspec: additionalTrustedCA: name: registry-cas allowedRegistriesForImport: - domainName: '<$TARGET_REGISTRY>' insecure: false
- domainName
entries for each secure registry.The image configuration entries in your installation might contain more entries. For an example, see
image.config.openshift.io/cluster CR
in Procedure Item 1 of 9.2.4. Adding registries that allow image short names
References¶
Docker / Podman Registries¶
- How to implement a simple personal/private Linux container image registry for internal use
Explainspodman
command to create a secure image registry. If you have a corporate TLS,this is all you need. If you need to create self signed TLS, there are other reference documents. - Setting up additional trusted certificate authorities for builds
Provides steps to define TLS trust in OCP whether you have a corporate or self signed TLS. - htpasswd - Manage user files for basic authentication