|
| 1 | +// Module included in the following assemblies: |
| 2 | +// |
| 3 | +// * microshift_security_compliance/microshift-custom-ca.adoc |
| 4 | + |
| 5 | +:_mod-docs-content-type: PROCEDURE |
| 6 | +[id="microshift-custom-cas-configuring_{context}"] |
| 7 | += Configuring custom certificate authorities |
| 8 | + |
| 9 | +To configure externally generated certificates and domain names using custom certificate authorities (CAs), add them to the {microshift-short} `/etc/microshift/config.yaml` configuration file. You must also configure the host operating system trust root. |
| 10 | + |
| 11 | +[NOTE] |
| 12 | +==== |
| 13 | +Externally generated `kubeconfig` files are created in the `/var/lib/microshift/resources/kubeadmin/<hostname>/kubeconfig` directory. If you need to use `localhost` in addition to externally generated configurations, retain the original `kubeconfig` file in its default location. The `localhost` `kubeconfig` file uses the self-signed certificate authority. |
| 14 | +==== |
| 15 | + |
| 16 | +.Prerequisites |
| 17 | +* The OpenShift CLI (`oc`) is installed. |
| 18 | +* You have access to the cluster as a user with the cluster administration role. |
| 19 | +* The certificate authority has issued the custom certificates. |
| 20 | +* A {microshift-short} `/etc/microshift/config.yaml` configuration file exists. |
| 21 | +
|
| 22 | +.Procedure |
| 23 | + |
| 24 | +. Copy the custom certificates you want to add to the trust root of the {microshift-short} host. Ensure that the |
| 25 | +certificate and private keys are only accessible to {microshift-short}. |
| 26 | + |
| 27 | +. For each custom CA that you need, add an `apiServer` section called `namedCertificates` to the `/etc/microshift/config.yaml` {microshift-short} configuration file by using the following example: |
| 28 | ++ |
| 29 | +[source,yaml] |
| 30 | +---- |
| 31 | +apiServer: |
| 32 | + namedCertificates: |
| 33 | + - certPath: ~/certs/api_fqdn_1.crt <1> |
| 34 | + keyPath: ~/certs/api_fqdn_1.key <2> |
| 35 | + - certPath: ~/certs/api_fqdn_2.crt |
| 36 | + keyPath: ~/certs/api_fqdn_2.key |
| 37 | + names: <3> |
| 38 | + - api_fqdn_1 |
| 39 | + - *.apps.external.com |
| 40 | +---- |
| 41 | +<1> Add the full path to the certificate. |
| 42 | +<2> Add the full path to the certificate key. |
| 43 | +<3> Optional. Add a list of explicit DNS names. Leading wildcards are allowed. If no names are provided, the implicit names are extracted from the certificates. |
| 44 | +
|
| 45 | +. Restart the {microshift-service} to apply the certificates by running the following command: |
| 46 | ++ |
| 47 | +[source,terminal] |
| 48 | +---- |
| 49 | +$ systemctl microshift restart |
| 50 | +---- |
| 51 | +
|
| 52 | +. Wait a few minutes for the system to restart and apply the custom server. New `kubeconfig` files are generated in the `/var/lib/microshift/resources/kubeadmin/` directory. |
| 53 | +
|
| 54 | +. Copy the `kubeconfig` files to the client. If you specified wildcards for the IP address, update the `kubeconfig` to remove the public IP address of the server and replace that IP address with the specific wildcard range you want to use. |
| 55 | +
|
| 56 | +. From the client, use the following steps: |
| 57 | +
|
| 58 | +.. Specify the `kubeconfig` to use by running the following command: |
| 59 | ++ |
| 60 | +[source,terminal] |
| 61 | +---- |
| 62 | +$ export KUBECONFIG=~/custom-kubeconfigs/kubeconfig <1> |
| 63 | +---- |
| 64 | +<1> Use the location of the copied `kubeconfig` file as the path. |
| 65 | +
|
| 66 | +.. Check that the certificates are applied by using the following command: |
| 67 | ++ |
| 68 | +[source,terminal] |
| 69 | +---- |
| 70 | +$ oc --certificate-authority ~/certs/ca.ca get node |
| 71 | +---- |
| 72 | ++ |
| 73 | +.Example output |
| 74 | +[source,terminal] |
| 75 | +---- |
| 76 | +oc get node |
| 77 | +NAME STATUS ROLES AGE VERSION |
| 78 | +dhcp-1-235-195.arm.example.com Ready control-plane,master,worker 76m v1.29.2 |
| 79 | +---- |
| 80 | +
|
| 81 | +.. Add the new CA file to the $KUBECONFIG environment variable by running the following command: |
| 82 | ++ |
| 83 | +[source,terminal] |
| 84 | +---- |
| 85 | +$ oc config set clusters.microshift.certificate-authority /tmp/certificate-authority-data-new.crt |
| 86 | +---- |
| 87 | +
|
| 88 | +.. Verify that the new `kubeconfig` file contains the new CA by running the following command: |
| 89 | ++ |
| 90 | +[source,terminal] |
| 91 | +---- |
| 92 | +$ oc config view --flatten |
| 93 | +---- |
| 94 | ++ |
| 95 | +.Example externally generated `kubeconfig` file |
| 96 | ++ |
| 97 | +[source,yaml] |
| 98 | +---- |
| 99 | +apiVersion: v1 |
| 100 | +clusters: |
| 101 | +- cluster: |
| 102 | + certificate-authority: /tmp/certificate-authority-data-new.crt <1> |
| 103 | + server: https://api.ci-ln-k0gim2b-76ef8.aws-2.ci.openshift.org:6443 |
| 104 | + name: ci-ln-k0gim2b-76ef8 |
| 105 | +contexts: |
| 106 | +- context: |
| 107 | + cluster: ci-ln-k0gim2b-76ef8 |
| 108 | + user: |
| 109 | + name: |
| 110 | +current-context: |
| 111 | +kind: Config |
| 112 | +preferences: {} |
| 113 | +---- |
| 114 | +<1> The `certificate-authority-data` section is not present in externally generated `kubeconfig` files. It is added with the `oc config set` command used previously. |
| 115 | +
|
| 116 | +.. Verify the `subject` and `issuer` of your customized API server certificate authority by running the following command: |
| 117 | ++ |
| 118 | +[source,terminal] |
| 119 | +---- |
| 120 | +$ curl --cacert /tmp/caCert.pem https://${fqdn_name}:6443/healthz -v |
| 121 | +---- |
| 122 | ++ |
| 123 | +.Example output |
| 124 | +---- |
| 125 | +Server certificate: |
| 126 | + subject: CN=kas-test-cert_server |
| 127 | + start date: Mar 12 11:39:46 2024 GMT |
| 128 | + expire date: Mar 12 11:39:46 2025 GMT |
| 129 | + subjectAltName: host "dhcp-1-235-3.arm.eng.rdu2.redhat.com" matched cert's "dhcp-1-235-3.arm.eng.rdu2.redhat.com" |
| 130 | + issuer: CN=kas-test-cert_ca |
| 131 | + SSL certificate verify ok. |
| 132 | +---- |
| 133 | ++ |
| 134 | +[IMPORTANT] |
| 135 | +==== |
| 136 | +Either replace the `certificate-authority-data` in the generated `kubeconfig` file with the new `rootCA` or add the `certificate-authority-data` to the trust root of the operating system. Do not use both methods. |
| 137 | +==== |
| 138 | +
|
| 139 | +.. Configure additional CAs in the trust root of the operating system. For example, in the RHEL Client truststore on the client system. See link:https://access.redhat.com/documentation/en-us/red_hat_enterprise_linux/9/html/securing_networks/using-shared-system-certificates_securing-networks#the-system-wide-trust-store_using-shared-system-certificates[The system-wide truststore] for details. |
| 140 | +** Updating the certificate bundle with the configuration that contains the CA is recommended. |
| 141 | +** If you do not want to configure your certificate bundles, you can alternately use the `oc login localhost:8443 --certificate-authority=/path/to/cert.crt` command, but this method is not preferred. |
0 commit comments