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

Mosquitto: In default mosquitto.conf, add a listener on port 1883 #4133

Closed
mattsmithuk opened this issue Feb 21, 2021 · 11 comments · Fixed by #4223
Closed

Mosquitto: In default mosquitto.conf, add a listener on port 1883 #4133

mattsmithuk opened this issue Feb 21, 2021 · 11 comments · Fixed by #4223
Labels
Enhancement 💨 Solution available 🥂 Definite solution has been done
Milestone

Comments

@mattsmithuk
Copy link

mattsmithuk commented Feb 21, 2021

Creating a feature request

Is your feature request related to a problem? Please describe:

  • Mosquitto versions prior to version 2 would work out of the box. Versions after 2.0 need a listener setting up in configuration before they will work across a network

Describe the solution you'd like:

  • Have the default mosquitto.conf file to have the following lines:
listener 1883
allow_anonymous true
  • Alternatively, have a user and password which matches global dietpi setup

Describe alternatives you've considered:

  • Display instructions to setup mosquitto.conf after installation
@Joulinar
Copy link
Collaborator

Probably something like this could be documented on our online docs https://dietpi.com/docs/software/hardware_projects/#mosquitto

@MichaIng
Copy link
Owner

Relevant for Bullseye: https://packages.debian.org/mosquitto
The manpage reflexes it: https://manpages.debian.org/unstable/mosquitto/mosquitto.8.en.html#OPTIONS

Jep we should definitely set it up with a default port, that simply matches the previous default, IMO. Any preference about whether to allow anonymous/unauthenticated access by default or setting it up with username and password (via mosquitto_passwd to have it hashed and with dedicated stricter permissions)?

@slopsjon
Copy link

slopsjon commented Mar 7, 2021

Mosquitto was working no problem on version DietPi 6.34 upgraded to 7.0.2 this morning and it stopped working. No service running and would not start, so I had to reinstall Mosquitto and that got the service running but then no connections. Until I read this and put
listener 1883
allow_anonymous true
into the conf file and now all working again.

@MichaIng
Copy link
Owner

MichaIng commented Mar 8, 2021

Which system are you using? RPi or other, Buster or Bullseye?
Should be only relevant on Bullseye, since on Buster there was no package update since 2019.

@slopsjon
Copy link

slopsjon commented Mar 8, 2021

Which system are you using? RPi or other, Buster or Bullseye?
Should be only relevant on Bullseye, since on Buster there was no package update since 2019.

It's on an RPi 3B+ Buster.
At the same time my DNS server kept crashing which is on another SBC (Pihole+Unbound). The only way to stop it crashing was to kill the Unbound service. I then added the above two lines to mosquitto.conf and rebooted the mosquitto server that worked and then rebooted the DNS server and that stopped crashing.

@MichaIng MichaIng added this to the v7.1 milestone Mar 8, 2021
@MichaIng
Copy link
Owner

MichaIng commented Mar 8, 2021

Very strange, as Unbound runs on a very different port, and it would be too much coincidence when Mosquitto would listen/bind to port 5335 by default, when none is set.

However, it does not hurt and is probably a good idea anyway to set the port on every distro version, even if it's only to expose that option transparently.

@MichaIng MichaIng removed the Bullseye label Mar 26, 2021
MichaIng added a commit that referenced this issue Mar 26, 2021
+ DietPi-Software | Mosquitto: Since the Bullseye suite of the official repository does not yet exist, use Buster instead
+ DietPi-Software | MPD: Simplify systemd service runtime directory creation by using the RuntimeDirectory setting
+ DietPi-Software | Mosquitto: Restore pre-v2.0 behaviour by explicitly adding the port 1883 listener without IP binding, as by default it now binds to the loopback IP: #4133
+ DietPi-Software | Mosquitto: Restore pre-v2.0 behaviour by explicitly allowing anonymous client connections. We might switch to a user+password authenticated default, using the global software password, but for now restoring the previous default should be fine.
+ DietPi-Software | Mosquitto: Always use our own systemd unit, which allows us to simplify and align it with other units we ship.
+ DietPi-Software | Mosquitto: Disable PID and log file, both not required when using the systemd unit as it can track the service status directly and logs can be viewed via journalctl then. This allows to simplify the systemd unit and start it as mosquitto user directly, instead of having the daemon forking itself as mosquitto user.
+ DietPi-Software | Mosquitto: Do not automatically restart the service on failure. Generally we think that a failed service has a reason that should be recognised and investigated ASAP before starting it again, whether it is OOM failure, filesystem/database corruption or a DDoS attack and such things, where an automatic restart might cause further damage. When services restart automatically (up to five times by default in a certain time), they do not only mess logs, making debugging difficult, but also as the service can stay up, an urgent reason for the crash might be recognised with much delay. When a service is that important that it must stay even when the server is running into troubles that lead to service crashes, then this should be configured only manually by admins that do know what they do.
@MichaIng
Copy link
Owner

