AMRC-FactoryPlus / amrc-connectivity-stack

The AMRC Connectivity Stack (ACS) is an open-source implementation of the AMRC's Factory+ framework
https://factoryplus.app.amrc.co.uk
MIT License
13 stars 2 forks source link

Consider moving MQTT auth out of process #350

Open amrc-benmorrow opened 8 hours ago

amrc-benmorrow commented 8 hours ago

Currently the HiveMQ MQTT auth code runs in-process within the MQTT broker. This is the way HiveMQ expect auth plugins to run and is common practice generally in the Java world but has some disadvantages:

We should consider whether it is sensible to instead implement a thinner plugin, which interfaces with a privileged client over MQTT. Client connections and ACL changes are not high-frequency events, so as long as the broker-side code has a ‘current ACL’ available for per-packet checking this should not impact performance.

If the interface is sensibly designed then longer-term it might be possible to implement the broker-side piece in Mosquitto. This would give us bridging and probably better performance. This would require core changes to Mosquitto; the current plugin interface is entirely synchronous (calls block the whole broker) and so completely inadequate for network-based auth.

amrc-benmorrow commented 8 hours ago

Having looked further into the HiveMQ APIs it’s less clear this would be an improvement. Watching for packets from a privileged client will still require hooking into inbound PUBLISHes, and switching away from the core ACL support means every packet will have to be explicitly checked against our ACL.

HiveMQ has two sets of APIs that could be used to implement dynamic ACLs: the Authorizer APIs and the Interceptor APIs. As far as I can tell, they overlap substantially, the differences being:

This suggests we might need to use the Authorizer API for publishes and the Interceptor for subscribes, which would be annoying.