Node-RED, back to the Cold War?#
Node-RED is a product from IBM Laboratories. It enables the creation and management of workflows via the interconnection of “nodes”.
The node link can be a simple input/output flow, or interwoven with logic processing nodes, other workflows…
Let your imagination run wild, according to your needs!
Objectives#
Cover, Node-RED installation on OpenBSD, for the following operating mode:
- Node-RED in daemon mode via user _nodered.
- Working directory on mirrored disk: /data/nodered
- https access only
- Access via authentication (login & password)
Prerequisites#
A platform running OpenBSD (64-bit architecture only), here our RockPro64
Installation#
The following packages must be installed:
- NodeJs
- Node-RED
- Node-Red-Admin
The last is a node-red module, for managing application users.
doas pkg_add node
doas npm install -g --unsafe-perm node-red
doas npm install -g node-red-admin
Create the working directory:
doas mkdir -p /data/nodered/.ssl
Add system user:
doas groupadd -v -g 777 _node-red
doas useradd -v -c "Node Red daemon" -d /data/nodered -g 777 -s /sbin/nologin -u 777 _node-red
chmod 755 /etc/rc.d/node-red
Initialize Node-Red instance; /data/node-red
doas -u _node-red /usr/local/bin/node-red --title "Node-Red : Home Automation" --userDir /data/node-red
Testing#
Open your browser at the url: http://mon.ip.domain.local:1880
Stop Node-Red via CTRL+C
Configuration#
Default startup#
/etc/rc.local
if [ -x /usr/local/bin/node-red ]; then
echo 'Starting Node-Red' && doas -u _node-red /usr/local/bin/node-red --title "Home Automation" --userDir /data/nodered
fi
Securing Node-RED#
1. Application administrator#
Create an encrypted password:
node-red-admin hash-pw
Password: <Enter a password>
$2a$08$gxCsv3bGcPOvlarJiZw.QOqNfQKak7.vzltgRIAbGScbvGdOfE3HO
Uncomment user object adminAuth in /var/data/nodered/settings.js
// 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$gxCsv3bGcPOvlarJiZw.QOqNfQKak7.vzltgRIAbGScbvGdOfE3HO",
permissions: "*"
}]
},
2. Dashboard access#
Create an encrypted password:
node-red-admin hash-pw
Password: <Enter a password>
$2a$08$Fa6lO1rVaMPZYsxivz/PVOJoMly4/.Qi9EqMhReMMOLzutmVcC8Ty
Uncomment node in /data/nodered/setting.js
// To password protect the node-defined HTTP endpoints (httpNodeRoot), or
// the static content (httpStatic), the following properties can be used.
// The pass field is a bcrypt hash of the password.
// See http://nodered.org/docs/security.html#generating-the-password-hash
httpNodeAuth: {user:"dashUser",pass:"$2a$08$Fa6lO1rVaMPZYsxivz/PVOJoMly4/.Qi9EqMhReMMOLzutmVcC8Ty"},
//httpStaticAuth: {user:"user",pass:"$2a$08$zZWtXTja0fB1pzD4sHCMyOCMYz2Z6dNbM6tl8sJogENOMcxWV9DN."},
3. https access#
Create a self-signed SSL certificate:
doas cd /data/nodered/.ssl/
doas openssl genrsa -out node.key 2048
doas openssl req -new -sha256 -key node.key -out node.csr
doas openssl x509 -req -in node.csr -signkey node.key -out node.crt
doas chmod 400 *
Uncomment in /data/nodered/setting.js
// The `https` setting requires the `fs` module. Uncomment the following
// to make it available:
var fs = require("fs");
// The following property can be used to enable HTTPS
// See http://nodejs.org/api/https.html#https_https_createserver_options_requestlistener
// for details on its contents.
// See the comment at the top of this file on how to load the `fs` module used by
// this setting.
//
https: {
key: fs.readFileSync(__dirname +'/.ssl/node.key'),
cert: fs.readFileSync(__dirname +'/.ssl/node.crt')
// The following property can be used to cause insecure HTTP connections to
// be redirected to HTTPS.
requireHttps: true,
}
4. Start service#
doas echo 'Starting Node-Red' && doas -u _node-red /usr/local/bin/node-red --title "Home Automation" --userDir /data/nodered
On first startup, the certificate error is normal.
Click on “Advanced “
Click on “Accept the risk and Continue”
Enjoy !