I'm trying to set up a Node-RED Docker container with a custom module and password protection using adminAuth
. However, I suspect that my approach to authentication won't work because Node-RED typically requires hashed passwords inside settings.js
.
Here’s my Dockerfile:
FROM nodered/node-red:latest
# Install custom module
RUN npm install node-red-contrib-my-custom-module
# Set working directory
WORKDIR /usr/src/node-red
# Copy settings file with adminAuth configuration
COPY settings.js /usr/src/node-red/
# Expose port
EXPOSE 1880
# Start Node-RED
CMD ["npm", "start", "--", "--userDir", "/data"]
And here’s my settings.js
configuration for authentication:
module.exports = {
// other settings
adminAuth: {
type: "credentials",
users: function(username) {
if (username === "myuser") {
return Promise.resolve({
username: "myuser",
permissions: "*"
});
} else {
return Promise.resolve(null);
}
},
authenticate: function(username, password) {
if (username === "myuser" && password === "mypassword") {
return Promise.resolve({
username: "myuser",
permissions: "*"
});
} else {
return Promise.resolve(null);
}
}
},
// other settings
};
I have a few concerns:
settings.js
? The documentation suggests using bcrypt hashes.authenticate
function?To build and run the container, I use:
docker build -t my-node-red .
docker run -d -p 1880:1880 my-node-red
Should I modify the approach to ensure secure authentication, or is there an alternative way to handle authentication inside settings.js
for Node-RED?
Any insights or corrections would be greatly appreciated!
The default built in authentication module uses hashed passwords. The built in authentication module is applied when adminAuth
takes a users
field as an array of user
objects with hashed passwords.
If you are passing users
and authenticate
functions then it's entirely up to you how/where you store the password to validate a user session.
I would recommend not using plain text passwords sorted in the settings file.
So to explicitly answer the questions.
But as with all security it really depends on what threat model you are working with.