.. This Software (Dioptra) is being made available as a public service by the .. National Institute of Standards and Technology (NIST), an Agency of the United .. States Department of Commerce. This software was developed in part by employees of .. NIST and in part by NIST contractors. Copyright in portions of this software that .. were developed by NIST contractors has been licensed or assigned to NIST. Pursuant .. to Title 17 United States Code Section 105, works of NIST employees are not .. subject to copyright protection in the United States. However, NIST may hold .. international copyright in software created by its employees and domestic .. copyright (or licensing rights) in portions of software that were assigned or .. licensed to NIST. To the extent that NIST holds copyright in this software, it is .. being made available under the Creative Commons Attribution 4.0 International .. license (CC BY 4.0). The disclaimers of the CC BY 4.0 license apply to all parts .. of the software developed or licensed by NIST. .. .. ACCESS THE FULL CC BY 4.0 LICENSE HERE: .. https://creativecommons.org/licenses/by/4.0/legalcode .. _how-to-replace-deployment-certificates: Replace Deployment Certificates ================================== Use this guide to replace the certificates used by the Dioptra API or nginx. Replacement briefly stops affected services. To replace the certificate authority (CA) created by Dioptra, see :ref:`how-to-replace-deployment-ca`. For an unfinished operation, use :ref:`how-to-recover-certificate-operation`. Prerequisites ---------------- * An :ref:`initialized Dioptra deployment `. * Python 3.11 or newer. * Docker with Docker Compose. * Terminal access to the deployment directory as the user who owns its files. * A protected backup of the :ref:`certificate and recovery files `. Overview ----------- Choose the option for the certificate you want to replace: * **Option A: Replace Certificates Generated by Dioptra.** Use this when Dioptra generates the certificate for you. * **Option B: Replace Certificates You Provide.** Use this when you obtain the replacement certificate from your organization or another certificate provider. The API and nginx can use different certificate sources. Check ``source`` in the service's ``[restapi]`` or ``[nginx]`` section of ``config/ssl.toml``. The value ``generated`` corresponds to Option A and ``supplied`` to Option B. To switch from a generated certificate to one you provide, follow Option B. Run commands from the deployment directory. .. _how-to-replace-generated-certificates: Option A: Replace Certificates Generated by Dioptra ------------------------------------------------------ Dioptra generates the new certificates for you using the same CA. .. rst-class:: header-on-a-card header-steps Step A1: Replace the Certificate ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ To replace nginx's certificate, run: .. code:: sh python3 scripts/manage_ssl.py replace --target nginx Use ``--target restapi`` for the API. To replace both certificates when both are generated by Dioptra, use ``--target all``. Wait for the command to report successful replacement and HTTPS checks. If it reports an interrupted operation, follow :ref:`how-to-recover-certificate-operation` using the reported operation ID. .. rst-class:: header-on-a-card header-steps Step A2: Check the Installed Certificates ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Check the installed certificates: .. code:: sh python3 scripts/manage_ssl.py validate Confirm that validation succeeds with no unavailable checks. Note the reported expiration dates so you can replace the certificates before they expire. .. rst-class:: header-on-a-card header-steps Step A3: Verify Access ~~~~~~~~~~~~~~~~~~~~~~ Open the deployment's HTTPS address in your browser and confirm that the frontend loads without certificate warnings. If you have an account, log in to check authenticated access. For external Python clients, repeat the :ref:`client connection and login checks `. Update your protected backup after successful replacement. See :ref:`reference-deployment-certificate-backups` for the files to retain. .. _how-to-replace-supplied-certificates: Option B: Replace Certificates You Provide --------------------------------------------- Have these files ready for each certificate you want to replace: * A PEM file containing your server certificate and any required intermediate certificates. Look for a download described as a **full certificate chain**, such as ``fullchain.pem``. * The private key associated with that server certificate. * The root certificate from your certificate authority (CA), which Dioptra uses to verify the server certificate. See :ref:`reference-certificate-policy` for certificate requirements. .. rst-class:: header-on-a-card header-steps Step B1: Combine Separate Certificate Files (Optional) ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ If you already have a full-chain PEM file, continue to :ref:`Step B2 `. If your provider supplies the server certificate and intermediate certificates separately, combine them into one PEM file with the server certificate first: .. code:: sh cat "SERVER_CERT_PATH" "INTERMEDIATE_CERTS_PATH" > server-chain.pem Replace ``SERVER_CERT_PATH`` with the server certificate file and ``INTERMEDIATE_CERTS_PATH`` with the intermediate certificate file supplied by your provider. Use the resulting ``server-chain.pem`` as ``CHAIN_PATH`` in :ref:`Step B2 `. .. _how-to-copy-replacement-certificate-files: .. rst-class:: header-on-a-card header-steps Step B2: Copy the Certificate Files ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Copy the files into the deployment directory. For nginx, run: .. code:: sh install -m 0644 "CHAIN_PATH" ssl/nginx/server.crt install -m 0600 "KEY_PATH" ssl/nginx/server.key install -m 0644 "ROOT_CA_PATH" ssl/ca-certificates/root-ca.crt Replace ``CHAIN_PATH``, ``KEY_PATH`` and ``ROOT_CA_PATH`` with the paths to your full certificate chain, private key and root CA certificate. The ``install`` command copies each file with the specified permissions, including owner-only access for the private key. For the API, use ``ssl/restapi/server.crt`` and ``ssl/restapi/server.key`` as the first two destinations. If the API and nginx use different root certificates, give each root certificate a separate filename in ``ssl/ca-certificates/``. .. rst-class:: header-on-a-card header-steps Step B3: Update the Certificate Configuration ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Open ``config/ssl.toml`` and update the service's ``source`` and ``trust_files`` fields. For nginx: .. code:: toml [nginx] source = "supplied" trust_files = ["ssl/ca-certificates/root-ca.crt"] For the API, update the ``[restapi]`` section instead. Set ``trust_files`` to the root certificate path used in :ref:`Step B2 `, relative to the deployment directory. Keep the other fields and their values unchanged. .. rst-class:: header-on-a-card header-steps Step B4: Replace the Certificate ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ To install nginx's replacement certificate, run: .. code:: sh python3 scripts/manage_ssl.py replace --target nginx Use ``--target restapi`` for the API. If you prepared replacement files for both services, use ``--target all``. Wait for the command to report successful replacement and HTTPS checks. If it reports an interrupted operation, follow :ref:`how-to-recover-certificate-operation` using the reported operation ID. .. rst-class:: header-on-a-card header-steps Step B5: Check the Installed Certificates ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Check the installed certificates: .. code:: sh python3 scripts/manage_ssl.py validate Confirm that validation succeeds with no unavailable checks. Note the reported expiration dates so you can replace the certificates before they expire. .. rst-class:: header-on-a-card header-steps Step B6: Update Certificate Trust (Optional) ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ If the replacement certificate uses a different CA, follow the :ref:`workstation ` or :ref:`Python client ` instructions to verify its fingerprint and update trust. .. rst-class:: header-on-a-card header-steps Step B7: Verify Access ~~~~~~~~~~~~~~~~~~~~~~ Open the deployment's HTTPS address in your browser and confirm that the frontend loads without certificate warnings. If you have an account, log in to check authenticated access. For external Python clients, repeat the :ref:`client connection and login checks `. Update your protected backup after successful replacement. See :ref:`reference-deployment-certificate-backups` for the files to retain. .. rst-class:: header-on-a-card header-seealso See Also ----------- * :ref:`how-to-replace-deployment-ca` covers replacing Dioptra's CA and its generated certificates. * :ref:`reference-manage-ssl-replace` describes replacement options and behavior. * :ref:`how-to-enabling-ssl-tls` covers certificate configuration for a fresh deployment. * :ref:`how-to-recover-certificate-operation` covers resume and rollback.