Deployment and configuration of node-red authentication on docker-compose

Deployment and configuration of node-red authentication on docker-compose

Deploying node-red on docker-compose with authentication and using docker volume.

Creating the docker-compose.yml file:

version: "3.7"

services:
  node-red:
    image: nodered/node-red
    environment:
      - TZ=Europe/Moscow
    ports:
      - "11880:1880" # 11880 - the port to connect to the container, 1880 - the port on which node-red runs inside the container.
    volumes:
      - "node-red:/data" # node-red - the directory that docker will allocate for data storage, /data - the directory inside the container.
    restart: always
volumes:
  node-red: # creating the node-red directory on the host.


Start the container in debug mode (the first run should be without the `-d`, to view errors as they appear):

$ docker-compose up node-red
Creating node-red_node-red_1_3e3e59f5e044 ... done
Attaching to node-red_node-red_1_bca4cb987984
node-red_1_bca4cb987984 |
node-red_1_bca4cb987984 | > node-red-docker@1.0.3 start /usr/src/node-red
node-red_1_bca4cb987984 | > node $NODE_OPTIONS node_modules/node-red/red.js $FLOWS "--userDir" "/data"
...

Stop the container and run the command to view the volume:

$ docker volume ls
DRIVER              VOLUME NAME
local               node-red_node-red

View detailed information about the volume:

$ docker volume inspect node-red_node-red
[
    {
        "CreatedAt": "2020-05-02T18:37:33Z",
        "Driver": "local",
        "Labels": {
            "com.docker.compose.project": "node-red",
            "com.docker.compose.version": "1.23.0",
            "com.docker.compose.volume": "node-red"
        },
        "Mountpoint": "/var/lib/docker/volumes/node-red_node-red/_data", # location of our directory
        "Name": "node-red_node-red",
        "Options": null,
        "Scope": "local"
    }
]

Navigate to the volume directory. This directory already contains the files created by docker when the container was deployed.

$ sudo ls /var/lib/docker/volumes/node-red_node-red/_data
lib  package.json  settings.js

We are interested in the file settings.js. Open it and look for the code snippet adminAuth. Uncomment it.

 // Securing Node-RED
    // -----------------
    // To password protect the Node-RED editor and admin API, the following
    // property can be used. See http://nodered.org/docs/security.html for details.
    adminAuth: {
        type: "credentials",
        users: [{
            username: "admin",
            password: "$2a$08$zZWtXTja0fB1pzD4sHCMyOCMYz2Z6dNbM6tl8sJogENOMcxWV9DN.",
            permissions: "*"
        }]
    },

In the key password: you need to insert the node-red password hash.

Getting the node-red password hash
On any machine with node.js, install the node-red-admin package.

npm i node-red-admin -g

Run the package and set a password:

node-red-admin hash-pw

Start the container and connect to the port 11880.

http://192.168.0.100:11880/

An authentication window should appear.

Deployment and configuration of node-red authentication on docker-compose

Enter the username and password.

If everything works, restart the container with the key -d.

$ docker-compose up -d node-red

Something like this.

Source: habr.com

Buy reliable website hosting with DDoS protection, VPS VDS servers 🔥 Buy reliable website hosting with DDoS protection, VPS VDS servers | ProHoster