Setup ESE with PostgreSQL using HiveMQ Operator
Prequisite
Access to infrastructure with Kubectl
Running HiveMQ Cluster Install HiveMQ using Kubernetes Operator
Values.yaml file Install HiveMQ using Kubernetes Operator | Add Helm repository and download values.yaml file
Kubectl, Helm and MQTT CLI Prerequisite - Software Packages
Installation of PostgreSQL Client
A PostgreSQL client installed locally (we use psql (PostgreSQL) 14.10)
Installation of PostgreSQL server
Add the PostgreSQL repo to your Helm:
helm repo add bitnami https://charts.bitnami.com/bitnami
Update the repo to the latest version:
helm repo update bitnami
Create a new namespace to place the PostgreSql in:
kubectl create namespace db
Switch the KubeCtl context to the new namespace:
Install PostgreSQL to the new namespace:
If everything is correct, then PostgreSQL in installed to namespace “db”. The default name for the admin user is “postgres”. To get the password for "postgres" user run the following command and note the password:
Create tables for the ESE
Port-forward service postgres-postgresql to localhost:
Create a new database. When asked “Password for user
postgres
: ", input the value of thePGPASSWORD
variable:
Insert test credentials into the ESE database
Save the attached script to the file. Execute the script to create all the necessary tables in the ese-db.
Save the attached script to the file. If asked “Password for user
postgres
: ", input the value of thePGPASSWORD
variable.Check your work. If asked “Password for user
postgres
: ", input the value of thePGPASSWORD
variable.
You can optionally install a UI client e.g. pgAdmin Download , add a connection (localhost for port forwarding) and check tables manually.
Setting up the ESE license as a ConfigMap
Step 3 is mandatory, setting HIVEMQ_ALLOW_ALL_CLIENTS to false
If you skip step 1 & 2, then the enterprise-security-extension will start in trial mode, limited to 5h, and will be automatically disabled by the HiveMQ broker after 5h.
HiveMQ Enterprise Security Extension requires a separate license file, e.g. ese-license.elic, in the $HIVEMQ_HOME/license directory. To add the ese-license.elic along with the hivemq-license.lic, create a new configmap hivemq-license including all desired license files:
Edit the values.yaml file of the hivemq-operator, section
hivemq.configMaps
. Update this:To this:
This will mount the content of the configMap
hivemq-license
to the directory/opt/hivemq/license
of the hivemq-broker pods.Finally, disable the default security extension. By default, the HiveMQ distribution comes with the allow-all extension that permits all MQTT connections without requiring authentication. Before you use HiveMQ in production, add an appropriate security extension and remove the HiveMQ allow-all extension.
To disable the extension, set theHIVEMQ_ALLOW_ALL_CLIENTS
environment variable to false.
Edit the values.yaml file of the hivemq-operator, sectionhivemq.env
. Update this:To this:
Configuring the extension
Download a simple configuration file for Enterprise Security Extensions in the example below.
Replace the “password” in<db-password>password</db-password>
with the value ofPGPASSWORD
variable.In the hivemq namespace create a configMap ese-config from the file config.xml
Edit values.yaml file of
hivemq-operator
and update section hivemq.extensions, havingname: hivemq-enterprise-security-extension
Update the old hivemq-enterprise-security-extension block from this:To this:
Re-deploy hivemq-operator with updated values.yaml
– for ease of use we switch the namespace back to hivemq
kubectl config set-context --current --namespace=hivemq
If everything is correct, The HiveMQ log contains info about using the correct license:
The output would contain the following data around license and extension:
End-to-end testing
Find the MQTTListenerURL or IP using the following command (hivemq-hivemq-mqtt in our case with IP 20.79.142.120)
Subscribe (update url/ip for host, taken from last step, localhost in case of port forward)
Publish (update url/ip for host, taken from last step, localhost in case of port forward)
If everything is correct, the subscriber will receive
Test
Next steps
Please read official documentation for more configuration options https://docs.hivemq.com/hivemq-enterprise-security-extension/latest/index.html