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 Replace the Deployment Certificate Authority. For an unfinished operation, use Recover an Interrupted Certificate Operation.

Prerequisites#

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.

Option A: Replace Certificates Generated by Dioptra#

Dioptra generates the new certificates for you using the same CA.

Step A1: Replace the Certificate#

To replace nginx’s certificate, run:

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 Recover an Interrupted Certificate Operation using the reported operation ID.

Step A2: Check the Installed Certificates#

Check the installed certificates:

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.

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 client connection and login checks.

Update your protected backup after successful replacement. See Certificate Backups for the files to retain.

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 Certificate Policy Reference for certificate requirements.

Step B1: Combine Separate Certificate Files (Optional)#

If you already have a full-chain PEM file, continue to Step B2.

If your provider supplies the server certificate and intermediate certificates separately, combine them into one PEM file with the server certificate first:

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 Step B2.

Step B2: Copy the Certificate Files#

Copy the files into the deployment directory. For nginx, run:

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/.

Step B3: Update the Certificate Configuration#

Open config/ssl.toml and update the service’s source and trust_files fields. For nginx:

[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 Step B2, relative to the deployment directory. Keep the other fields and their values unchanged.

Step B4: Replace the Certificate#

To install nginx’s replacement certificate, run:

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 Recover an Interrupted Certificate Operation using the reported operation ID.

Step B5: Check the Installed Certificates#

Check the installed certificates:

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.

Step B6: Update Certificate Trust (Optional)#

If the replacement certificate uses a different CA, follow the workstation or Python client instructions to verify its fingerprint and update trust.

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 client connection and login checks.

Update your protected backup after successful replacement. See Certificate Backups for the files to retain.

See Also#