=============================
Updating TLS/SSL certificates
=============================

You can replace the self-signed certificates Data Science & AI Workbench generates during installation at any time. 

.. _ssl-preparing:

Preparing for the update
========================

Anaconda recommends that you gather the following information and files before you proceed. If you are using the admin console, place your files in a location where you can view them to copy their contents into the applicable fields within the UI. If you are updating your certificates using the command line, you'll need to copy your files to the server.

Most installations will need the following items:
    * The fully qualified domain name (FQDN) of the server
    * The public SSL certificate for the domain: ``tls.crt``
    * The private SSL key for the domain: ``tls.key``
    * If applicable, the intermediate certificate bundle: ``intermediate.pem`` 
    * If your certificate was issued by a private root CA, the public certificate for that CA: ``rootca.crt``

If you are using LetsEncrypt, your filenames will be different:
    * The public SSL certificate for the domain: ``cert.pem``
    * The private SSL key for the domain: ``privkey.pem``
    * The intermediate certificate bundle: ``chain.pem``
    * No root CA file is needed in this case.

If you are using a different domain and/or SSL certificate for the session/deployment subdomains, you also need:
    * The wildcard subdomain FQDN
    * The public SSL certificate for the wildcard subdomain: ``wildcard.crt``
    * The private SSL key for the wildcard subdomain: ``wildcard.key``

.. note::
  
    * Workbench assumes that the intermediate certificate and root CA (if applicable) are identical for both certificates.
    * Workbench version 5.6+ automatically applies the updated SSL certificates to all running sessions and deployments.

Updating SSL certificates
=========================

You can update your TLS/SSL certificates using the Workbench administrator console. 

#. Log in to Workbench as an administrator. 
#. Open the |circle-user| **My Account** dropdown menu and select *Admin Console*. 
#. Select |file-certificate| **Web Certificates** from the left-hand menu.
#. Enter your certificate and key information from the files you gathered during preparation into the appropriate fields. Make sure to paste the *content* of each file into the appropriate box, not the *filenames*.

    * Domain name: The server FQDN
    * SSL Certificate: ``tls.crt`` / ``cert.pem``
    * SSL Private Key: ``tls.key`` / ``privkey.pem``
    * Root Certificate: ``rootca.crt`` if applicable
    * Intermediate Certificate: ``intermediate.pem`` / ``chain.pem`` if applicable
    * Wildcard Domain: The subdomain FQDN if applicable; the server FQDN again if not. *Do not include an asterisk*.
    * Wildcard Certificate: ``wildcard.crt`` if applicable; ``tls.crt`` / ``cert.pem`` if not.
    * Wildcard Private Key: ``wildcard.key`` if applicable; ``tls.key`` / ``privkey.pem`` if not.

#. Click **Save** to update the platform with your changes.
#. If your root CA has changed, restart the Workbench system pods to ensure the pods that use this certificate pick up the new copy by running the following command:

    .. code-block:: none
      
        # Replace <NAMESPACE> with your Workbench cluster namespace
        kubectl delete -n <NAMESPACE> --wait=false $(kubectl get pods -o name|grep ap-)

.. note:: 

    If you use the Workbench CLI, you must :ref:`configure the certificates there as well <cli-cert-config>`.

.. |circle-user| raw:: html
   
   <svg class="inline" height="1em" width="1em" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 512 512"><path d="M256 496c-54 0-103.9-17.9-144-48v0c0-61.9 50.1-112 112-112h64c61.9 0 112 50.1 112 112v0c5.3-4 10.4-8.2 15.4-12.6C409.1 370.6 354.5 320 288 320H224c-66.5 0-121.1 50.6-127.4 115.4C47.2 391.5 16 327.4 16 256C16 123.5 123.5 16 256 16s240 107.5 240 240s-107.5 240-240 240zm0 16A256 256 0 1 0 256 0a256 256 0 1 0 0 512zm80-304a80 80 0 1 0 -160 0 80 80 0 1 0 160 0zm-80-64a64 64 0 1 1 0 128 64 64 0 1 1 0-128z"/></svg>

