Database connection encryption
General
This document provides the guidelines on database connection encryption for MySQL, PostgreSQL, MongoDB using SSL certificates. SSL certificates solve two problems: traffic encryption and verification of trust. What certificates to use: Connection encryption configuration requires an SSL key pair for the services (MySQL, Postgres, MongoDB). Authentication method: Classic login/password authentication through SSL connection.
Document terms
Predefined common variables:
- WorkFusion user. Default is
wfuser. - WorkFusion Home Directory. Default is
/opt/workfusion.
In the guide, we will use certificates located on DB server in the /nginx/ssl folder.
User values should be entered whenever you see the [ ] placeholder.
Application-level encryption of data in transit
PostgreSQL
PostgreSQL server configuration:
SSH to DB server and switch to
<WF_USER>, for example:sudo su - wfuserCopy certificates to PostgreSQL data directory and make sure the permissions for the files are set to 600.
cp /opt/workfusion/nginx/ssl/db.key /opt/workfusion/postgres/data/server.key cp /opt/workfusion/nginx/ssl/db.crt /opt/workfusion/postgres/data/server.crt cp /opt/workfusion/nginx/ssl/ca.crt /opt/workfusion/postgres/data/root.crt chmod 600 /opt/workfusion/postgres/data/server.key chmod 600 /opt/workfusion/postgres/data/server.crt chmod 600 /opt/workfusion/postgres/data/root.crtEnable SSL support in PostgreSQL config files.
- Find the string in
/opt/workfusion/postgres/data/postgresql.conf.
#ssl = offMake sure it's uncommented (Remove the
##sign at the beginning of the line), and change "off" to "on", as shown below:ssl = on- Find string in
/opt/workfusion/postgres/data/pg_hba.conf.
host all all 0.0.0.0/0 md5- Replace it with:
hostssl all all 0.0.0.0/0 md5- Find the string in
Restart PostgreSQL.
wfmanager restart postgresqlModify
mysql_serverforeign server settings (foreign data wrapper for mysql). Specify$workfusion_analytics_userusername and path to root certificate.psql -U analytics -d wf_datastore -c "alter server mysql_server OPTIONS (ssl_ca '/opt/workfusion/postgres/data/root.crt');"-U analytics: default$workfusion_analytics_userusernameTry to connect without SSL from APP Server.
- SSH to the APP server and switch to
<WF_USER>. - Execute the following:
psql "sslmode=disable host=[db_hostname]"As we disabled non-ssl connections, we should get following error:
psql: FATAL: no pg_hba.conf entry for host " dbhost_ip_adress ", user "wfuser", database "wfuser", SSL off
- SSH to the APP server and switch to
Try to connect with SSL from APP Server:
psql "sslmode=require host=[db_hostname] dbname=wf_datastore" -U [workfusion]where
[workfusion]isworkfusion_datastore_userof PostgreSQL DB.
It’s ok now. Serverside SSL configuration for postgresql is completed.
MySQL
MySQL server configuration is as follows:
SSH to DB server and switch to
<WF_USER>, e.g.sudo su - wfuserCopy certificates to the mysql directory.
cp -r /opt/workfusion/nginx/ssl /opt/workfusion/mysqlAdd the following strings in the mysql configuration
/opt/workfusion/mysql/usr/my.cnf.[mysqld] require_secure_transport=ON ssl-ca=/opt/workfusion/mysql/ssl/ca.crt ssl-cert=/opt/workfusion/mysql/ssl/db.crt ssl-key=/opt/workfusion/mysql/ssl/db.keyRestart MySQL.
wfmanager restart mysqlConnect to MySQL with SSL from APP Server.
- SSH to the APP server and switch to
<WF_USER>. - Execute the following:
mysql -h [db_hostname] -u [workfusion] -p --ssl MySQL [(none)]> status; SSL: Cipher in use is DHE-RSA-AES256-SHA
- SSH to the APP server and switch to
As we can see SSL for MySQL was successfully configured.
MongoDB
note
In versions 9.0.x-9.2.x, the rpa-manager and OCR applications are unable to establish connection with MONGODB via SSL.
caution
Do not perform section below until fixed rpa-manager and OCR applications are out.
Section below describes how to configure MongoDB server to use SSL.
SSH to DB server and switch to
<WF_USER>, e.g.sudo su - wfuserMongoDB uses only one file that holds certificate and serverkey.
cd /opt/workfusion/mongodb/etc cat /opt/workfusion/nginx/ssl/db.key /opt/workfusion/nginx/ssl/db.crt > /opt/workfusion/mongodb/etc/db.pemAdd following section to MongoDB configuration in the
/opt/workfusion/mongodb_db/etc/mongodb.conffile to enable SSL support.net: ssl: mode: requireSSL PEMKeyFile: /opt/workfusion/mongodb/etc/db.pemRestart MongoDB.
wfmanager restart mongodbCheck that SSL works:
- SSH to the APP server and switch to
<WF_USER>. - Execute the following:
mongo --ssl --sslAllowInvalidCertificates --host [db_hostname]:27016- SSH to the APP server and switch to
WorkFusion settings
The following steps should be performed on DB server.
Fill the next variables and execute in shell:
export DB_HOSTNAME=< YOUR_DB_SERVER_HOSTNAME_HERE> export MYSQL_PORT=<YOUR_MYSQL_PORT_HERE> export POSTGRESQL_PORT=<YOUR_POSTGRESQL_PORT_HERE>The next commands will create a file with SSL properties which will be uploaded to VAULT with
loader.sh.cd /opt/workfusion/wf-sec-storage/ cat << EOF > /opt/workfusion/wf-sec-storage/config-ssl.properties mturkds.database.url=jdbc:mysql://$DB_HOSTNAME:$MYSQL_PORT/wfdb?noAccessToProcedureBodies=true&useLegacyDatetimeCode=false&noAccessToProcedureBodies=true&serverTimezone=UTC&rewriteBatchedStatements=true&failOverReadOnly=false&verifyServerCertificate=false&useSSL=true wf.datastore.database.url=jdbc:postgresql://$DB_HOSTNAME:$POSTGRESQL_PORT/wf_datastore?targetServerType=master&sslmode=require&ssl=true&sslfactory=org.postgresql.ssl.NonValidatingFactory tableau.db.url=jdbc:postgresql://$DB_HOSTNAME:$POSTGRESQL_PORT/wfml_automation?targetServerType=master&sslmode=require&ssl=true&sslfactory=org.postgresql.ssl.NonValidatingFactory EOF ./loader.sh workfusion config-ssl.properties
The following steps should be performed on APP server.
Change the datasource URL in
/opt/workfusion/wfbi/conf/Catalina/localhost/service-wfbi.xml.url="jdbc:postgresql://db_hostname:postgresql_port/wfml_automation?targetServerType=master&useSSL=true&sslmode=require&ssl=true"Change the datasource URL in
/opt/workfusion/workspace_sandbox/conf/workspace-sandbox.properties.dataSource.url=jdbc:postgresql://hostname:port/virtualizer_sandbox?targetServerType=master&sslmode=require&ssl=trueChange the datasource URL in
/opt/workfusion/workspace_production/conf/workspace.properties.dataSource.url=jdbc:postgresql://hostname:port/virtualizer?targetServerType=master&&sslmode=require&ssl=trueChange the datasource URL in
/opt/workfusion/sqc/conf/Catalina/localhost/sqc-rest.xml.url="jdbc:mysql://db_hostname:mysql_port/sqc?useLegacyDatetimeCode=false&serverTimezone=UTC&rewriteBatchedStatements=true&autoReconnect=true&useSSL=true"Restart workfusion applications on APP server.
wfmanager restart all