cmccambridge / mosquitto-unraid

Docker container for eclipse-mosquitto with unRAID ease-of-use tweaks
19 stars 7 forks source link

Error opening password file "/mosquitto/config/passwd" #38

Open Lecso11 opened 1 week ago

Lecso11 commented 1 week ago

I installed the docker container on Unraid with the following config: image I followed the instructions in readme adn created an user and password. I uncommented the option 2 in the default config file:

# mosquitto-unraid DEFAULT CONFIGURATION

# !! You MUST edit this file, or set RUN_INSECURE_MQTT_SERVER=1 !!

# Choose one of the options below to enable, or learn the details of Mosquitto
# configuration and write your own configuration file:
# 1. Mosquitto 2.0: https://mosquitto.org/blog/2020/12/version-2-0-0-released/
# 2. Migration guide: https://mosquitto.org/documentation/migrating-to-2-0/

# OPTION 1: Insecure listener restoring Mosquitto 1.x behavior

# These are the same settings that will be in effect if you run the container
# with RUN_INSECURE_MQTT_SERVER = 1 in the environment. They match the settings
# from pre-2.0, i.e. MQTT protocol on port 1883 on all interfaces, permitting
# anonymous connections. To enable this configuration, remove the # characters
# from the start of the next 3 lines to uncomment them:
#listener 1883
#protocol mqtt
#allow_anonymous true

# OPTION 2: Enable a listener on the standard port, and use a password file

# 1. Uncomment the following block to enable a standard port 1883 MQTT listener,
#    and require password authentication.
# 2. Follow the instructions on the mosquitto-unraid README to create users and
#    set their passwords:
#    https://github.com/cmccambridge/mosquitto-unraid/blob/master/README.md#Authentication
listener 1883
protocol mqtt
password_file /mosquitto/config/passwd
user mosquitto

My files have the following permissions: image If I set the password file to be readable by anybody, the docker starts, but gives me the error, that future versions will not open this because it has world readable permissions. I created an user in unraid named mosquitto and also in the mosquitto passwd file. What is the problem here?

cmccambridge commented 1 week ago

Apologies, I haven't seen this error about future versions not opening the file with world readable permissions before. My config files are world-readable, owned by root:

-rw-r--r-- 1 root root    30 Dec  6  2020 include_dir.conf
-rw-r--r-- 1 root root  1354 Jan 20  2021 mosquitto-unraid-default.conf
-rw-r--r-- 1 root root 38812 Oct 28  2020 mosquitto.conf
-rw-r--r-- 1 root root 38754 Nov  7  2018 mosquitto.conf.example
-rw-r--r-- 1 root root  1815 Sep 29  2023 passwd

Note that the definition of users is different between unraid itself and within a docker container... I do not have an unraid-level user for mosquitto at all, and the upstream Mosquitto container is hardcoded to associate mosquitto with uid 1883.

I would try explicitly creating your unraid mosquitto user with the uid and gid of 1883 exactly, and then chown the files to that UID/GID. Or, you can do this from within the mosquitto container through docker exec - you'll be root by default and can simply chown -R mosquitto:mosquitto /mosquitto/config/* to use the container's definition of the mosquitto user, i.e. uid=1883.

cmccambridge commented 1 week ago

Here's the "after" view of my server after running that chown command from inside the mosquitto container. See previous post for the "before" view:

# FROM UNRAID'S VIEW, NOTE NO USERNAME FOR UID / GID 1883
root@tower:/mnt/user/appdata/mosquitto# ls -l
total 53
-rw-r--r-- 1 1883 1883    30 Dec  6  2020 include_dir.conf
-rw-r--r-- 1 1883 1883  1354 Jan 20  2021 mosquitto-unraid-default.conf
-rw-r--r-- 1 1883 1883 38812 Oct 28  2020 mosquitto.conf
-rw-r--r-- 1 1883 1883 38754 Nov  7  2018 mosquitto.conf.example
-rw-r--r-- 1 1883 1883  1815 Sep 29  2023 passwd

# FROM CONTAINER'S VIEW
root@tower:/mnt/user/appdata/mosquitto# docker exec -it mosquitto /bin/sh
/ # ls -l mosquitto/config/
total 53
-rw-r--r--    1 mosquitt mosquitt        30 Dec  6  2020 include_dir.conf
-rw-r--r--    1 mosquitt mosquitt      1354 Jan 20  2021 mosquitto-unraid-default.conf
-rw-r--r--    1 mosquitt mosquitt     38812 Oct 28  2020 mosquitto.conf
-rw-r--r--    1 mosquitt mosquitt     38754 Nov  7  2018 mosquitto.conf.example
-rw-r--r--    1 mosquitt mosquitt      1815 Sep 29  2023 passwd