.. |file-certificate| raw:: html

  <svg class="inline" height="1em" width="1em" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 512 512"><path d="M480 448c0 17.7-14.3 32-32 32H224v16c0 5.5-1 10.9-2.7 16H448c35.3 0 64-28.7 64-64V163.9c0-12.7-5.1-24.9-14.1-33.9L382.1 14.1c-9-9-21.2-14.1-33.9-14.1H192c-35.3 0-64 28.7-64 64v71.1l.1-.1c1.5-.7 4-2 6.6-3c8.2-3.4 16.9-4.6 25.3-4V64c0-17.7 14.3-32 32-32H320V144c0 26.5 21.5 48 48 48H480V448zm-.5-288H368c-8.8 0-16-7.2-16-16V32.5c2.8 .7 5.4 2.1 7.4 4.2L475.3 152.6c2.1 2.1 3.5 4.6 4.2 7.4zM69.8 358.5l-2.1 15.2 2.1-15.2L59 357l-1.5-10.8c-1.4-10.4-6.9-19.8-15.1-26.2L22.8 345.2 42.4 320l-8.6-6.7 4.1-10.1c4-9.7 4-20.6 0-30.3l-4.1-10.1 8.6-6.7L22.8 230.7 9.3 241.2c-8.5 6.6-11.6 18.1-7.5 28L8.2 285c.8 1.9 .8 4.1 0 6L1.8 306.8c-4.1 10-1 21.4 7.5 28l13.5 10.4c1.7 1.3 2.7 3.2 3 5.2l2.3 16.9c1.5 10.7 9.8 19.1 20.5 20.5L64 390V496c0 5.9 3.2 11.3 8.5 14.1s11.5 2.5 16.4-.8L128 483.2l39.1 26.1c4.9 3.3 11.2 3.6 16.4 .8s8.5-8.2 8.5-14.1V390l15.4-2.1c10.7-1.5 19.1-9.8 20.5-20.5l2.3-16.9-31.7-4.3L197 357l-10.8 1.5c-10.4 1.4-19.8 6.9-26.2 15.1l-6.7 8.6-10.1-4.1c-9.7-4-20.6-4-30.3 0l-10.1 4.1L96 373.6c-6.4-8.3-15.8-13.7-26.2-15.1zm-47-127.7L42.4 256c8.3-6.4 13.7-15.8 15.1-26.2L29.3 226l28.2 3.8L59 219l10.8-1.5c10.4-1.4 19.8-6.9 26.2-15.1l6.7-8.6 10.1 4.1c9.7 4 20.6 4 30.3 0l-11.3-27.6 11.3 27.6 10.1-4.1 6.7 8.6c6.4 8.3 15.8 13.7 26.2 15.1L197 219l1.5 10.8c1.4 10.4 6.9 19.8 15.1 26.2l8.6 6.7-4.1 10.1c-4 9.7-4 20.6 0 30.3l4.1 10.1-8.6 6.7c-8.3 6.4-13.7 15.8-15.1 26.2l31.7 4.3c.3-2.1 1.4-4 3-5.2l13.5-10.4c8.5-6.6 11.6-18.1 7.5-28L247.8 291c-.8-1.9-.8-4.1 0-6l6.5-15.8c4.1-10 1-21.4-7.5-28l-13.5-10.4c-1.7-1.3-2.7-3.2-3-5.2l-2.3-16.9c-1.5-10.7-9.8-19.1-20.5-20.5l-16.9-2.3c-2.1-.3-4-1.4-5.2-3l-10.4-13.5c-6.6-8.5-18.1-11.6-28-7.5L131 168.2c-1.9 .8-4.1 .8-6 0l-15.8-6.5c-10-4.1-21.4-1-28 7.5L70.7 182.8c-1.3 1.7-3.2 2.7-5.2 3l-16.9 2.3c-10.7 1.5-19.1 9.8-20.5 20.5l-2.3 16.9c-.3 2.1-1.4 4-3 5.2zM160 466.1l-23.1-15.4c-5.4-3.6-12.4-3.6-17.8 0L96 466.1V415.6c4.3 .8 8.9 .3 13.2-1.4l15.8-6.5c1.9-.8 4.1-.8 6 0l15.8 6.5c4.3 1.8 8.9 2.2 13.2 1.4v50.5z"/></svg>