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 ctasnginx docker container:
- /etc/nginx/server.crt
- /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:
- Document what changes we are making to the Docker containers
- 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:
- Dockerfile: new Dockerfile created
- ctas-custom.yml: additional docker-compose file to customize docker setup
- server_cert.crt: crt file for the new certificate
- server_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/ctasnginx:latest USER root COPY server_cert.crt /etc/nginx/server.crt COPY server_cert.key /etc/nginx/server.key RUN chown -R webserver:webserver /etc/nginx/server.* USER webserver
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: nginx: image: registry.paterva.com/ctasnginx:latest 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 mst_onprem.yml -f ctas-custom.yml up -d --build
This will build and start a new server using 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/ctasnginx:latest ... maltego_ctasnginx_1 c5a7dd3d6b85 postgres:10
Identify the ‘CONTAINER ID’ for the ‘ctasnginx’ 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