Using your own SSL Certificate

Modified on: Wed, 11 Nov, 2020 at 12:31 PM

Many customers would like to replace our server certificates with their own certificates issued with the correct common name and using their company or commercial Certificate Authority (CA).


There are two methods of achieving this which are both explained below.


Method 1: Permanent Solution (Recommended)

The paths for the files that you need to overwrite are as defined in /etc/nginx/conf.d/dispatcher.conf  within the ctasdispatcher docker container:

  1. /etc/nginx/server.crt
  2. /etc/nginx/server.key


You should be able to overwrite the above files in the Docker containers in order to change the certificate that is being used, however, by changing the files inside the Docker container, you will need to repeat this action every time the Docker images change when an update is released because the changes will be lost every time a new container is created.


There is a long-term solution though; ideally we would like to make use of the Docker workflow to change the certificates but also achieve additional objectives:

  1. Document what changes we are making to the Docker containers
  2. Have the changes persist between updates


Building a custom Docker image that is based on our original image will allow us to achieve this. The following example will demonstrate the changes required for the CTAS server. The example will assume that you are in a directory containing the following files:

  1. Dockerfile: new Dockerfile created
  2. ctas-custom.yml: additional docker-compose file to customize docker setup
  3. internal_cert.crt: crt file for the new certificate
  4. internal_cert.key: key file for the new certificate


Prepare new certificate

Prepare a new certificate as per the requirements of your organization.


Note: NGINX recommends that the full certificate chain is in the certificate file. Be sure to create a combined certificate with any intermediate certificates, e.g.: cat main.crt intermediate.crt > combined.crt


First we need to build a new Docker image that is based off of our image and contains the custom certificate and its key.

We can do this by creating the following Dockerfile:


FROM registry.paterva.com/ctasdispatcher:latest
COPY ./internal_cert.crt /etc/nginx/server.crt
COPY ./internal_cert.key /etc/nginx/server.key


This will create a new Docker image that is based off our server image, but has new certificate and its key copied from a local directory into the container.


Next we need to change our Docker-compose file to reference the local Dockerfile, rather than using our images directly. We will make changes to our compose file, whilst following the guidelines outlined here.


We can create a new Docker-compose file with the filename “ctas-custom.yml”. The file should have the following contents:


version: '3'
services:
  ctasdispatcher:
    build: .


The above contents tells Docker to build an image using the Dockerfile from the local directory, rather than running our image directly.


We can then run the server using our new certificate with the command:


docker-compose -f ctas.yml -f ctas-custom.yml up -d --build


This will build and start a new server using the your certificate and its key for HTTPS connections.


Method 2: Temporary Solution

If rebuilding containers won’t be an option for you, you can replace the SSL certificates inside the container.


Warning: This is a temporary solution that won’t survive an update. You need to repeat these instructions in the future.


Log into the Server or VM that hosts the CTAS Docker Containers.


Log into the CTAS container terminal

Start by obtaining the Container ID or Container Name.


docker ps


Sample output:


CONTAINER ID IMAGE ... NAMES
0afddd35cdf3 registry.paterva.com/ctastransforms:latest ... maltego_ctastransforms_1
8cb065694455 registry.paterva.com/ctasdispatcher:latest ... maltego_ctasdispatcher_1
c5a7dd3d6b85 postgres:10


Gen

Identify the ‘CONTAINER ID’ for the ‘ctasdispatcher’ instance, and use the ‘exec’ argument with ‘docker’ to log into the system (replace ID with the one from your instance):


sudo docker exec -it 8cb065694455 bash


Sample output:


root@8cb065694455:/#


Find the pre-installed SSL certificates:


cd /etc/nginx/
ll


Sample output:


...
-rw-r--r-- 1 root root 1724 Oct 19 2018 CA.crt
-rw-r--r-- 1 root root 1196 Oct 19 2018 server.crt
-rw-r--r-- 1 root root 1704 Oct 19 2018 server.key


Rename the “server.crt” and “server.key” files to backups.


mv server.crt server.crt.bck
mv server.key server.key.bck
ll


Sample output:


...
-rw-r--r-- 1 root root 1724 Oct 19 2018 CA.crt
-rw-r--r-- 1 root root 1196 Oct 19 2018 server.crt.bck
-rw-r--r-- 1 root root 1704 Oct 19 2018 server.key.bck


Exit the CTAS container terminal:


exit


Copy the new SSL certificates to the CTAS container

Use the same Docker Container ID or Container Name used previously to log into the CTAS container to copy the new certificates into the container.


sudo docker cp internal_cert.crt 8cb065694455:/etc/nginx/server.crt
sudo docker cp internal_cert.key 8cb065694455:/etc/nginx/server.key


Restart the CTAS Container.

Use the same Docker Container ID or Container Name used previously to log into the CTAS  container.


sudo docker restart 8cb065694455


Did you find it helpful? Yes No

Send feedback
Sorry we couldn't be helpful. Help us improve this article with your feedback.