|
| 1 | +// Module included in the following assemblies: |
| 2 | +// |
| 3 | +// * security/certificates/api-server.adoc |
| 4 | + |
| 5 | +:_content-type: PROCEDURE |
| 6 | +[id="replace-the-certificate-authority_{context}"] |
| 7 | + |
| 8 | += Replace the installer-generated kubeconfig before replacing it with a newly generated CA certificate |
| 9 | + |
| 10 | +The installer-generated kubeconfig cannot be removed, but it can be invalidated and replaced with a newly generated CA certificate. |
| 11 | + |
| 12 | +You may choose to invalidate the installer-generated kubeconfig, stored in the `admin-kubeconfig-client-ca` configmap under the `openshift-config` namespace, when: |
| 13 | + |
| 14 | +* You don't trust who installed the cluster |
| 15 | +* The kubeconfig is leaked |
| 16 | +* Other security-related needs exist, such as periodic rotation of the kubeconfig |
| 17 | + |
| 18 | +[IMPORTANT] |
| 19 | +==== |
| 20 | +To avoid being locked out of the cluster, have an alternative way to login, such as, using an OAuth-authenticated administrator user or using a client certificate signed by an additional client CA. |
| 21 | +==== |
| 22 | + |
| 23 | +.Procedure |
| 24 | + |
| 25 | +. Optional: Generate a new self-signed CA, unless an existing corporate or other CA is to be used. |
| 26 | ++ |
| 27 | +[source,terminal] |
| 28 | +---- |
| 29 | +$ export NAME="custom" |
| 30 | +$ export CA_SUBJ="/OU=openshift/CN=admin-kubeconfig-signer-custom" |
| 31 | +
|
| 32 | +# set the CA validity to 10 years |
| 33 | +$ export VALIDITY=3650 |
| 34 | +
|
| 35 | +# generate the CA private key |
| 36 | +$ openssl genrsa -out ${NAME}-ca.key 4096 |
| 37 | +
|
| 38 | +# Create the CA certificate |
| 39 | +$ openssl req -x509 -new -nodes -key ${NAME}-ca.key -sha256 -days $VALIDITY -out ${NAME}-ca.crt -subj "${CA_SUBJ}" |
| 40 | +---- |
| 41 | ++ |
| 42 | +. Generate a new `system:admin` certificate. The client certificate must have the user into the x.509 subject CN field and the group into the O field. |
| 43 | ++ |
| 44 | +[source,terminal] |
| 45 | +---- |
| 46 | +$ export USER=system:admin |
| 47 | +$ export GROUP=system:masters |
| 48 | +$ export USER_SUBJ="/O=${GROUP}/CN=${USER}" |
| 49 | +
|
| 50 | +# create the user CSR |
| 51 | +$ openssl req -nodes -newkey rsa:2048 -keyout ${USER}.key -subj "${USER_SUBJ}" -out ${USER}.csr |
| 52 | +
|
| 53 | +# sign the user CSR and generate the certificate, the certificate must have the `clientAuth` extension |
| 54 | +$ openssl x509 -extfile <(printf "extendedKeyUsage = clientAuth") -req -in ${USER}.csr \ |
| 55 | + -CA ${NAME}-ca.crt -CAkey ${NAME}-ca.key -CAcreateserial -out |
| 56 | +${USER}.crt -days $VALIDITY -sha256 |
| 57 | +---- |
| 58 | ++ |
| 59 | +. Add the new certificate as an additional clientCA. |
| 60 | ++ |
| 61 | +[source,terminal] |
| 62 | +---- |
| 63 | +# create the client-ca ConfigMap" |
| 64 | +$ oc create configmap client-ca-custom -n openshift-config --from-file=ca-bundle.crt=${NAME}-ca.crt |
| 65 | +
|
| 66 | +# patch the APIServer |
| 67 | +$ oc patch apiserver cluster --type=merge -p '{"spec": {"clientCA": {"name": "client-ca-custom"}}}' |
| 68 | +---- |
| 69 | ++ |
| 70 | +. Import an additional CA certificate in a configmap of the openshift-config namespace. The CA file must be in PEM format. |
| 71 | ++ |
| 72 | +[source,terminal] |
| 73 | +---- |
| 74 | +$ oc create configmap admin-kubeconfig-client-ca -n openshift-config |
| 75 | +--from-file=ca-bundle.crt=new-ca.crt \ |
| 76 | + --dry-run -o yaml | oc replace -f - |
| 77 | +---- |
| 78 | + |
0 commit comments