Skip to content

password-file: Error: Unable to open pwfile #3544

@Kra-tor

Description

@Kra-tor

Hello all,
I'm trying to create a simple test setup with mosquitto and docker, but I'm getting a lot of trouble with the password file.
I'm creating it within the container, but as soon as I insert it into the config file, the container won't start any more.
Apologies in advance for all the text, I'm trying to make this as clear as possible; Here the steps I have done:

  1. Structure:
/srv/mosquitto/
├── compose.yaml
├── config
│   └── mosquitto.conf
├── data
└── log
  1. compose.yaml:
services:
  mosquitto:
    image: eclipse-mosquitto
    container_name: mosquitto
    volumes:
      - ./config:/mosquitto/config
      - ./data:/mosquitto/data
      - ./log:/mosquitto/log
    ports:
      - 1883:1883
      - 9001:9001
    stdin_open: true 
    tty: true
  1. config/mosquitto.conf:
listener 1883
listener 9001
protocol websockets
persistence true
persistence_file mosquitto.db
persistence_location /mosquitto/data/

#Authentication
allow_anonymous false
#password_file /mosquitto/config/pwfile

-> Note that password_file is commented out at this point

Now i ran it with docker compose up -d
4. log:

mosquitto  | 1773868970: Info: running mosquitto as user: mosquitto.
mosquitto  | 1773868970: mosquitto version 2.1.2 starting
mosquitto  | 1773868970: Config loaded from /mosquitto/config/mosquitto.conf.
mosquitto  | 1773868970: Bridge support available.
mosquitto  | 1773868970: Persistence support available.
mosquitto  | 1773868970: TLS support available.
mosquitto  | 1773868970: TLS-PSK support available.
mosquitto  | 1773868970: Websockets support available.
mosquitto  | 1773868970: Opening ipv4 listen socket on port 1883.
mosquitto  | 1773868970: Opening ipv6 listen socket on port 1883.
mosquitto  | 1773868970: Opening ipv4 listen socket on port 9001.
mosquitto  | 1773868970: Opening ipv6 listen socket on port 9001.
mosquitto  | 1773868970: mosquitto version 2.1.2 running

-> so far so good
5. Switch inside the container and create an password file:

root@mycomputer:/srv/mosquitto# docker exec -it mosquitto sh
/ # cd mosquitto/config/
/mosquitto/config # ls -alF
total 12
drwxr-xr-x    2 root     root          4096 Mar 18 21:28 ./
drwxr-xr-x    5 mosquitto mosquitto      4096 Feb  9 20:01 ../
-rw-r--r--    1 root     root           212 Mar 18 21:19 mosquitto.conf
/mosquitto/config # mosquitto_passwd -c -b ./pwfile secretuser verysecretpassword
Adding password for user secretuser
/mosquitto/config # ls -alF
total 16
drwxr-xr-x    2 root     root          4096 Mar 18 21:29 ./
drwxr-xr-x    5 mosquitto mosquitto      4096 Feb  9 20:01 ../
-rw-r--r--    1 root     root           212 Mar 18 21:19 mosquitto.conf
-rw-------    1 root     root           197 Mar 18 21:29 pwfile
/mosquitto/config # exit
  1. enable password file in mosquito.conf:
listener 1883
listener 9001
protocol websockets
persistence true
persistence_file mosquitto.db
persistence_location /mosquitto/data/

#Authentication
allow_anonymous false
password_file /mosquitto/config/pwfile
  1. When I'm trying to fire up the container, it creates this log:
