Chapter 14. Tutorial: Update component routes with custom domains and TLS certificates
You can modify the hostname and Transport Layer Security (TLS) certificate of the Web console, OAuth server, and Downloads component routes in Red Hat OpenShift Service on AWS classic architecture version 4.14 and later.
The changes that you make to the component routes in this tutorial are described in greater detail in the OpenShift Container Platform documentation, see resources about customizing the internal OAuth server URL, console route, and download route in Additional resources.
14.1. Prerequisites for updating component routes Copy linkLink copied to clipboard!
Review the following prerequisites before updating component routes.
-
The ROSA command-line interface (CLI) (
rosa) version 1.2.37 or later is installed. -
The AWS CLI (
aws) is installed. - You have a Red Hat OpenShift Service on AWS classic architecture cluster version 4.14 or later.
-
The OpenShift CLI (
oc) is installed. -
The
jqCLI tool is installed. -
You have access to the cluster as a user with the
cluster-adminrole. - OpenSSL is installed.
14.2. Set up your environment Copy linkLink copied to clipboard!
Set environment variables to ensure consistency across the commands within this tutorial.
Procedure
-
Log in to your cluster using an account with
cluster-adminprivileges. Configure an environment variable for your cluster name:
$ export CLUSTER_NAME=$(oc get infrastructure cluster -o=jsonpath="{.status.infrastructureName}" | sed 's/-[a-z0-9]\{5\}$//')Ensure all fields output correctly before moving to the next section:
$ echo "Cluster: ${CLUSTER_NAME}"Example output
Cluster: my-rosa-cluster
14.3. Find the current routes Copy linkLink copied to clipboard!
Find the base hostnames of your cluster routes and retrieve the ingress ID so you can update the routes with custom domains later.
Procedure
Verify that you can reach the component routes on their default hostnames.
You can find the hostnames by querying the lists of routes in the
openshift-consoleandopenshift-authenticationprojects.$ oc get routes -n openshift-console$ oc get routes -n openshift-authenticationExample output
NAME HOST/PORT PATH SERVICES PORT TERMINATION WILDCARD console console-openshift-console.apps.my-example-cluster-aws.z9a9.p1.openshiftapps.com ... 1 more console https reencrypt/Redirect None downloads downloads-openshift-console.apps.my-example-cluster-aws.z9a9.p1.openshiftapps.com ... 1 more downloads http edge/Redirect None NAME HOST/PORT PATH SERVICES PORT TERMINATION WILDCARD oauth-openshift oauth-openshift.apps.my-example-cluster-aws.z9a9.p1.openshiftapps.com ... 1 more oauth-openshift 6443 passthrough/Redirect NoneFrom this output you can see that your base hostname is
z9a9.p1.openshiftapps.com.Get the ID of the default ingress by running the following command:
$ export INGRESS_ID=$(rosa list ingress -c ${CLUSTER_NAME} -o json | jq -r '.[] | select(.default == true) | .id')Ensure all fields output correctly before moving to the next section:
$ echo "Ingress ID: ${INGRESS_ID}"Example output
Ingress ID: r3l6By running these commands you can see that the default component routes for your cluster are:
-
console-openshift-console.apps.my-example-cluster-aws.z9a9.p1.openshiftapps.comfor Console -
downloads-openshift-console.apps.my-example-cluster-aws.z9a9.p1.openshiftapps.comfor Downloads oauth-openshift.apps.my-example-cluster-aws.z9a9.p1.openshiftapps.comfor OAuthYou can use the
rosa edit ingresscommand to change the hostname of each service and add a TLS certificate for all of your component routes. The relevant parameters are shown in this excerpt of the command-line help for therosa edit ingresscommand:$ rosa edit ingress -h Edit a cluster ingress for a cluster. Usage: rosa edit ingress ID [flags] [...] --component-routes string Component routes settings. Available keys [oauth, console, downloads]. For each key a pair of hostname and tlsSecretRef is expected to be supplied. Format should be a comma separate list 'oauth: hostname=example-hostname;tlsSecretRef=example-secret-ref,downloads:...'For this example, you use the following custom component routes:
-
console.my-new-domain.devfor Console -
downloads.my-new-domain.devfor Downloads -
oauth.my-new-domain.devfor OAuth
-
14.4. Create a valid TLS certificate for each component route Copy linkLink copied to clipboard!
Create three separate self-signed Transport Layer Security (TLS) certificate key pairs and add them to your local trust store to verify that you can access the new component routes in a web browser.
This is for demonstration purposes only, and is not recommended as a solution for production workloads. Consult your certificate authority to understand how to create certificates with similar attributes for your production workloads.
To prevent issues with HTTP/2 connection coalescing, you must use a separate individual certificate for each endpoint. Using a wildcard or Subject Alternative Name (SAN) certificate is not supported.
Procedure
Generate a certificate for each component route, taking care to set the certificate’s subject (
-subj) to the custom domain of the component route you want to use:Example
$ openssl req -newkey rsa:2048 -new -nodes -x509 -days 365 -keyout key-console.pem -out cert-console.pem -subj "/CN=console.my-new-domain.dev"$ openssl req -newkey rsa:2048 -new -nodes -x509 -days 365 -keyout key-downloads.pem -out cert-downloads.pem -subj "/CN=downloads.my-new-domain.dev"$ openssl req -newkey rsa:2048 -new -nodes -x509 -days 365 -keyout key-oauth.pem -out cert-oauth.pem -subj "/CN=oauth.my-new-domain.dev"This generates three pairs of
.pemfiles,key-<component>.pemandcert-<component>.pem.
14.5. Add the certificates to the cluster as secrets Copy linkLink copied to clipboard!
Add the Transport Layer Security (TLS) certificates to your cluster as secrets by using the OpenShift CLI (oc) tool. Store the certificates as secrets in the openshift-config namespace so that you can reference them when you update the component routes later.
Procedure
Create three TLS secrets in the
openshift-confignamespace.These become your secret reference when you update the component routes.
$ oc create secret tls console-tls --cert=cert-console.pem --key=key-console.pem -n openshift-config$ oc create secret tls downloads-tls --cert=cert-downloads.pem --key=key-downloads.pem -n openshift-config$ oc create secret tls oauth-tls --cert=cert-oauth.pem --key=key-oauth.pem -n openshift-config
14.6. Find the hostname of the load balancer in your cluster Copy linkLink copied to clipboard!
When you create a cluster, the service creates a load balancer and generates a hostname for that load balancer. You need to know the load balancer hostname to create Domain Name System (DNS) records for your cluster.
Procedure
Run the following command against the
openshift-ingressnamespace.$ oc get svc -n openshift-ingressExample output
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE router-default LoadBalancer 172.30.237.88 a234gsr3242rsfsfs-1342r624.us-east-1.elb.amazonaws.com 80:31175/TCP,443:31554/TCP 76dThe hostname of the load balancer is the
EXTERNAL-IPassociated with therouter-defaultservice in theopenshift-ingressnamespace. In this example, the hostname isa234gsr3242rsfsfs-1342r624.us-east-1.elb.amazonaws.com.Save this value, because you need it to configure DNS records for your new component route hostnames.
14.7. Add component route DNS records to your hosting provider Copy linkLink copied to clipboard!
You can add component route Domain Name System (DNS) records to your hosting provider to map the new component route hostnames to the load balancer.
Procedure
-
In your hosting provider, add DNS records that map the
CNAMEof your new component route hostnames to the load balancer hostname that you found in Find the hostname of the load balancer in your cluster.
14.8. Update the component routes and TLS secret using the rosa CLI Copy linkLink copied to clipboard!
When your Domain Name System (DNS) records have been updated, change the component routes and Transport Layer Security (TLS) secret references to ensure your cluster traffic is routed correctly through your custom domain and protected with updated TLS certificates.
Procedure
Update your default ingress route with the new base domain and the secret reference associated with it, and update the hostnames for each component route:
$ rosa edit ingress -c ${CLUSTER_NAME} ${INGRESS_ID} --component-routes 'console: hostname=console.my-new-domain.dev;tlsSecretRef=console-tls,downloads: hostname=downloads.my-new-domain.dev;tlsSecretRef=downloads-tls,oauth: hostname=oauth.my-new-domain.dev;tlsSecretRef=oauth-tls'Alternatively, you can edit only a subset of the component routes by leaving the component routes you do not want to change set to an empty string. For example, to change only the Console and OAuth server hostnames and TLS certificates, run the following command:
$ rosa edit ingress -c ${CLUSTER_NAME} ${INGRESS_ID} --component-routes 'console: hostname=console.my-new-domain.dev;tlsSecretRef=console-tls,downloads: hostname="";tlsSecretRef="", oauth: hostname=oauth.my-new-domain.dev;tlsSecretRef=oauth-tls'Verify that your changes were successfully made:
$ rosa list ingress -c ${CLUSTER_NAME} -ojson | jq ".[] | select(.id == \"${INGRESS_ID}\") | .component_routes"Example output
{ "console": { "kind": "ComponentRoute", "hostname": "console.my-new-domain.dev", "tls_secret_ref": "console-tls" }, "downloads": { "kind": "ComponentRoute", "hostname": "downloads.my-new-domain.dev", "tls_secret_ref": "downloads-tls" }, "oauth": { "kind": "ComponentRoute", "hostname": "oauth.my-new-domain.dev", "tls_secret_ref": "oauth-tls" } }- Add your certificate to the truststore on your local system.
- Confirm that you can access your components at their new routes by using your local web browser.
14.9. Reset the component routes to the default using the rosa CLI Copy linkLink copied to clipboard!
You can use the ROSA command-line interface (CLI) (rosa) tool to reset the component routes to the default configuration if you no longer need your custom domain.
Procedure
Reset your component routes by running the following command:
$ rosa edit ingress -c ${CLUSTER_NAME} ${INGRESS_ID} --component-routes 'console: hostname="";tlsSecretRef="",downloads: hostname="";tlsSecretRef="", oauth: hostname="";tlsSecretRef=""'