VerneMQ webhooks with diversity plugin

Hello! I’m using VErneMQ 1.12.1 broker, was successfully able to setup diversity plugin for postgres and tls to connect clients.
I need to get the data of clients (username and client_id) that failed to pass authorization, or get all the data of clients that tried to pass authorization successfully or not.
I found information about webhooks in the documentation, but for auth_on_register, auth_on_subscribe, auth_on_publish hooks work interchangeably. That is, after I answer status 200, authorization through posgres does not work.
Ideally what I want is:

  1. The client logs in to VerneMQ.
  2. The hook fires, I get the client data.
    3.1) If I answer status 200, then authorization continues through the diversity plugin postgres, otherwise authorization is not passed.
    3.2) Or whatever I answer, the authorization continues through the deversity plugin postgres.

Example my docker environment:
DOCKER_VERNEMQ_PLUGINS__VMQ_WEBHOOKS: ‘on’
DOCKER_VERNEMQ_VMQ_WEBHOOKS__AUTH_ON_REGISTER1__HOOK: ‘auth_on_register’
DOCKER_VERNEMQ_VMQ_WEBHOOKS__AUTH_ON_REGISTER1__ENDPOINT: ‘http://127.0.0.1:8008/hooks/test
DOCKER_VERNEMQ_VMQ_WEBHOOKS__AUTH_ON_PUBLISH1__HOOK: ‘auth_on_publish’
DOCKER_VERNEMQ_VMQ_WEBHOOKS__AUTH_ON_PUBLISH1__ENDPOINT: ‘http://127.0.0.1:8008/hooks/test
DOCKER_VERNEMQ_VMQ_WEBHOOKS__AUTH_ON_SUBSCRIBE1__HOOK: ‘auth_on_subscribe’
DOCKER_VERNEMQ_VMQ_WEBHOOKS__AUTH_ON_SUBSCRIBE1__ENDPOINT: ‘http://127.0.0.1:8008/hooks/test
DOCKER_VERNEMQ_PLUGINS__VMQ_WEBHOOKS__PRIORITY: 10
DOCKER_VERNEMQ_ACCEPT_EULA: ‘yes’
DOCKER_VERNEMQ_ALLOW_ANONYMOUS: ‘off’
DOCKER_VERNEMQ_PLUGINS__VMQ_PASSWD: ‘off’
DOCKER_VERNEMQ_PLUGINS__VMQ_ACL: ‘off’
DOCKER_VERNEMQ_VMQ_ACL__ACL_RELOAD_INTERVAL: 10
DOCKER_VERNEMQ_PLUGINS__VMQ_DIVERSITY: ‘on’
DOCKER_VERNEMQ_VMQ_DIVERSITY__AUTH_POSTGRES__ENABLED: ‘on’

I will be grateful for any help!

If I understand correctly, you want to use a WebHooks plugin as some sort of logging plugin, and then use a vmq_diversity (database) plugin to do the actual authentication/authorization.

This should be possible when your auth_on_register WebHook returns {"result": "next"} so that we pass data to the next plugin in the chain.
You might need to set a priority level for each plugin in the vernemq.conf to ensure the WebHooks plugin is called first.

I hope this helps a bit.

1 Like

Thanks a lot! This is exactly what I needed, now everything working for me, as I wanted.
Everything is very conveniently done.

1 Like