mosquitto  | 1773869758: Info: running mosquitto as user: mosquitto.
mosquitto  | 1773869758: Restored 0 base messages
mosquitto  | 1773869758: Restored 0 retained messages
mosquitto  | 1773869758: Restored 0 clients
mosquitto  | 1773869758: Restored 0 subscriptions
mosquitto  | 1773869758: Restored 0 client messages
mosquitto  | 1773869758: mosquitto version 2.1.2 starting
mosquitto  | 1773869758: Config loaded from /mosquitto/config/mosquitto.conf.
mosquitto  | 1773869758: Bridge support available.
mosquitto  | 1773869758: Persistence support available.
mosquitto  | 1773869758: TLS support available.
mosquitto  | 1773869758: TLS-PSK support available.
mosquitto  | 1773869758: Websockets support available.
mosquitto  | 1773869758: password-file: Error: Unable to open pwfile "/mosquitto/config/pwfile".
mosquitto  | 1773869758: mosquitto version 2.1.2 terminating
mosquitto  | 1773869758: Saving in-memory database to /mosquitto/data//mosquitto.db.
mosquitto exited with code 13
  1. After doing chmod 0700 pwfile:
mosquitto  | 1773869919: Info: running mosquitto as user: mosquitto.
mosquitto  | 1773869919: Restored 0 base messages
mosquitto  | 1773869919: Restored 0 retained messages
mosquitto  | 1773869919: Restored 0 clients
mosquitto  | 1773869919: Restored 0 subscriptions
mosquitto  | 1773869919: Restored 0 client messages
mosquitto  | 1773869919: mosquitto version 2.1.2 starting
mosquitto  | 1773869919: Config loaded from /mosquitto/config/mosquitto.conf.
mosquitto  | 1773869919: Bridge support available.
mosquitto  | 1773869919: Persistence support available.
mosquitto  | 1773869919: TLS support available.
mosquitto  | 1773869919: TLS-PSK support available.
mosquitto  | 1773869919: Websockets support available.
mosquitto  | 1773869919: password-file: Error: Unable to open pwfile "/mosquitto/config/pwfile".
mosquitto  | 1773869919: mosquitto version 2.1.2 terminating
mosquitto  | 1773869919: Saving in-memory database to /mosquitto/data//mosquitto.db.
mosquitto exited with code 13

9 Additionally chown mosquitto:mosquitto pwfile:

root@mycomputer:/srv/mosquitto# ls -alF config/
total 16
drwxr-xr-x 2 root      root      4096 Mar 18 22:34 ./
drwxr-xr-x 5 root      root      4096 Mar 18 21:53 ../
-rw-r--r-- 1 root      root       211 Mar 18 22:34 mosquitto.conf
-rwx------ 1 mosquitto mosquitto  197 Mar 18 22:29 pwfile*
root@mycomputer:/srv/mosquitto# docker compose up
Attaching to mosquitto
mosquitto  | 1773870429: Info: running mosquitto as user: mosquitto.
mosquitto  | 1773870429: Restored 0 base messages
mosquitto  | 1773870429: Restored 0 retained messages
mosquitto  | 1773870429: Restored 0 clients
mosquitto  | 1773870429: Restored 0 subscriptions
mosquitto  | 1773870429: Restored 0 client messages
mosquitto  | 1773870429: mosquitto version 2.1.2 starting
mosquitto  | 1773870429: Config loaded from /mosquitto/config/mosquitto.conf.
mosquitto  | 1773870429: Bridge support available.
mosquitto  | 1773870429: Persistence support available.
mosquitto  | 1773870429: TLS support available.
mosquitto  | 1773870429: TLS-PSK support available.
mosquitto  | 1773870429: Websockets support available.
mosquitto  | 1773870429: password-file: Error: Unable to open pwfile "/mosquitto/config/pwfile".
mosquitto  | 1773870429: mosquitto version 2.1.2 terminating
mosquitto  | 1773870429: Saving in-memory database to /mosquitto/data//mosquitto.db.
mosquitto exited with code 13

Also when I'm running the container with disabled file in the config, switch the container terminal and do cat /mosquitto/config/pwfile it can access the file without any problem (I've copied the path from the error message)

I’ve already read and tried several troubleshooting tips for this; either I don’t understand what ultimately led to the solution, or the solution didn’t work for me, which is why I’ve tried to describe the issue in as much detail as possible, so sorry again for the long text

Metadata

Metadata

Assignees

No one assigned

    Labels

    Status: AvailableNo one has claimed responsibility for resolving this issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions