Mosquitto Auth Plugin

Hallo everyone,

I’m trying to use the Mosquitto Auth Plugin to setup Mosquitto so that it retrieves the users and permissions from the LoRa App Server database.

I have my lora app server, postgresql db and mosquitto on different servers and they are working fine with the local username and password.

First thing I’m not sure about is on which server I need to install the requirements on the website? I installed them on the mqtt server except the postgresql-server-dev-9.6 which is installed on the postgresql db server.

Secondly when I add the content to /opt/mosquitto-auth-plug/config.mk I don’t know if I need to add anything to the MOSQUITTO_SRC =, or not.

And lastly when I clone the repository and try to compile the plugin with
Compile the plugin:

cd /opt/mosquitto-auth-plug
sudo make

I get the following error:
Selected backends: Memcached PostgreSQL Files
Using mosquitto source dir:
OpenSSL install dir: /usr
If you changed the backend selection, you might need to ‘make clean’ first
CFLAGS: -DRAW_SALT -I/src/ -I/lib/ -fPIC -Wall -Werror -DBE_MEMCACHED -DBE_POSTGRES -DBE_FILES -I/usr/local/include/libmemcached -I/usr/include/postgresql -I/src -DDEBUG=1 -I/usr/include
LDFLAGS: -L/usr/local/lib -L/lib/
LDADD: -lmemcached -L/usr/lib/x86_64-linux-gnu -lpq -L/usr/lib -lcrypto -lmosquitto
cc -DRAW_SALT -I/src/ -I/lib/ -fPIC -Wall -Werror -DBE_MEMCACHED -DBE_POSTGRES -DBE_FILES -I/usr/local/include/libmemcached -Ipg_config --includedir -I/src -DDEBUG=1 -I/usr/include -c -o auth-plug.o auth-plug.c
auth-plug.c: In function ‘mosquitto_auth_plugin_init’:
auth-plug.c:347:20: error: assignment from incompatible pointer type [-Werror=incompatible-pointer-types]
(*bep)->getuser = be_memcached_getuser;
^
cc1: all warnings being treated as errors
: recipe for target ‘auth-plug.o’ failed
make: *** [auth-plug.o] Error 1

You can find an example config.mk here:

https://github.com/brocaar/loraserver-setup/blob/master/roles/mosquitto-auth-plug/files/config.mk

Please note that this plugin is not without issues. E.g. when Mosquitto starts before PostgreSQL, Mosquitto will not start as it can not connect to PostgreSQL. See also as an alternative:

https://forum.loraserver.io/t/go-mosquitto-auth-plugin/448

Hi @shayan.

About failed compilation, there’s an issue at the plugin’s repo mentioning it: https://github.com/jpmens/mosquitto-auth-plug/issues/317.

As for the plugin’s location, the plugin.so must be in the same machine as mosquitto, but Postgres needs not to, as you can set remote host and port to access it. Just make sure to make Postgres accessible.

Finally, if you do go with the alternative plugin that @brocaar suggested, feel free to ask any questions here or open a different topic and I’ll guide you with the installation process, configurations, issues, etc.

Thanks for the response!

I used the code you put here and the error is gone. Is there a reason the code here is different from the code on the website? (https://docs.loraserver.io/install/mqtt-auth/). Because if not, I would advise you to update the code.

@iegomez Thanks for the help, the error is gone now it says I can’t connect to the MQTT server, which I expected is because of the username and password that have changed (need to figure that part out). I will contact you if I need your help.

I think that plugin included memcached recently, so it wasn’t in the loraserver docs. Surely Orne will add it soon.

I’m no expert in mosquitto-auth-plug. In fact, I wrote an entire new plugin (the one suggested by Orne) just because I wasn’t happy with that one. That said, I’ll gladly help with that plugin if I can, but surely can be more helpful if you choose to use mine.

I’ve updated the documentation source. It will be pushed on the next documentation update :slight_smile: