==========================================
Enable and configure SSL post installation
==========================================

Enabling SSL
============

Because Package Security Manager does not require SSL certificates to operate, you'll need to perform some additional steps in order to enable SSL on an existing HTTP based instance. 

#. Open a terminal and connect to your instance of Package Security Manager.
#. Enter your installer directory (``ate-installer-*``). 

    .. note::
        
        This directory contains both the ``docker-compose.yml`` and ``.env`` files. 

#. Using your preferred file editor, open the ``docker-compose.yml`` file. 

    #. Find the ``services: nginx_proxy:`` section near the top of the file and add the following lines:

        .. code-block:: none

            secrets:
            - source: nginx_key
              target: /etc/nginx/certs/tls.key
            - source: nginx_cert
              target: /etc/nginx/certs/tls.crt

        .. dropdown:: For example

            .. code-block:: none

                services:
                ...
                    nginx_proxy:
                        secrets:
                        - source: nginx_key
                        target: /etc/nginx/certs/tls.key
                        - source: nginx_cert
                        target: /etc/nginx/certs/tls.crt
   
    #. Find the ``keycloak: environment:`` section further down in the file and add the following lines:
          
        .. code-block:: none

            - PROXY_ADDRESS_FORWARDING=true

#. Edit your ``.env`` file.

   #. Change ``DOMAIN`` to new FQDN, if applicable.
   #. Change ``NGINX_PROXY_PORT`` to ``443``.
   #. Change ``PROTOCOL`` to ``https``

.. _ssl:

Configuring SSL
===============

The following steps will allow you to configure the SSL:

#. Add or remove the following lines relating to the SSL in ``<BASE_DIR>/config/nginx/conf.d/repo.conf``:

    .. note:: 

        By default, the ``<BASE_DIR>`` is ``/opt/anaconda/repo``.

    .. code-block:: none
        
        listen              8080 ssl;
        listen              [::]:8080 ssl;

        ssl_certificate     /etc/nginx/certs/tls.crt;
        ssl_certificate_key /etc/nginx/certs/tls.key;
        ssl_protocols       TLSv1.2 TLSv1.3;
        ssl_ciphers         HIGH:!aNULL:!MD5;

    .. thumbnail:: ../img/repo_config_ssl_section.png
          :align: center

#. Add or remove certificates from the ``<BASE_DIR>/config/nginx/certs`` directory.

#. Run the following commands:

   .. code-block:: none

       docker compose stop nginx_proxy
       docker compose up --detach

Refer to nginx's documentation for the standard `SSL configuration <http://nginx.org/en/docs/http/configuring_https_servers.html>`_ procedure. 

Updating URL/URIs in Keycloak
=============================

Once your SSL cert and key are in place, you will need to update Keycloak to point to your new root URL and any valid URI redirects to your domain. 

#. Navigate to your Keycloak instance at ``<FQDN>/auth/admin`` and log in. 
#. Open the dropdown in the left-hand navigation and select the **Anaconda Login (dev)** realm.
#. Select **Clients** from the left-hand navigation.
#. Select **repo-service** from the list of available clients. 
#. On the **Settings** tab, update your root URL and any necessary valid redirect URI's.
#. Click **Save** at the bottom of the page. 
#. Select **Clients** from the left-hand navigation.
#. Select **repo-account-sync** from the list of available clients.
#. On the **Settings** tab, update your root URL. 
#. Click **Save** at the bottom of the page. 


Rebuilding your channel index
=============================

Migrating from ``HTTP`` to ``HTTPS`` or updating your ``FQDN`` will alter the file path to your channel's packages. You must :ref:`rebuild your channel index <rebuild-channel-index>` to correct the file path. If you do not, you will be unable to successfully download packages after migrating.