MichaIng commented Apr 4, 2021

I'll go with a password file. It makes sense to not allow unauthenticated remote requests by default. Any preferences on the username? dietpi or mosquitto? Password will be the global software password of course, and if the password file already exists, it won't be touched, of course.

@Joulinar
Copy link
Collaborator

Joulinar commented Apr 4, 2021

Personally I would vote for user mosquitto. We have other applications where user is identical with the application name like Qbit

@MichaIng
Copy link
Owner

MichaIng commented Apr 4, 2021

In case of qBittorrent its necessary as the login user is the UNIX user, which is quite uncommon otherwise. But there are other cases. Would be actually nice to have this aligned, either "dietpi" or the application name. Most importantly, "root" and "admin" should be avoided (also for this we have cases) to make it not too easy for brute-force attacks 😉.

@Joulinar
Copy link
Collaborator

Joulinar commented Apr 4, 2021

to make it not too easy for brute-force attacks

In this case, let's auto generate users per per installation individually 🤣

@MichaIng
Copy link
Owner

MichaIng commented Apr 4, 2021

In this case, let's auto generate users per per installation individually 🤣

Would be the safest option, although then better leave remote requests disabled by default 😄. But seriously, it's crazy how many bots try to login via the non-existing "admin" account on our Wordpress instance.

Actually nice would be to have a "global software user", similarly like the global software password. For ownCloud/Nextcloud, we have a dietpi.txt option, while by default "admin" is used (hardcoded default for the CLI install command as well) 😅. Makes sense to change that as well and make that option a global software authentication user. So I can use "MichaIng" or "Micha", which matches the user I'd want to create in most cases anyway.

But, to not mix too many changes together, "dietpi" or "mosquitto" will do for now 😄.

MichaIng added a commit that referenced this issue Apr 5, 2021
+ DietPi-Software | Mosquitto: Since the Bullseye suite of the official repository does not yet exist, use Buster instead
+ DietPi-Software | Mosquitto: Restore pre-v2.0 behaviour by explicitly adding the port 1883 listener without IP binding, as by default it now binds to the loopback IP: #4133
+ DietPi-Software | Mosquitto: Instead of restoring pre-v2.0 behaviour on anonymous requests, enable authenticated requests via password file by default, using username "mosquitto" and global software password.
+ DietPi-Software | Mosquitto: Always use our own systemd unit, which allows us to simplify and align it with other units we ship.
+ DietPi-Software | Mosquitto: Disable PID and log file, both not required when using the systemd unit as it can track the service status directly and logs can be viewed via journalctl then. This allows to simplify the systemd unit and start it as mosquitto user directly, instead of having the daemon forking itself as mosquitto user.
+ DietPi-Software | Mosquitto: Do not automatically restart the service on failure. Generally we think that a failed service has a reason that should be recognised and investigated ASAP before starting it again, whether it is OOM failure, filesystem/database corruption or a DDoS attack and such things, where an automatic restart might cause further damage. When services restart automatically (up to five times by default in a certain time), they do not only mess logs, making debugging difficult, but also as the service can stay up, an urgent reason for the crash might be recognised with much delay. When a service is that important that it must stay even when the server is running into troubles that lead to service crashes, then this should be configured only manually by admins that do know what they do.
+ DietPi-Software | MPD: Simplify systemd service runtime directory creation by using the RuntimeDirectory setting
+ DietPi-Software | ownCloud/Nextcloud: Instead of "<omitted>", show "XXXX" as replacement for passwords during CLI install with the amount of Xes matching the length of the password
@MichaIng MichaIng mentioned this issue Apr 27, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Enhancement 💨 Solution available 🥂 Definite solution has been done
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants