Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add comms (mqtt) component to forge platform #706

Merged
merged 17 commits into from
Jul 26, 2022
Merged

Add comms (mqtt) component to forge platform #706

merged 17 commits into from
Jul 26, 2022

Conversation

knolleary
Copy link
Member

@knolleary knolleary commented Jun 17, 2022

Part of #464

This adds the Comms component to the platform, enabling MQTT communication.

The Comms component will enable the following uses:

Broker Configuration

This requires a properly configured MQTT broker to be running and available to the platform.

We are using mosquitto, with the mosquitto-go-auth plugin.

The following is an example configuration:

auth_plugin /Users/nol/code/flowforge/mosquitto/mosquitto-go-auth/go-auth.so
auth_opt_cache true
auth_opt_backends  http
auth_opt_http_host localhost
auth_opt_http_port 3000
auth_opt_http_getuser_uri /api/comms/auth/client
auth_opt_http_aclcheck_uri /api/comms/auth/acl
per_listener_settings false
listener 4880
listener 4881
protocol websockets

Note it includes the http host/port of the forge platform, as well as the full path to the go-auth plugin.

API Routes

The mosquitto auth plugin uses http requests to the platform to authenticate and authorise requests. These are made to two new api routes:

  • POST /api/comms/auth/client - validate a given username/password is valid
  • POST /api/comms/auth/acl - validate an access request to a given topic is valid for a particular client

Database Changes

Adds a BrokerClient table to store username/passwords for MQTT Clients.

The platform generates its own BrokerClient on initialisation (forge_platform) - used to subscribe to status events and publish commands to devices/launchers.

Devices get a BrokerClient generated whenever they generate credentials - and the details are provided along with the other device credentials in the UI.

Runtime Configuration

A broker configuration must be provided via flowforge.yml:

broker:
  url: mqtt://localhost:1880
  • Question: interval vs external broker url (ie, what launchers would use, vs what devices would use)

Next steps

@knolleary
Copy link
Member Author

Currently reviewing whether this is the right approach for the security integration with the broker.

The problem with the dynamic security approach is we don't hold the master record of who can access what. We are reliant on the broker storing that information and it always being available.

In the k8s world, that means having a persistent volume - which complicates matters.

There is also the matter of bootstrapping its config file with the admin username/password. We wouldn't be able to mount that file in like we do flowforge.yml as mosquitto needs to write to it as well as read.

An alternative approach would be to use https://github.com/iegomez/mosquitto-go-auth which supports talking directly to sqlite/postgres to validate users.

That would allow us to keep the information in our own database - and the mosquitto instance can be more ephemeral.

The added complication is building that plugin (written in Go) for the platforms we want to support and getting it installed properly.

@ZJvandeWeg ZJvandeWeg added this to the 0.7 milestone Jun 21, 2022
@knolleary
Copy link
Member Author

Updated the main description to reflect the move to the go-auth plugin.

forge/routes/index.js Outdated Show resolved Hide resolved
@sammachin sammachin modified the milestones: 0.7, 0.8 Jul 14, 2022
@knolleary
Copy link
Member Author

Rebased this branch to main as of the 0.7 release.

@knolleary knolleary marked this pull request as ready for review July 25, 2022 16:57
@knolleary knolleary mentioned this pull request Jul 25, 2022
3 tasks
Copy link
Contributor

@hardillb hardillb left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good

@hardillb hardillb merged commit 763460d into main Jul 26, 2022
@knolleary knolleary deleted the add-broker branch July 27, 2022 09:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants