Issue
I am having trouble connecting an external MongoDB with my self-hosted Appsmith instance. The database requires the tlsCAFile parameter in the connection URL, but the backend does not support it. I have tried importing my certificate to the keystore, but with no success. After several hours of debugging, I discovered that a node-js script runs on deploy and also uses APPSMITH_MONGODB_URI, so I need both the tlsCAFile parameter in APPSMITH_MONGODB_URI and also an imported cert.
Resolution
To connect your external MongoDB with a custom certificate, follow these steps:
- Copy the Custom Certificate:
- Place the custom certificate file in the
stacks
folder of your Appsmith instance. - Rename the certificate for easy access, if desired.
- Place the custom certificate file in the
- Modify the MongoDB URI:
- Open the
stacks/configuration/docker.env
file. - Update the
APPSMITH_MONGODB_URI
variable to include thetlsCAFile
parameter with the path to the custom certificate file. Ensure the entire URI is enclosed in double quotes.
Example: -
APPSMITH_MONGODB_URI="mongodb://<username>:<password>@<host>:<port>/<database>?tls=true&tlsCAFile=/path/to/custom/cert"
- Open the
-
Restart Appsmith: Execute the following command to restart your Appsmith instance:
docker-compose restart appsmith
-
Import Certificate into TrustStore (if needed): If the connection to MongoDB is still unsuccessful, import the custom certificate into the trustStore with this command:
docker-compose exec appsmith keytool -import -noprompt -trustcacerts -alias customProxy -file /appsmith-stacks/myRootCert.cer -keystore /usr/lib/jvm/java-1.11.0-openjdk-amd64/lib/security/cacerts -storepass changeit
- Restart Appsmith Again: Restart the Appsmith instance again with:
docker-compose restart appsmith
Check Deployment Scripts:
- If your Appsmith instance runs a
check_replica_set.js
script during deployment, ensure that theAPPSMITH_MONGODB_URI
variable in that script also includes thetlsCAFile
parameter. - Confirm the custom certificate is imported into the trustStore using the same command from step 4.
- By following these steps, you should be able to successfully connect your external MongoDB instance with a custom certificate to your self-hosted Appsmith.