DocumentDB Walkthrough

Use this page to learn how to run the FaceTec Server with DocumentDB.


Overview

There are three main steps to configuring and running the Server with DocumentDB.

  1. Create a Trust Store Script
  2. Update the FaceTec Server's Dockerfile
  3. Update MongoDatabase.java
Important Note: The above steps are specifically tailored for connecting the FaceTec Server to DocumentDB. For an in-depth overview of how to connect Services and Programs to Document DB, please see Amazon's Official Documentation for Connecting programmatically to Amazon DocumentDB.

Step 1: Create a Trust Store Script

A Trust Store needs to be created in order for Transport Layer Security (TLS) to be configured for Your DocumentDB Database. Your Team can create a Trust Store by adding the below script (make-truststore.sh) to the root of Your Server Directory and running it in Your FaceTec Server's Dockerfile.

mydir=. # rds-truststore.jks will be installed in the same directory as config.yaml.
truststore=${mydir}/rds-truststore.jks
storepassword="testpassword" # Change to Your Own Password.

curl -sS "https://truststore.pki.rds.amazonaws.com/global/global-bundle.pem" > ${mydir}/global-bundle.pem
awk 'split_after == 1 {n++;split_after=0} /-----END CERTIFICATE-----/ {split_after=1}{print > "rds-ca-" n ".pem"}' < ${mydir}/global-bundle.pem

for CERT in rds-ca-*; do
    alias=$(openssl x509 -noout -text -in $CERT | perl -ne 'next unless /Subject:/; s/.*(CN=|CN = )//; print')
    echo "Importing $alias"
    keytool -import -file ${CERT} -alias "${alias}" -storepass ${storepassword} -keystore ${truststore} -noprompt
    rm $CERT
done

rm ${mydir}/global-bundle.pem

echo "Trust store content is: "

keytool -list -v -keystore "$truststore" -storepass ${storepassword} | grep Alias | cut -d " " -f3- | while read alias
do
    expiry=`keytool -list -v -keystore "$truststore" -storepass ${storepassword} -alias "${alias}" | grep Valid | perl -ne 'if(/until: (.*?)\n/) { print "$1\n"; }'`
    echo " Certificate ${alias} expires in '$expiry'"
done

Step 2: Update the FaceTec Server's Dockerfile

The Dockerfile needs to be updated so Your Server can install the necessary certificates and create a Trust Store with the script from Step 1.

Important Note: The specific segment of code that will need to be added to the Dockerfile starts with the tag "### Beginning of DocumentDB TLS Code ###" and ends with the tag "### End of DocumentDB TLS Code ###".
# Gets argument variables from docker-compose.yml

# Latest stable Debian 11 release with Node.
FROM node:18.17.1-bullseye-slim

# FaceTec Directories
ARG FACETEC_CUSTOM_SERVER_DIRECTORY=./FaceTecSDK-custom-server-<VERSION_NUMBER>
ARG FACETEC_SERVER_CORE_DIRECTORY=./FaceTecSDK-server-core-java-<VERSION_NUMBER>

RUN apt-get update && apt-get upgrade -y
RUN apt-get install -y default-jdk
RUN apt-get install -y maven
RUN apt-get install -y libgomp1

COPY $FACETEC_CUSTOM_SERVER_DIRECTORY /home/FaceTec_Custom_Server
COPY $FACETEC_SERVER_CORE_DIRECTORY /home/FaceTec_Server_Core
COPY ./facetec_usage_logs_server /home/FaceTec_Custom_Server/deploy/facetec_usage_logs_server
COPY ./OCRTemplates /home/OCRTemplates

### Beginning of DocumentDB TLS Code ###

# DocumentDB TLS SETUP - STEP 1: Install cURL, which is required for downloading the Certificates from AWS.
RUN apt-get install -y curl

# DocumentDB TLS SETUP - STEP 2: Copy the Trust Store Script into the container.
COPY ./make-truststore.sh /home/

# DocumentDB TLS SETUP - STEP 3: Run the make-truststore.sh script.
RUN bash /home/make-truststore.sh

# DocumentDB TLS SETUP - STEP 4: Copy the resulting truststore to the deploy folder.
RUN cp ./rds-truststore.jks /home/FaceTec_Custom_Server/deploy

### End of DocumentDB TLS Code ###

RUN cp /home/FaceTec_Custom_Server/config.yaml /home/FaceTec_Custom_Server/deploy

# Install FaceTec ServerCore into Maven
RUN mvn install:install-file -Dfile=/home/FaceTec_Server_Core/libs/FaceTecSDK-<VERSION_NUMBER>.jar -DgroupId=com.facetec.servercore -DartifactId=server -Dversion=<VERSION_NUMBER> -Dpackaging=jar

# Build REST SDK
RUN mvn -f /home/FaceTec_Custom_Server/pom.xml clean package -Plinux

WORKDIR /home/FaceTec_Custom_Server/deploy
RUN cd ./facetec_usage_logs_server && npm install

# Creates run.sh to launch app
RUN printf "#!/bin/bash\ncd facetec_usage_logs_server && npm start && cd .. && java -jar FaceTec-Custom-Server.jar" > run.sh

EXPOSE 8080

CMD ["bash", "run.sh"]

Step 3: Update MongoDatabase.java

Before they can be used, the Trust Store and the Trust Store Password need to be specified as properties in Your Document DB. Your Team can set these properties by adding the following code to the top of the initializeDatabaseConnection Method in Your FaceTec Server's MongoDatabase.java file:

String truststore = "rds-truststore.jks";
String truststorePassword = "testpassword";
System.setProperty("javax.net.ssl.trustStore", truststore);
System.setProperty("javax.net.ssl.trustStorePassword", truststorePassword);