How to Use a Remote Database Server with the Harmony Access Point v2.x?
These instructions apply to Harmony Access Point version 2.0 only. Instructions for Harmony Access Point versions older than 2.0.0 are available here.
By default, the Harmony Access Point application and the MySQL database server are installed on the same host. However, it’s possible to install the application and the database server on separate hosts too. The steps that are required to complete the setup are explained in this article.
In order to complete the setup, two separate hosts are required: host 1 and host 2. The Harmony Access Point application is installed on the host 1 and the MySQL database server on the host 2.
The MySQL database server major version must be 8.
Instructions
Please follow the steps below to complete the setup.
Host 2 (Database Host)
Create a file
install_db.shwith the following content. The script installs MySQL database server and creates the Harmony Access Point database.By default, the script grants
harmony_apDB user access from all remote hosts. If you want to allow access from host 1 only, update lines 18-20 ('$DBUSER'@'%'=>'$DBUSER'@'x.x.x.x') replacing%with the host 1 IP address.#!/bin/bash set -e sudo apt update sudo apt install mysql-server --yes echo "MySQL Server installed" >&2 DBUSER=harmony_ap DBSCHEMA=$DBUSER SCHEMA_EXISTS=$(mysql -s -N -e "SELECT SCHEMA_NAME FROM INFORMATION_SCHEMA.SCHEMATA WHERE SCHEMA_NAME='$DBSCHEMA'"); if [ -z "$SCHEMA_EXISTS" ]; then echo "Creating database harmony_ap" >&2 DBPASSWORD=$(openssl rand -base64 12) mysql -e \ "create schema $DBSCHEMA; \ alter database $DBSCHEMA charset=utf8mb4 collate=utf8mb4_bin; \ create user '$DBUSER'@'%' identified by '$DBPASSWORD'; \ grant all on $DBSCHEMA.* to '$DBUSER'@'%'; " echo "Database schema is: $DBSCHEMA" >&2 echo "Database user is: $DBUSER" >&2 echo "Database password is: $DBPASSWORD" >&2 else echo "Database $DBSCHEMA already exists. Skipping database creation" >&2 fi
Run the script with
sudo.sudo ./install_db.shWhen the script has executed successfully, it prints the database schema, username and password (
DATABASE_PASSWORD) to the console. Copy them to a separate file.... Database schema is: harmony_ap Database user is: harmony_ap Database password is: oz0/cZZ77l4e7W2jEnable the
mysqlservice so that it’s automatically started after the host is rebooted.sudo systemctl enable mysqlBy default, the MySQL server accepts connections from
localhostonly. Update thebind-addressparameter in the/etc/mysql/mysql.conf.d/mysqld.cnfconfiguration to listen on another network interface (or use0.0.0.0to listen on all network interfaces).It is also necessary to populate MySQL time zone information tables (see https://dev.mysql.com/doc/refman/8.0/en/time-zone-support.html#time-zone-installation), e.g. using the following command as root on the external database host (here assuming a Debian-based distribution like Ubuntu, the location of the time zone data can differ):
mysql_tzinfo_to_sql /usr/share/zoneinfo/posix | mysql -u root mysqlRestart the MySQL server to apply the changes.
sudo systemctl restart mysql
Host 1
Try to establish a connection to the remote database.
mysql -u harmony_ap -p'<DATABASE_PASSWORD>' -h <DATABASE_HOST> -P 3306 -D <DB_SCHEMA>If the connection fails, please check your firewall configuration. Host 1 must be able to connect to port
3306of host 2.
Install the Harmony Access Point application by following the installation guide. When prompted for database connection information, use the database host name (or IP) and schema and credentials from the above database setup step 3.
Enable Secure Database Connection
By default, the connection between the Harmony Access Point application and the MySQL server is unencrypted. With a couple of additional steps, encryption can be enabled.
Host 2
Open the
/etc/mysql/mysql.conf.d/mysqld.cnfconfiguration file for editing and add the following configuration at the end of the file:ssl-cert=server-cert.pem ssl-key=server-key.pem ssl-ca=ca.pem require_secure_transport=ONThe keys defined in the configuration are located in the
/var/lib/mysql/directory.server-cert.pem- identifies the server public key certificate.server-key.pem- identifies the server private key.ca.pem- identifies the Certificate Authority (CA) certificate.
Restart the MySQL server to apply the changes.
sudo systemctl restart mysqlCopy the
/var/lib/mysql/ca.pemfile to host 1.
Host 1
Store the
ca.pemfile copied from host 2 in a file.Import the
ca.pemfile in the/etc/harmony-ap/tls-truststore.jksfile.sudo keytool -importcert -alias mysql_root -file ca.pem -keystore /etc/harmony-ap/tls-truststore.jks -storepass <tls_truststore_password>The truststore password can be found from the
/etc/harmony-ap/tomcat-conf/server.xmlfile in thetruststorePassproperty.Note: If the CA certificate is a certificate chain that consists of multiple certificates (e.g., root certificate + intermediate certificate), all the certificates in the chain must be added to the
/etc/harmony-ap/tls-truststore.jksfile separately. In other words, store the certificates in separate files and run the import command for each file.
Create a new key and certificate for the MySQL client or alternatively, use the
client-key.pemandclient-cert.pemfiles located in the/var/lib/mysql/directory on host 2.Create a new
pkcs12container for the client key and certificate.openssl pkcs12 -export -in client-cert.pem -inkey client-key.pem -out keystore.p12 -name "mysql_client" -passout pass:<pkcs12_password>Create a new
JKSkeystore using thepkcs12container.Note: The keystore and the private key must have the same password. Using different passwords is not supported.
sudo keytool -J-Dkeystore.pkcs12.legacy -importkeystore -alias mysql_client -srckeystore keystore.p12 -srcstoretype pkcs12 -destkeystore /etc/harmony-ap/mysql-keystore.jks -srcstorepass <pkcs12_password> -deststoretype JKS -deststorepass <mysql_keystore_password> sudo chown harmony-ap:harmony-ap /etc/harmony-ap/mysql-keystore.jks sudo chmod 751 /etc/harmony-ap/mysql-keystore.jks
Open the Harmony Access Point configuration file
/etc/harmony-ap/domibus.propertiesfor editing and update thedomibus.datasource.urlproperty values. After the update, they should look like this:domibus.datasource.url=jdbc:mysql://${domibus.database.serverName}:${domibus.database.port}/${domibus.database.schema}?sslMode=VERIFY_CA&clientCertificateKeyStoreUrl=file:///etc/harmony-ap/mysql-keystore.jks&clientCertificateKeyStoreType=jks&clientCertificateKeyStorePassword=<mysql_keystore_password>If the password contains special characters, they must be URL encoded.
Restart the Harmony Access Point application:
sudo systemctl restart harmony-ap.
Host 2 (optional)
The previous configuration steps enabled TLS connection between the MySQL server and MySQL clients. However, if mutual TLS authentication (mTLS) is required, one additional step is needed on host 2.
The MySQL server must be configured to verify the issuer (ISSUER) or the subject (SUBJECT) of client certificates. The allowed value for the harmony_ap user must be updated to the mysql database:
mysql -e "use mysql; ALTER USER 'harmony_ap'@'%' REQUIRE ISSUER '<ISSUER_DISTINGUISHED_NAME>';"For example, if the client-key.pem and client-cert.pem files located in the /var/lib/mysql/ directory on host 2 are used, the allowed ISSUER value is /CN=MySQL_Server_8.0.30_Auto_Generated_CA_Certificate.
mysql -e "use mysql; ALTER USER 'harmony_ap'@'%' REQUIRE ISSUER '/CN=MySQL_Server_8.0.30_Auto_Generated_CA_Certificate';"The connection can be manually tested on host 1:
mysql -u harmony_ap -p'<DATABASE_PASSWORD>' -h <DATABASE_HOST> -P 3306 -D <DB_SCHEMA> --ssl-ca=ca.pem --ssl-cert=client-cert.pem --ssl-key=client-key.pem